comparison UIControl/AddEquipmentUIControl.cs @ 56:0c5fbb54bfb0

Re #60: Add UI to add/remove/edit weapons in GTK * Refactor enabling/disabling of radio buttons * Handle null selections * Move Dispose() to be an interface method and move call out to controller
author IBBoard <dev@ibboard.co.uk>
date Wed, 25 Aug 2010 20:04:27 +0000
parents eb7db8495bb5
children 293d204e40db
comparison
equal deleted inserted replaced
55:eb7db8495bb5 56:0c5fbb54bfb0
22 } 22 }
23 23
24 private void SetupUI() 24 private void SetupUI()
25 { 25 {
26 CreateEquipmentUI(); 26 CreateEquipmentUI();
27 ui.SetUnitEquipmentLimitsEnabled(false);
27 UnitEquipmentItem[] items = Arrays.Subtract(UnitEquipmentUtil.GetAllowedEquipmentItems(unit), unit.GetEquipment()); 28 UnitEquipmentItem[] items = Arrays.Subtract(UnitEquipmentUtil.GetAllowedEquipmentItems(unit), unit.GetEquipment());
28 ui.SetUnitEquipmentItems(items); 29 ui.SetUnitEquipmentItems(items);
29 ui.UnitEquipmentItemChoiceChanged += HandleUiUnitEquipmentItemChoiceChanged; 30 ui.UnitEquipmentItemChoiceChanged += HandleUiUnitEquipmentItemChoiceChanged;
30 } 31 }
31 32
35 ui = new FrmAddEquipment(); 36 ui = new FrmAddEquipment();
36 } 37 }
37 38
38 private void HandleUiUnitEquipmentItemChoiceChanged(UnitEquipmentItem equip) 39 private void HandleUiUnitEquipmentItemChoiceChanged(UnitEquipmentItem equip)
39 { 40 {
40 bool equipIsRatioLimit = UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip); 41 if (equip != null)
41 double maxPercent = RoundPercentage(UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); 42 {
42 maxPercent = Math.Max(0, maxPercent); 43 bool equipIsRatioLimit = UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip);
43 double minPercent = RoundPercentage(UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); 44 double maxPercent = RoundPercentage(UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
44 minPercent = Math.Max(0, minPercent); 45 maxPercent = Math.Max(0, maxPercent);
45 int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip); 46 double minPercent = RoundPercentage(UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
46 maxNumber = Math.Max(0, maxNumber); 47 minPercent = Math.Max(0, minPercent);
47 int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip); 48 int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip);
48 minNumber = Math.Max(0, minNumber); 49 maxNumber = Math.Max(0, maxNumber);
50 int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip);
51 minNumber = Math.Max(0, minNumber);
49 52
50 ui.SetUnitEquipmentLimits(equipIsRatioLimit, minPercent, maxPercent, minNumber, maxNumber); 53 ui.SetUnitEquipmentLimits(equipIsRatioLimit, minPercent, maxPercent, minNumber, maxNumber);
51 54 ui.SetUnitEquipmentLimitsEnabled(true);
55 }
56 else
57 {
58 ui.SetUnitEquipmentLimits(true, 0, 0, 0, 0);
59 ui.SetUnitEquipmentLimitsEnabled(false);
60 }
52 } 61 }
53 62
54 private double RoundPercentage(double percent) 63 private double RoundPercentage(double percent)
55 { 64 {
56 return Math.Round(percent, 1); 65 return Math.Round(percent, 1);
57 } 66 }
58 67
59 public void Show() 68 public void Show()
60 { 69 {
61 ui.ShowControl(); 70 ui.ShowControl();
71 //Do command stuff here
72 ui.Dispose();
62 } 73 }
63 } 74 }
64 } 75 }
65 76