-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCategoryEditor.cs
273 lines (257 loc) · 12.9 KB
/
CategoryEditor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BDO_Item_Sorter
{
public partial class CategoryEditor : Form
{
public static string[] itemName = new string[10000], itemCategory = new string[10000], menuCategories = new string[100], menuCities = new string[100], menuCategoryAttribution = new string[100], menuCityAttribution = new string[100];
public static int menuCategoriesIndex = 0, menuCitiesIndex = 0, itemDatabaseIndex = 0, categoryAttributionIndex = 0;
public static int[] itemID = new int[10000], cityCapacity = new int[100];
public static bool[] itemIgnored = new bool[10000], itemProblematic = new bool[10000];
public CategoryEditor()
{
InitializeComponent();
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
}
private void CategoryEditor_Load(object sender, EventArgs e)
{
Directory.SetCurrentDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\BDO Item Sorter Data");
update();
}
public void update()
{
menuCategoriesIndex = 0;
menuCitiesIndex = 0;
itemDatabaseIndex = 0;
categoryAttributionIndex = 0;
categoryDisplay.Items.Clear();
categoryDrop.Items.Clear();
cityDrop.Items.Clear();
using (StreamReader reader = new StreamReader(Directory.GetCurrentDirectory() + "\\Categories.txt"))
{
while (reader.EndOfStream == false)
{
menuCategories[menuCategoriesIndex] = reader.ReadLine();
menuCategoriesIndex++;
}
reader.Dispose();
}
using (StreamReader reader = new StreamReader(Directory.GetCurrentDirectory() + "\\Cities.txt"))
{
while (reader.EndOfStream == false)
{
menuCities[menuCitiesIndex] = reader.ReadLine();
menuCitiesIndex++;
}
reader.Dispose();
}
using (StreamReader reader = new StreamReader(Directory.GetCurrentDirectory() + "\\Item Attributions.csv"))
{
while (reader.EndOfStream == false)
{
string[] tempAttributes = new string[5];
tempAttributes = reader.ReadLine().Split(',');
itemID[itemDatabaseIndex] = Convert.ToInt32(tempAttributes[0]);
itemName[itemDatabaseIndex] = tempAttributes[1];
itemCategory[itemDatabaseIndex] = tempAttributes[2];
itemIgnored[itemDatabaseIndex] = Convert.ToBoolean(tempAttributes[3]);
itemProblematic[itemDatabaseIndex] = Convert.ToBoolean(tempAttributes[4]);
itemDatabaseIndex++;
}
reader.Dispose();
}
using (StreamReader reader = new StreamReader(Directory.GetCurrentDirectory() + "\\Category Attributions.csv"))
{
while (reader.EndOfStream == false)
{
string[] tempAttributes = new string[2];
tempAttributes = reader.ReadLine().Split(',');
menuCategoryAttribution[categoryAttributionIndex] = tempAttributes[0];
menuCityAttribution[categoryAttributionIndex] = tempAttributes[1];
categoryAttributionIndex++;
}
reader.Dispose();
}
for (int i = 0; i < menuCategoriesIndex; i++)
{
categoryDisplay.Items.Add(menuCategories[i]);
categoryDrop.Items.Add(menuCategories[i]);
}
for(int i = 0; i < menuCitiesIndex; i++)
{
cityDrop.Items.Add(menuCities[i]);
}
categoryDrop.SelectedIndex = menuCategoriesIndex - 1;
cityDrop.SelectedIndex = menuCitiesIndex - 1;
}
private void attributeButton_Click(object sender, EventArgs e)
{
if (categoryDrop.SelectedIndex != menuCategoriesIndex - 1)
{
MainMenu.lineEditor(categoryDrop.Text + ',' + cityDrop.Text, Directory.GetCurrentDirectory() + "\\Category Attributions.csv", categoryDrop.SelectedIndex);
}
}
private void categoryDrop_SelectedIndexChanged(object sender, EventArgs e)
{
for (int i = 0; i < menuCitiesIndex; i++)
{
if (menuCityAttribution[categoryDrop.SelectedIndex] == menuCities[i])
{
cityDrop.SelectedIndex = i;
break;
}
}
}
private void moveUpToolStripMenuItem_Click(object sender, EventArgs e)
{
if (categoryDisplay.SelectedIndex != menuCategoriesIndex - 1 && categoryDisplay.SelectedIndex != 0)
{
string[] temp = File.ReadAllLines(Directory.GetCurrentDirectory() + "\\Categories.txt");
string b;
b = temp[categoryDisplay.SelectedIndex];
MainMenu.lineEditor(temp[categoryDisplay.SelectedIndex - 1], Directory.GetCurrentDirectory() + "\\Categories.txt", categoryDisplay.SelectedIndex);
MainMenu.lineEditor(b, Directory.GetCurrentDirectory() + "\\Categories.txt", categoryDisplay.SelectedIndex - 1);
string[] temp2 = File.ReadAllLines(Directory.GetCurrentDirectory() + "\\Category Attributions.csv");
string b2;
b2 = temp2[categoryDisplay.SelectedIndex];
MainMenu.lineEditor(temp2[categoryDisplay.SelectedIndex - 1], Directory.GetCurrentDirectory() + "\\Category Attributions.csv", categoryDisplay.SelectedIndex);
MainMenu.lineEditor(b2, Directory.GetCurrentDirectory() + "\\Category Attributions.csv", categoryDisplay.SelectedIndex - 1);
}
else
MessageBox.Show("Cannot change the order of (none) or the first item.", "Wait, that's illegal!", MessageBoxButtons.OK, MessageBoxIcon.Information);
update();
}
private void moveDownToolStripMenuItem_Click(object sender, EventArgs e)
{
if (categoryDisplay.SelectedIndex != menuCategoriesIndex - 1 && categoryDisplay.SelectedIndex != menuCategoriesIndex - 2)
{
string[] temp = File.ReadAllLines(Directory.GetCurrentDirectory() + "\\Categories.txt");
string b;
b = temp[categoryDisplay.SelectedIndex];
MainMenu.lineEditor(temp[categoryDisplay.SelectedIndex + 1], Directory.GetCurrentDirectory() + "\\Categories.txt", categoryDisplay.SelectedIndex);
MainMenu.lineEditor(b, Directory.GetCurrentDirectory() + "\\Categories.txt", categoryDisplay.SelectedIndex + 1);
string[] temp2 = File.ReadAllLines(Directory.GetCurrentDirectory() + "\\Category Attributions.csv");
string b2;
b2 = temp2[categoryDisplay.SelectedIndex];
MainMenu.lineEditor(temp2[categoryDisplay.SelectedIndex + 1], Directory.GetCurrentDirectory() + "\\Category Attributions.csv", categoryDisplay.SelectedIndex);
MainMenu.lineEditor(b2, Directory.GetCurrentDirectory() + "\\Category Attributions.csv", categoryDisplay.SelectedIndex + 1);
}
else
MessageBox.Show("Cannot change the order of (none).", "Wait, that's illegal!", MessageBoxButtons.OK, MessageBoxIcon.Information);
update();
}
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
{
if (categoryDisplay.SelectedIndex != menuCategoriesIndex - 1)
{
string tempFile = Path.GetTempFileName();
using (var sr = new StreamReader(Directory.GetCurrentDirectory() + "\\Categories.txt"))
using (var sw = new StreamWriter(tempFile))
{
string line;
while ((line = sr.ReadLine()) != null)
{
if (line != menuCategories[categoryDisplay.SelectedIndex])
sw.WriteLine(line);
}
}
File.Delete(Directory.GetCurrentDirectory() + "\\Categories.txt");
File.Move(tempFile, Directory.GetCurrentDirectory() + "\\Categories.txt");
using (var sr = new StreamReader(Directory.GetCurrentDirectory() + "\\Category Attributions.csv"))
using (var sw = new StreamWriter(tempFile))
{
string line;
while ((line = sr.ReadLine()) != null)
{
if (line != (menuCategoryAttribution[categoryDisplay.SelectedIndex] + ',' + menuCityAttribution[categoryDisplay.SelectedIndex]))
sw.WriteLine(line);
}
}
File.Delete(Directory.GetCurrentDirectory() + "\\Category Attributions.csv");
File.Move(tempFile, Directory.GetCurrentDirectory() + "\\Category Attributions.csv");
for (int i = 0; i < itemDatabaseIndex; i++)
{
if (itemCategory[i] == menuCategories[categoryDisplay.SelectedIndex])
{
MainMenu.lineEditor(Convert.ToString(itemID[i]) + ',' + itemName[i] + ',' + "(none)" + ',' + Convert.ToString(itemIgnored[i]) + ',' + itemProblematic[i], Directory.GetCurrentDirectory() + "\\Item Attributions.csv", i);
}
}
update();
}
}
private void addCategory_Click(object sender, EventArgs e)
{
if (newCategoryText.Text.Contains(',') == true)
{
MessageBox.Show("The name cannot contain commas (\",\")!", "Illegal character", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (newCategoryText.Text != null)
{
MainMenu.lineEditor(newCategoryText.Text, Directory.GetCurrentDirectory() + "\\Categories.txt", menuCategoriesIndex - 1);
using (StreamWriter writer = new StreamWriter(Directory.GetCurrentDirectory() + "\\Categories.txt", true))
{
writer.WriteLine("(none)");
writer.Dispose();
}
MainMenu.lineEditor(newCategoryText.Text + ",(none)", Directory.GetCurrentDirectory() + "\\Category Attributions.csv", categoryAttributionIndex - 1);
using (StreamWriter writer = new StreamWriter(Directory.GetCurrentDirectory() + "\\Category Attributions.csv", true))
{
writer.WriteLine("(none),(none)");
writer.Dispose();
}
newCategoryText.Text = null;
}
update();
}
private void addLocation_Click(object sender, EventArgs e)
{
if (newLocationText.Text.Contains(',') == true)
{
MessageBox.Show("The name cannot contain commas (\",\")!", "Illegal character", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (newLocationText.Text != null)
{
MainMenu.lineEditor(newLocationText.Text, Directory.GetCurrentDirectory() + "\\Cities.txt", menuCitiesIndex - 1);
using (StreamWriter writer = new StreamWriter(Directory.GetCurrentDirectory() + "\\Cities.txt", true))
{
writer.WriteLine("(none)");
writer.Dispose();
}
newLocationText.Text = null;
}
update();
}
private void doneButton_Click(object sender, EventArgs e)
{
this.Close();
}
private void CategoryEditor_FormClosing(object sender, FormClosingEventArgs e)
{
if (categoryDrop.SelectedIndex != menuCategoriesIndex - 1)
{
MainMenu.lineEditor(categoryDrop.Text + ',' + cityDrop.Text, Directory.GetCurrentDirectory() + "\\Category Attributions.csv", categoryDrop.SelectedIndex);
}
}
private void categoryDisplay_MouseDown(object sender, MouseEventArgs e)
{
categoryDisplay.SelectedIndex = categoryDisplay.IndexFromPoint(e.Location);
if (e.Button == MouseButtons.Right)
{
if (categoryDisplay.SelectedIndex != -1 && categoryDisplay.SelectedItem.ToString() != "(none)")
moveContext.Show(Cursor.Position);
}
}
}
}