comparison FrmSystem.cs @ 15:3a347947ecea

Updates to Categories and Stat Lines Categories Adjusted some things behind the scenes. Stat Lines Added functionality of already existing buttons.
author Tsudico
date Wed, 22 Dec 2010 18:35:52 -0600
parents 26f7f6d2b4f8
children 489d36b167a6
comparison
equal deleted inserted replaced
14:26f7f6d2b4f8 15:3a347947ecea
65 && !this.cbPercentMax.Checked) 65 && !this.cbPercentMax.Checked)
66 { 66 {
67 return true; 67 return true;
68 } 68 }
69 else if (currentCategory.MaximumPercentage != this.numPercentMax.Value) 69 else if (currentCategory.MaximumPercentage != this.numPercentMax.Value)
70 {
71 return true;
72 }
73 }
74 return false;
75 }
76 }
77
78 private bool UpdateSystemStats
79 {
80 get
81 {
82 if(currentStats == null)
83 {
84 return false;
85 }
86 if(currentStats.ID != this.txtStatLineID.Text)
87 {
88 return true;
89 }
90 if(currentStats.SlotCount != this.listCategories.Items.Count)
91 {
92 return true;
93 }
94 if(system.GetSystemStatsForID(currentStats.ID).SlotCount != currentStats.SlotCount)
95 {
96 return true;
97 }
98 for(int i = 0; i < currentStats.SlotCount; i++)
99 {
100 if(system.GetSystemStatsForID(currentStats.ID).StatSlots[i].Name == currentStats.StatSlots[i].Name)
70 { 101 {
71 return true; 102 return true;
72 } 103 }
73 } 104 }
74 return false; 105 return false;
138 this.numPercentMax.Value = 100; 169 this.numPercentMax.Value = 100;
139 this.numPercentMax.Enabled = false; 170 this.numPercentMax.Enabled = false;
140 currentCategory = null; 171 currentCategory = null;
141 } 172 }
142 173
174 private void clearStatLine()
175 {
176 this.txtStatName.Clear();
177 this.txtStatLineID.Clear();
178 this.listStatNames.Items.Clear();
179 this.lviewStatPreview.Columns.Clear();
180 this.lviewStatPreview.Items.Clear();
181 currentStats = null;
182 }
183
143 private void updateCategoryList() 184 private void updateCategoryList()
144 { 185 {
145 if (system.Categories.Length > 0) 186 if (system.Categories.Length > 0)
146 { 187 {
147 this.listCategories.Items.Clear(); 188 this.listCategories.Items.Clear();
176 this.lviewStats.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.HeaderSize); 217 this.lviewStats.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.HeaderSize);
177 } 218 }
178 219
179 private void updateStatLinePreview(IBBoard.WarFoundry.API.Objects.SystemStats stats) 220 private void updateStatLinePreview(IBBoard.WarFoundry.API.Objects.SystemStats stats)
180 { 221 {
222 this.lviewStatPreview.Items.Clear();
223 this.lviewStatPreview.Columns.Clear();
181 if(stats.SlotCount > 0) 224 if(stats.SlotCount > 0)
182 { 225 {
183 this.lviewStatPreview.Items.Clear();
184 this.lviewStatPreview.Columns.Clear();
185 for(int i = 0; i < stats.SlotCount; i++) 226 for(int i = 0; i < stats.SlotCount; i++)
186 { 227 {
187 System.Windows.Forms.ColumnHeader column = new ColumnHeader(); 228 System.Windows.Forms.ColumnHeader column = new ColumnHeader();
188 column.Name = generateID(stats.StatSlots[i].Name); 229 column.Name = generateID(stats.StatSlots[i].Name);
189 column.Text = stats.StatSlots[i].Name; 230 column.Text = stats.StatSlots[i].Name;
191 this.lviewStatPreview.Columns.Add(column); 232 this.lviewStatPreview.Columns.Add(column);
192 } 233 }
193 this.lviewStatPreview.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); 234 this.lviewStatPreview.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
194 this.lviewStatPreview.Items.Add(" "); 235 this.lviewStatPreview.Items.Add(" ");
195 } 236 }
237 this.btnStatLineApply.Enabled = this.UpdateSystemStats;
196 } 238 }
197 239
198 private void updateStatNames(IBBoard.WarFoundry.API.Objects.SystemStats stats) 240 private void updateStatNames(IBBoard.WarFoundry.API.Objects.SystemStats stats)
199 { 241 {
242 this.listStatNames.Items.Clear();
200 if (stats.SlotCount > 0) 243 if (stats.SlotCount > 0)
201 { 244 {
202 this.listStatNames.Items.Clear();
203 for (int i = 0; i < stats.SlotCount; i++) 245 for (int i = 0; i < stats.SlotCount; i++)
204 { 246 {
205 this.listStatNames.Items.Add(stats.StatSlots[i].Name); 247 this.listStatNames.Items.Add(stats.StatSlots[i].Name);
206 } 248 }
207 } 249 }
220 private void listCategories_SelectedIndexChanged(object sender, EventArgs e) 262 private void listCategories_SelectedIndexChanged(object sender, EventArgs e)
221 { 263 {
222 currentCategory = null; 264 currentCategory = null;
223 foreach (IBBoard.WarFoundry.API.Objects.Category cat in system.Categories) 265 foreach (IBBoard.WarFoundry.API.Objects.Category cat in system.Categories)
224 { 266 {
225 if (cat.Name == this.listCategories.SelectedItem) 267 if (cat.Name == (string)this.listCategories.SelectedItem)
226 { 268 {
227 currentCategory = cat; 269 currentCategory = cat;
228 this.txtCategoryName.Text = currentCategory.Name; 270 this.txtCategoryName.Text = currentCategory.Name;
229 this.txtCategoryID.Text = currentCategory.ID; 271 this.txtCategoryID.Text = currentCategory.ID;
230 if (currentCategory.MinimumPoints > 0) 272 if (currentCategory.MinimumPoints > 0)
237 { 279 {
238 this.cbPointMin.Checked = false; 280 this.cbPointMin.Checked = false;
239 this.numPointMin.Enabled = false; 281 this.numPointMin.Enabled = false;
240 } 282 }
241 if (currentCategory.MaximumPoints > 0 283 if (currentCategory.MaximumPoints > 0
242 && currentCategory.MaximumPoints < this.numPercentMax.Maximum) 284 && currentCategory.MaximumPoints < this.numPointMax.Maximum)
243 { 285 {
244 this.numPointMax.Value = currentCategory.MaximumPoints; 286 this.numPointMax.Value = currentCategory.MaximumPoints;
245 this.cbPointMax.Checked = true; 287 this.cbPointMax.Checked = true;
246 this.numPointMax.Enabled = true; 288 this.numPointMax.Enabled = true;
247 } 289 }
325 367
326 private void btnCategoryRemove_Click(object sender, EventArgs e) 368 private void btnCategoryRemove_Click(object sender, EventArgs e)
327 { 369 {
328 foreach(IBBoard.WarFoundry.API.Objects.Category cat in system.Categories) 370 foreach(IBBoard.WarFoundry.API.Objects.Category cat in system.Categories)
329 { 371 {
330 if(cat.Name == this.listCategories.SelectedItem) 372 if(cat.Name == (string)this.listCategories.SelectedItem)
331 { 373 {
332 system.RemoveCategory(cat.ID); 374 system.RemoveCategory(cat.ID);
333 this.listCategories.ClearSelected(); 375 this.listCategories.ClearSelected();
334 this.btnCategoryRemove.Enabled = false; 376 this.btnCategoryRemove.Enabled = false;
335 break; 377 break;
392 this.listCategories.SelectedIndex = index + 1; 434 this.listCategories.SelectedIndex = index + 1;
393 } 435 }
394 436
395 private void txtCategoryName_TextChanged(object sender, EventArgs e) 437 private void txtCategoryName_TextChanged(object sender, EventArgs e)
396 { 438 {
397 if (this.UpdateCategory) 439 this.btnCategoryApply.Enabled = this.UpdateCategory;
398 { 440
399 this.btnCategoryApply.Enabled = true;
400 }
401 else
402 {
403 this.btnCategoryApply.Enabled = false;
404 }
405 if(this.txtCategoryName.Text != string.Empty && this.txtCategoryID.Text != string.Empty) 441 if(this.txtCategoryName.Text != string.Empty && this.txtCategoryID.Text != string.Empty)
406 { 442 {
407 this.btnCategoryAdd.Enabled = true; 443 this.btnCategoryAdd.Enabled = true;
408 } 444 }
409 else 445 else
412 } 448 }
413 } 449 }
414 450
415 private void txtCategoryID_TextChanged(object sender, EventArgs e) 451 private void txtCategoryID_TextChanged(object sender, EventArgs e)
416 { 452 {
417 if (this.UpdateCategory) 453 this.btnCategoryApply.Enabled = this.UpdateCategory;
418 {
419 this.btnCategoryApply.Enabled = true;
420 }
421 else
422 {
423 this.btnCategoryApply.Enabled = false;
424 }
425 } 454 }
426 455
427 private void btnGenerateCatID_Click(object sender, EventArgs e) 456 private void btnGenerateCatID_Click(object sender, EventArgs e)
428 { 457 {
429 this.txtCategoryID.Text = generateID(this.txtCategoryName.Text); 458 this.txtCategoryID.Text = generateID(this.txtCategoryName.Text);
437 } 466 }
438 else 467 else
439 { 468 {
440 this.numPointMin.Enabled = false; 469 this.numPointMin.Enabled = false;
441 } 470 }
442 if(this.UpdateCategory) 471 this.btnCategoryApply.Enabled = this.UpdateCategory;
443 {
444 this.btnCategoryApply.Enabled = true;
445 }
446 else
447 {
448 this.btnCategoryApply.Enabled = false;
449 }
450 } 472 }
451 473
452 private void cbPointMax_CheckedChanged(object sender, EventArgs e) 474 private void cbPointMax_CheckedChanged(object sender, EventArgs e)
453 { 475 {
454 if (this.cbPointMax.Checked) 476 if (this.cbPointMax.Checked)
457 } 479 }
458 else 480 else
459 { 481 {
460 this.numPointMax.Enabled = false; 482 this.numPointMax.Enabled = false;
461 } 483 }
462 if (this.UpdateCategory) 484 this.btnCategoryApply.Enabled = this.UpdateCategory;
463 {
464 this.btnCategoryApply.Enabled = true;
465 }
466 else
467 {
468 this.btnCategoryApply.Enabled = false;
469 }
470 } 485 }
471 486
472 private void cbPercentMin_CheckedChanged(object sender, EventArgs e) 487 private void cbPercentMin_CheckedChanged(object sender, EventArgs e)
473 { 488 {
474 if (this.cbPercentMin.Checked) 489 if (this.cbPercentMin.Checked)
477 } 492 }
478 else 493 else
479 { 494 {
480 this.numPercentMin.Enabled = false; 495 this.numPercentMin.Enabled = false;
481 } 496 }
482 if (this.UpdateCategory) 497 this.btnCategoryApply.Enabled = this.UpdateCategory;
483 {
484 this.btnCategoryApply.Enabled = true;
485 }
486 else
487 {
488 this.btnCategoryApply.Enabled = false;
489 }
490 } 498 }
491 499
492 private void cbPercentMax_CheckedChanged(object sender, EventArgs e) 500 private void cbPercentMax_CheckedChanged(object sender, EventArgs e)
493 { 501 {
494 if (this.cbPercentMax.Checked) 502 if (this.cbPercentMax.Checked)
497 } 505 }
498 else 506 else
499 { 507 {
500 this.numPercentMax.Enabled = false; 508 this.numPercentMax.Enabled = false;
501 } 509 }
502 if (this.UpdateCategory) 510 this.btnCategoryApply.Enabled = this.UpdateCategory;
503 {
504 this.btnCategoryApply.Enabled = true;
505 }
506 else
507 {
508 this.btnCategoryApply.Enabled = false;
509 }
510 } 511 }
511 512
512 private void numPointMin_ValueChanged(object sender, EventArgs e) 513 private void numPointMin_ValueChanged(object sender, EventArgs e)
513 { 514 {
514 if (this.UpdateCategory) 515 this.btnCategoryApply.Enabled = this.UpdateCategory;
515 {
516 this.btnCategoryApply.Enabled = true;
517 }
518 else
519 {
520 this.btnCategoryApply.Enabled = false;
521 }
522 } 516 }
523 517
524 private void numPointMax_ValueChanged(object sender, EventArgs e) 518 private void numPointMax_ValueChanged(object sender, EventArgs e)
525 { 519 {
526 if (this.UpdateCategory) 520 this.btnCategoryApply.Enabled = this.UpdateCategory;
527 {
528 this.btnCategoryApply.Enabled = true;
529 }
530 else
531 {
532 this.btnCategoryApply.Enabled = false;
533 }
534 } 521 }
535 522
536 private void numPercentMin_ValueChanged(object sender, EventArgs e) 523 private void numPercentMin_ValueChanged(object sender, EventArgs e)
537 { 524 {
538 if (this.UpdateCategory) 525 this.btnCategoryApply.Enabled = this.UpdateCategory;
539 {
540 this.btnCategoryApply.Enabled = true;
541 }
542 else
543 {
544 this.btnCategoryApply.Enabled = false;
545 }
546 } 526 }
547 527
548 private void numPercentMax_ValueChanged(object sender, EventArgs e) 528 private void numPercentMax_ValueChanged(object sender, EventArgs e)
549 { 529 {
550 if (this.UpdateCategory) 530 this.btnCategoryApply.Enabled = this.UpdateCategory;
551 {
552 this.btnCategoryApply.Enabled = true;
553 }
554 else
555 {
556 this.btnCategoryApply.Enabled = false;
557 }
558 } 531 }
559 532
560 private void btnCategoryApply_Click(object sender, EventArgs e) 533 private void btnCategoryApply_Click(object sender, EventArgs e)
561 { 534 {
562 currentCategory.Name = this.txtCategoryName.Text; 535 currentCategory.Name = this.txtCategoryName.Text;
610 } 583 }
611 foreach(ListViewItem item in items) 584 foreach(ListViewItem item in items)
612 { 585 {
613 if(stat.ID == item.Text) 586 if(stat.ID == item.Text)
614 { 587 {
615 currentStats = stat; 588 currentStats = new IBBoard.WarFoundry.API.Objects.SystemStats(stat.ID);
589 foreach(IBBoard.WarFoundry.API.Objects.StatSlot slot in stat.StatSlots)
590 {
591 currentStats.AddStatSlot(slot.Name);
592 }
616 if(currentStats.ID.Equals(system.StandardSystemStatsID)) 593 if(currentStats.ID.Equals(system.StandardSystemStatsID))
617 { 594 {
618 this.btnStatsDefault.Enabled = false; 595 this.btnStatsDefault.Enabled = false;
619 } 596 }
620 else 597 else
621 { 598 {
622 this.btnStatsDefault.Enabled = true; 599 this.btnStatsDefault.Enabled = true;
623 } 600 }
624 this.txtStatLineID.Text = currentStats.ID; 601 this.txtStatLineID.Text = currentStats.ID;
602 this.txtStatName.Enabled = true;
625 updateStatNames(currentStats); 603 updateStatNames(currentStats);
626 updateStatLinePreview(currentStats); 604 updateStatLinePreview(currentStats);
627 } 605 }
628 } 606 }
629 } 607 }
608 if(this.txtStatLineID.Text == string.Empty)
609 {
610 this.txtStatName.Enabled = false;
611 }
612 }
613
614 private void btnStatsAdd_Click(object sender, EventArgs e)
615 {
616 if(this.txtStatLineID.Text == string.Empty)
617 {
618 MessageBox.Show("You must enter an ID!", "Create Stat Line Error");
619 return;
620 }
621 if (currentStats == null)
622 {
623 currentStats = new IBBoard.WarFoundry.API.Objects.SystemStats(this.txtStatLineID.Text);
624 }
625 system.AddSystemStats(currentStats);
626 clearStatLine();
627 updateSystemStatsList();
630 } 628 }
631 629
632 private void btnStatsRemove_Click(object sender, EventArgs e) 630 private void btnStatsRemove_Click(object sender, EventArgs e)
633 { 631 {
634 system.RemoveSystemStats(currentStats.ID); 632 system.RemoveSystemStats(currentStats.ID);
645 private void txtStatLineID_TextChanged(object sender, EventArgs e) 643 private void txtStatLineID_TextChanged(object sender, EventArgs e)
646 { 644 {
647 if(this.txtStatLineID.Text != string.Empty) 645 if(this.txtStatLineID.Text != string.Empty)
648 { 646 {
649 this.btnStatsAdd.Enabled = true; 647 this.btnStatsAdd.Enabled = true;
648 this.txtStatName.Enabled = true;
650 } 649 }
651 else 650 else
652 { 651 {
653 this.btnStatsAdd.Enabled = false; 652 this.btnStatsAdd.Enabled = false;
653 this.txtStatName.Enabled = false;
654 this.btnStatListAdd.Enabled = false;
654 } 655 }
655 } 656 }
656 657
657 private void txtStatName_TextChanged(object sender, EventArgs e) 658 private void txtStatName_TextChanged(object sender, EventArgs e)
658 { 659 {
666 } 667 }
667 } 668 }
668 669
669 private void btnStatListAdd_Click(object sender, EventArgs e) 670 private void btnStatListAdd_Click(object sender, EventArgs e)
670 { 671 {
672 if(currentStats == null)
673 {
674 if(this.txtStatLineID.Text != string.Empty)
675 {
676 currentStats = new IBBoard.WarFoundry.API.Objects.SystemStats(this.txtStatLineID.Text);
677 }
678 else
679 {
680 MessageBox.Show("You must first define an ID for the stat line.", "No ID Error");
681 return;
682 }
683 }
671 if(this.txtStatName.Text != string.Empty) 684 if(this.txtStatName.Text != string.Empty)
672 { 685 {
673 currentStats.AddStatSlot(this.txtStatName.Text); 686 currentStats.AddStatSlot(this.txtStatName.Text);
674 } 687 }
688 this.txtStatName.Clear();
675 updateStatNames(currentStats); 689 updateStatNames(currentStats);
676 updateStatLinePreview(currentStats); 690 updateStatLinePreview(currentStats);
677 } 691 }
678 692
679 private void listStatNames_SelectedIndexChanged(object sender, EventArgs e) 693 private void listStatNames_SelectedIndexChanged(object sender, EventArgs e)
770 } 784 }
771 785
772 private void btnStatLineApply_Click(object sender, EventArgs e) 786 private void btnStatLineApply_Click(object sender, EventArgs e)
773 { 787 {
774 system.SetSystemStats(currentStats); 788 system.SetSystemStats(currentStats);
789 clearStatLine();
775 } 790 }
776 } 791 }
777 } 792 }