Mercurial > repos > WarFoundryForge
annotate FrmSystem.cs @ 8:0dadaa315430
Category Tab Updates:
Remove 'Edit' Button, clicking on the list will populate the category fields
Add 'Apply' Button, make it so changes to the category enable it
Max points for category set to default army size(disabled)
author | Tsudico |
---|---|
date | Thu, 16 Dec 2010 18:52:30 -0600 |
parents | d63df495cf5a |
children | 43d88f50c712 |
rev | line source |
---|---|
0 | 1 using System; |
2 using System.Collections.Generic; | |
3 using System.ComponentModel; | |
4 using System.Data; | |
5 using System.Drawing; | |
6 using System.Text; | |
7 using System.Text.RegularExpressions; | |
8 using System.Windows.Forms; | |
9 using IBBoard.Lang; | |
10 using IBBoard.Windows.Forms; | |
11 using IBBoard.Windows.Forms.I18N; | |
12 | |
13 namespace IBBoard.WarFoundry.Forge.WinForms | |
14 { | |
15 public partial class FrmSystem : IBBoard.Windows.Forms.IBBForm | |
16 { | |
4
866d0093bb11
WarFoundryLoader.GetDefault().LoadFile returning null object.
Tsudico
parents:
0
diff
changeset
|
17 private IBBoard.WarFoundry.API.Objects.GameSystem system; |
866d0093bb11
WarFoundryLoader.GetDefault().LoadFile returning null object.
Tsudico
parents:
0
diff
changeset
|
18 |
8 | 19 private bool UpdateCategory |
20 { | |
21 get | |
22 { | |
23 if(this.listCategories.SelectedIndex >= 0) | |
24 { | |
25 foreach(IBBoard.WarFoundry.API.Objects.Category cat in system.Categories) | |
26 { | |
27 if(cat.Name == this.listCategories.SelectedItem) | |
28 { | |
29 if(cat.Name != this.txtCategoryName.Text) | |
30 { | |
31 return true; | |
32 } | |
33 if(cat.ID != this.txtCategoryID.Text) | |
34 { | |
35 return true; | |
36 } | |
37 if(cat.MinimumPoints > 0 && !this.cbPointMin.Checked) | |
38 { | |
39 return true; | |
40 } | |
41 else if(cat.MinimumPoints != this.numPointMin.Value) | |
42 { | |
43 return true; | |
44 } | |
45 if(cat.MaximumPoints < this.numPointMax.Maximum && !this.cbPointMax.Checked) | |
46 { | |
47 return true; | |
48 } | |
49 else if(cat.MaximumPoints != this.numPointMax.Value) | |
50 { | |
51 return true; | |
52 } | |
53 if(cat.MinimumPercentage > 0 && !this.cbPercentMin.Checked) | |
54 { | |
55 return true; | |
56 } | |
57 else if(cat.MinimumPercentage != this.numPercentMin.Value) | |
58 { | |
59 return true; | |
60 } | |
61 if(cat.MaximumPercentage < this.numPercentMax.Maximum && !this.cbPercentMax.Checked) | |
62 { | |
63 return true; | |
64 } | |
65 else if(cat.MaximumPercentage != this.numPercentMax.Value) | |
66 { | |
67 return true; | |
68 } | |
69 } | |
70 } | |
71 } | |
72 return false; | |
73 } | |
74 } | |
75 | |
4
866d0093bb11
WarFoundryLoader.GetDefault().LoadFile returning null object.
Tsudico
parents:
0
diff
changeset
|
76 public FrmSystem(IBBoard.WarFoundry.API.Objects.GameSystem loadSystem) |
0 | 77 { |
78 InitializeComponent(); | |
4
866d0093bb11
WarFoundryLoader.GetDefault().LoadFile returning null object.
Tsudico
parents:
0
diff
changeset
|
79 system = loadSystem; |
6
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
80 this.txtSystemName.Text = system.Name; |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
81 this.txtSystemId.Text = system.ID; |
8 | 82 this.numDefaultSize.Value = system.SystemArmyDefaultSize; |
83 this.numPointMax.Value = this.numDefaultSize.Value; | |
6
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
84 if(system.AllowAllies) |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
85 { |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
86 this.radSystemAlliesYes.Checked = true; |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
87 } |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
88 else |
4
866d0093bb11
WarFoundryLoader.GetDefault().LoadFile returning null object.
Tsudico
parents:
0
diff
changeset
|
89 { |
6
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
90 this.radSystemAlliesNo.Checked = true; |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
91 } |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
92 if (system.WarnOnError) |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
93 { |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
94 this.radSystemWarnYes.Checked = true; |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
95 } |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
96 else |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
97 { |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
98 this.radSystemWarnNo.Checked = true; |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
99 } |
8 | 100 updateCategoryList(); |
0 | 101 } |
6
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
102 |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
103 private string generateID(string name) |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
104 { |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
105 string newId = String.Empty; |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
106 |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
107 MatchCollection id_parts = Regex.Matches(name, @"[A-Z\d]"); |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
108 foreach (Match part in id_parts) |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
109 { |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
110 newId += part.ToString(); |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
111 } |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
112 |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
113 if (newId.Length < 3) |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
114 { |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
115 newId = name.ToLower().Replace(" ", ""); |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
116 } |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
117 |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
118 return newId.ToLower(); |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
119 } |
8 | 120 |
121 private void clearCategory() | |
122 { | |
123 this.txtCategoryName.Text = string.Empty; | |
124 this.txtCategoryID.Text = string.Empty; | |
125 this.cbPointMin.Checked = false; | |
126 this.cbPointMax.Checked = false; | |
127 this.cbPercentMin.Checked = false; | |
128 this.cbPercentMax.Checked = false; | |
129 this.numPointMin.Value = 0; | |
130 this.numPointMin.Enabled = false; | |
131 this.numPointMax.Value = this.numDefaultSize.Value; | |
132 this.numPointMax.Enabled = false; | |
133 this.numPercentMin.Value = 0; | |
134 this.numPercentMin.Enabled = false; | |
135 this.numPercentMax.Value = 100; | |
136 this.numPercentMax.Enabled = false; | |
137 } | |
138 | |
139 private void updateCategoryList() | |
140 { | |
141 if (system.Categories.Length > 0) | |
142 { | |
143 this.listCategories.Items.Clear(); | |
144 for (int i = 0; i < system.Categories.Length; i++) | |
145 { | |
146 this.listCategories.Items.Add(system.Categories[i].Name); | |
147 } | |
148 } | |
149 } | |
0 | 150 |
151 private void btnSystemClose_Click(object sender, EventArgs e) | |
152 { | |
153 this.Close(); | |
154 } | |
155 | |
156 private void btnGenerateSysId_Click(object sender, EventArgs e) | |
157 { | |
6
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
158 this.txtSystemId.Text = generateID(this.txtSystemName.Text); |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
159 } |
0 | 160 |
8 | 161 private void listCategories_SelectedIndexChanged(object sender, EventArgs e) |
162 { | |
163 foreach (IBBoard.WarFoundry.API.Objects.Category cat in system.Categories) | |
164 { | |
165 if (cat.Name == this.listCategories.SelectedItem) | |
166 { | |
167 this.txtCategoryName.Text = cat.Name; | |
168 this.txtCategoryID.Text = cat.ID; | |
169 if (cat.MinimumPoints > 0) | |
170 { | |
171 this.numPointMin.Value = cat.MinimumPoints; | |
172 this.cbPointMin.Checked = true; | |
173 this.numPointMin.Enabled = true; | |
174 } | |
175 else | |
176 { | |
177 this.numPointMin.Enabled = false; | |
178 } | |
179 if (cat.MaximumPoints > 0 && cat.MaximumPoints < this.numPercentMax.Maximum) | |
180 { | |
181 this.numPointMax.Value = cat.MaximumPoints; | |
182 this.cbPointMax.Checked = true; | |
183 this.numPointMax.Enabled = true; | |
184 } | |
185 else | |
186 { | |
187 this.numPointMax.Value = this.numDefaultSize.Value; | |
188 this.numPointMax.Enabled = false; | |
189 } | |
190 if (cat.MinimumPercentage > 0) | |
191 { | |
192 this.numPercentMin.Value = cat.MinimumPercentage; | |
193 this.cbPercentMin.Checked = true; | |
194 this.numPercentMin.Enabled = true; | |
195 } | |
196 else | |
197 { | |
198 this.numPercentMin.Enabled = false; | |
199 } | |
200 if (cat.MaximumPercentage < 100) | |
201 { | |
202 this.numPercentMax.Value = cat.MaximumPercentage; | |
203 this.cbPercentMax.Checked = true; | |
204 this.numPercentMax.Enabled = true; | |
205 } | |
206 else | |
207 { | |
208 this.numPercentMax.Enabled = false; | |
209 } | |
210 this.btnCategoryApply.Enabled = false; | |
211 break; | |
212 } | |
213 } | |
214 } | |
215 | |
6
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
216 private void btnCategoryAdd_Click(object sender, EventArgs e) |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
217 { |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
218 if(this.txtCategoryName.Text == string.Empty) |
0 | 219 { |
6
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
220 MessageBox.Show("Category must have a name", "Category Error"); |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
221 return; |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
222 } |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
223 if (this.txtCategoryID.Text == string.Empty) |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
224 { |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
225 MessageBox.Show("Category must have an ID", "Category Error"); |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
226 return; |
0 | 227 } |
6
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
228 IBBoard.WarFoundry.API.Objects.Category cat = new IBBoard.WarFoundry.API.Objects.Category( |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
229 this.txtCategoryID.Text, |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
230 this.txtCategoryName.Text |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
231 ); |
0 | 232 |
6
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
233 cat.MinimumPoints = (int)this.numPointMin.Value; |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
234 cat.MaximumPoints = (int)this.numPointMax.Value; |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
235 cat.MinimumPercentage = (int)this.numPercentMin.Value; |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
236 cat.MaximumPercentage = (int)this.numPercentMax.Value; |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
237 |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
238 system.AddCategory(cat); |
8 | 239 updateCategoryList(); |
240 clearCategory(); | |
6
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
241 } |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
242 |
8 | 243 private void btnCategoryRemove_Click(object sender, EventArgs e) |
6
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
244 { |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
245 foreach(IBBoard.WarFoundry.API.Objects.Category cat in system.Categories) |
0 | 246 { |
6
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
247 if(cat.Name == this.listCategories.SelectedItem) |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
248 { |
8 | 249 system.RemoveCategory(cat.ID); |
250 this.listCategories.ClearSelected(); | |
251 break; | |
6
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
252 } |
0 | 253 } |
8 | 254 updateCategoryList(); |
255 } | |
256 | |
257 private void txtCategoryName_TextChanged(object sender, EventArgs e) | |
258 { | |
259 if (this.UpdateCategory) | |
260 { | |
261 this.btnCategoryApply.Enabled = true; | |
262 } | |
263 else | |
264 { | |
265 this.btnCategoryApply.Enabled = false; | |
266 } | |
267 } | |
268 | |
269 private void txtCategoryID_TextChanged(object sender, EventArgs e) | |
270 { | |
271 if (this.UpdateCategory) | |
272 { | |
273 this.btnCategoryApply.Enabled = true; | |
274 } | |
275 else | |
276 { | |
277 this.btnCategoryApply.Enabled = false; | |
278 } | |
6
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
279 } |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
280 |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
281 private void btnGenerateCatID_Click(object sender, EventArgs e) |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
282 { |
d63df495cf5a
Implemented initial support for adding and editing categories.
Tsudico
parents:
4
diff
changeset
|
283 this.txtCategoryID.Text = generateID(this.txtCategoryName.Text); |
0 | 284 } |
8 | 285 |
286 private void cbPointMin_CheckedChanged(object sender, EventArgs e) | |
287 { | |
288 if(this.cbPointMin.Checked) | |
289 { | |
290 this.numPointMin.Enabled = true; | |
291 } | |
292 else | |
293 { | |
294 this.numPointMin.Enabled = false; | |
295 } | |
296 if(this.UpdateCategory) | |
297 { | |
298 this.btnCategoryApply.Enabled = true; | |
299 } | |
300 else | |
301 { | |
302 this.btnCategoryApply.Enabled = false; | |
303 } | |
304 } | |
305 | |
306 private void cbPointMax_CheckedChanged(object sender, EventArgs e) | |
307 { | |
308 if (this.cbPointMax.Checked) | |
309 { | |
310 this.numPointMax.Enabled = true; | |
311 } | |
312 else | |
313 { | |
314 this.numPointMax.Enabled = false; | |
315 } | |
316 if (this.UpdateCategory) | |
317 { | |
318 this.btnCategoryApply.Enabled = true; | |
319 } | |
320 else | |
321 { | |
322 this.btnCategoryApply.Enabled = false; | |
323 } | |
324 } | |
325 | |
326 private void cbPercentMin_CheckedChanged(object sender, EventArgs e) | |
327 { | |
328 if (this.cbPercentMin.Checked) | |
329 { | |
330 this.numPercentMin.Enabled = true; | |
331 } | |
332 else | |
333 { | |
334 this.numPercentMin.Enabled = false; | |
335 } | |
336 if (this.UpdateCategory) | |
337 { | |
338 this.btnCategoryApply.Enabled = true; | |
339 } | |
340 else | |
341 { | |
342 this.btnCategoryApply.Enabled = false; | |
343 } | |
344 } | |
345 | |
346 private void cbPercentMax_CheckedChanged(object sender, EventArgs e) | |
347 { | |
348 if (this.cbPercentMax.Checked) | |
349 { | |
350 this.numPercentMax.Enabled = true; | |
351 } | |
352 else | |
353 { | |
354 this.numPercentMax.Enabled = false; | |
355 } | |
356 if (this.UpdateCategory) | |
357 { | |
358 this.btnCategoryApply.Enabled = true; | |
359 } | |
360 else | |
361 { | |
362 this.btnCategoryApply.Enabled = false; | |
363 } | |
364 } | |
365 | |
366 private void numPointMin_ValueChanged(object sender, EventArgs e) | |
367 { | |
368 if (this.UpdateCategory) | |
369 { | |
370 this.btnCategoryApply.Enabled = true; | |
371 } | |
372 else | |
373 { | |
374 this.btnCategoryApply.Enabled = false; | |
375 } | |
376 } | |
377 | |
378 private void numPointMax_ValueChanged(object sender, EventArgs e) | |
379 { | |
380 if (this.UpdateCategory) | |
381 { | |
382 this.btnCategoryApply.Enabled = true; | |
383 } | |
384 else | |
385 { | |
386 this.btnCategoryApply.Enabled = false; | |
387 } | |
388 } | |
389 | |
390 private void numPercentMin_ValueChanged(object sender, EventArgs e) | |
391 { | |
392 if (this.UpdateCategory) | |
393 { | |
394 this.btnCategoryApply.Enabled = true; | |
395 } | |
396 else | |
397 { | |
398 this.btnCategoryApply.Enabled = false; | |
399 } | |
400 } | |
401 | |
402 private void numPercentMax_ValueChanged(object sender, EventArgs e) | |
403 { | |
404 if (this.UpdateCategory) | |
405 { | |
406 this.btnCategoryApply.Enabled = true; | |
407 } | |
408 else | |
409 { | |
410 this.btnCategoryApply.Enabled = false; | |
411 } | |
412 } | |
0 | 413 } |
414 } |