Mercurial > repos > WarFoundryForge
comparison 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 |
comparison
equal
deleted
inserted
replaced
7:d4c03cc5bfb7 | 8:0dadaa315430 |
---|---|
14 { | 14 { |
15 public partial class FrmSystem : IBBoard.Windows.Forms.IBBForm | 15 public partial class FrmSystem : IBBoard.Windows.Forms.IBBForm |
16 { | 16 { |
17 private IBBoard.WarFoundry.API.Objects.GameSystem system; | 17 private IBBoard.WarFoundry.API.Objects.GameSystem system; |
18 | 18 |
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 | |
19 public FrmSystem(IBBoard.WarFoundry.API.Objects.GameSystem loadSystem) | 76 public FrmSystem(IBBoard.WarFoundry.API.Objects.GameSystem loadSystem) |
20 { | 77 { |
21 InitializeComponent(); | 78 InitializeComponent(); |
22 system = loadSystem; | 79 system = loadSystem; |
23 this.txtSystemName.Text = system.Name; | 80 this.txtSystemName.Text = system.Name; |
24 this.txtSystemId.Text = system.ID; | 81 this.txtSystemId.Text = system.ID; |
82 this.numDefaultSize.Value = system.SystemArmyDefaultSize; | |
83 this.numPointMax.Value = this.numDefaultSize.Value; | |
25 if(system.AllowAllies) | 84 if(system.AllowAllies) |
26 { | 85 { |
27 this.radSystemAlliesYes.Checked = true; | 86 this.radSystemAlliesYes.Checked = true; |
28 } | 87 } |
29 else | 88 else |
36 } | 95 } |
37 else | 96 else |
38 { | 97 { |
39 this.radSystemWarnNo.Checked = true; | 98 this.radSystemWarnNo.Checked = true; |
40 } | 99 } |
41 if(system.Categories.Length > 0) | 100 updateCategoryList(); |
101 } | |
102 | |
103 private string generateID(string name) | |
104 { | |
105 string newId = String.Empty; | |
106 | |
107 MatchCollection id_parts = Regex.Matches(name, @"[A-Z\d]"); | |
108 foreach (Match part in id_parts) | |
109 { | |
110 newId += part.ToString(); | |
111 } | |
112 | |
113 if (newId.Length < 3) | |
114 { | |
115 newId = name.ToLower().Replace(" ", ""); | |
116 } | |
117 | |
118 return newId.ToLower(); | |
119 } | |
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) | |
42 { | 142 { |
43 this.listCategories.Items.Clear(); | 143 this.listCategories.Items.Clear(); |
44 for(int i = 0; i < system.Categories.Length; i++) | 144 for (int i = 0; i < system.Categories.Length; i++) |
45 { | 145 { |
46 this.listCategories.Items.Add(system.Categories[i].Name); | 146 this.listCategories.Items.Add(system.Categories[i].Name); |
47 } | 147 } |
48 } | 148 } |
49 } | 149 } |
50 | |
51 private string generateID(string name) | |
52 { | |
53 string newId = String.Empty; | |
54 | |
55 MatchCollection id_parts = Regex.Matches(name, @"[A-Z\d]"); | |
56 foreach (Match part in id_parts) | |
57 { | |
58 newId += part.ToString(); | |
59 } | |
60 | |
61 if (newId.Length < 3) | |
62 { | |
63 newId = name.ToLower().Replace(" ", ""); | |
64 } | |
65 | |
66 return newId.ToLower(); | |
67 } | |
68 | 150 |
69 private void btnSystemClose_Click(object sender, EventArgs e) | 151 private void btnSystemClose_Click(object sender, EventArgs e) |
70 { | 152 { |
71 this.Close(); | 153 this.Close(); |
72 } | 154 } |
73 | 155 |
74 private void btnGenerateSysId_Click(object sender, EventArgs e) | 156 private void btnGenerateSysId_Click(object sender, EventArgs e) |
75 { | 157 { |
76 this.txtSystemId.Text = generateID(this.txtSystemName.Text); | 158 this.txtSystemId.Text = generateID(this.txtSystemName.Text); |
159 } | |
160 | |
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 } | |
77 } | 214 } |
78 | 215 |
79 private void btnCategoryAdd_Click(object sender, EventArgs e) | 216 private void btnCategoryAdd_Click(object sender, EventArgs e) |
80 { | 217 { |
81 if(this.txtCategoryName.Text == string.Empty) | 218 if(this.txtCategoryName.Text == string.Empty) |
97 cat.MaximumPoints = (int)this.numPointMax.Value; | 234 cat.MaximumPoints = (int)this.numPointMax.Value; |
98 cat.MinimumPercentage = (int)this.numPercentMin.Value; | 235 cat.MinimumPercentage = (int)this.numPercentMin.Value; |
99 cat.MaximumPercentage = (int)this.numPercentMax.Value; | 236 cat.MaximumPercentage = (int)this.numPercentMax.Value; |
100 | 237 |
101 system.AddCategory(cat); | 238 system.AddCategory(cat); |
102 | 239 updateCategoryList(); |
103 if (system.Categories.Length > 0) | 240 clearCategory(); |
104 { | 241 } |
105 this.listCategories.Items.Clear(); | 242 |
106 for (int i = 0; i < system.Categories.Length; i++) | 243 private void btnCategoryRemove_Click(object sender, EventArgs e) |
107 { | |
108 this.listCategories.Items.Add(system.Categories[i].Name); | |
109 } | |
110 } | |
111 } | |
112 | |
113 private void btnCategoryEdit_Click(object sender, EventArgs e) | |
114 { | 244 { |
115 foreach(IBBoard.WarFoundry.API.Objects.Category cat in system.Categories) | 245 foreach(IBBoard.WarFoundry.API.Objects.Category cat in system.Categories) |
116 { | 246 { |
117 if(cat.Name == this.listCategories.SelectedItem) | 247 if(cat.Name == this.listCategories.SelectedItem) |
118 { | 248 { |
119 this.txtCategoryName.Text = cat.Name; | 249 system.RemoveCategory(cat.ID); |
120 this.txtCategoryID.Text = cat.ID; | 250 this.listCategories.ClearSelected(); |
121 if(cat.MinimumPoints >= 0) | 251 break; |
122 { | |
123 this.numPointMin.Value = cat.MinimumPoints; | |
124 } | |
125 if(cat.MaximumPoints > 0 && cat.MaximumPoints < this.numPointMax.Maximum) | |
126 { | |
127 this.numPointMax.Value = cat.MaximumPoints; | |
128 } | |
129 if(cat.MinimumPercentage >= 0) | |
130 { | |
131 this.numPercentMin.Value = cat.MinimumPercentage; | |
132 } | |
133 if(cat.MaximumPercentage <= 100) | |
134 { | |
135 this.numPercentMax.Value = cat.MaximumPercentage; | |
136 } | |
137 } | 252 } |
138 } | 253 } |
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 } | |
139 } | 279 } |
140 | 280 |
141 private void btnGenerateCatID_Click(object sender, EventArgs e) | 281 private void btnGenerateCatID_Click(object sender, EventArgs e) |
142 { | 282 { |
143 this.txtCategoryID.Text = generateID(this.txtCategoryName.Text); | 283 this.txtCategoryID.Text = generateID(this.txtCategoryName.Text); |
284 } | |
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 } | |
144 } | 412 } |
145 } | 413 } |
146 } | 414 } |