comparison FrmAddEquipment.cs @ 61:e7ad676a7344

Re #60: Add UI to add/remove/edit weapons in GTK * Add events to track equipment amount and amount changing * Select most appropriate equipment type by default * Add methods an implementation for enabling/disabling Okay button
author IBBoard <dev@ibboard.co.uk>
date Sun, 29 Aug 2010 15:09:34 +0000
parents 293d204e40db
children f733073967a2
comparison
equal deleted inserted replaced
60:04c0f6a7625c 61:e7ad676a7344
14 public partial class FrmAddEquipment : Dialog, IAddEquipmentUI 14 public partial class FrmAddEquipment : Dialog, IAddEquipmentUI
15 { 15 {
16 private static ILog log = LogManager.GetLogger(typeof(FrmAddEquipment)); 16 private static ILog log = LogManager.GetLogger(typeof(FrmAddEquipment));
17 17
18 public event SingleArgMethodInvoker<UnitEquipmentItem> UnitEquipmentItemChoiceChanged; 18 public event SingleArgMethodInvoker<UnitEquipmentItem> UnitEquipmentItemChoiceChanged;
19 public event MethodInvoker UnitEquipmentAmountTypeChanged;
20 public event MethodInvoker UnitEquipmentAmountChanged;
19 21
20 private bool limitsEnabled = false; 22 private bool limitsEnabled = false;
21 private bool ratioLimited = false; 23 private bool ratioLimited = false;
22 24
23 public FrmAddEquipment() 25 public FrmAddEquipment()
27 TreeViewColumn equipColumn = new TreeViewColumn(); 29 TreeViewColumn equipColumn = new TreeViewColumn();
28 equipColumn.Title = "Equipment"; 30 equipColumn.Title = "Equipment";
29 CellRendererText equipCell = new CellRendererText(); 31 CellRendererText equipCell = new CellRendererText();
30 equipColumn.PackStart(equipCell, true); 32 equipColumn.PackStart(equipCell, true);
31 equipColumn.SetCellDataFunc(equipCell, GtkWarFoundryUtil.RenderWarFoundryObjectName); 33 equipColumn.SetCellDataFunc(equipCell, GtkWarFoundryUtil.RenderWarFoundryObjectName);
32 lstEquipment.AppendColumn(equipColumn); 34 lstEquipment.AppendColumn(equipColumn);
33 } 35 }
34 36
35 protected virtual void OnSelectionChanged(object o, EventArgs e) 37 private void OnUnitEquipmentAmountChanged()
38 {
39 if (UnitEquipmentAmountChanged != null)
40 {
41 UnitEquipmentAmountChanged();
42 }
43 }
44
45 private void OnUnitEquipmentAmountTypeChanged()
46 {
47 if (UnitEquipmentAmountChanged != null)
48 {
49 UnitEquipmentAmountTypeChanged();
50 }
51 }
52
53 protected void OnSelectionChanged(object o, EventArgs e)
36 { 54 {
37 if (UnitEquipmentItemChoiceChanged!=null) 55 if (UnitEquipmentItemChoiceChanged!=null)
38 { 56 {
39 UnitEquipmentItemChoiceChanged(SelectedUnitEquipmentItem); 57 UnitEquipmentItemChoiceChanged(SelectedUnitEquipmentItem);
40 } 58 }
54 72
55 public void SetUnitEquipmentLimits(bool isRatioLimit, double minPercent, double maxPercent, int minNumber, int maxNumber) 73 public void SetUnitEquipmentLimits(bool isRatioLimit, double minPercent, double maxPercent, int minNumber, int maxNumber)
56 { 74 {
57 log.DebugFormat("IsRatio? {0}. Limits: {1}->{2}, {3}%->{4}%", isRatioLimit, minNumber, maxNumber, minPercent, maxPercent); 75 log.DebugFormat("IsRatio? {0}. Limits: {1}->{2}, {3}%->{4}%", isRatioLimit, minNumber, maxNumber, minPercent, maxPercent);
58 ratioLimited = isRatioLimit; 76 ratioLimited = isRatioLimit;
59 SetEnabledState();
60 numericAmount.SetRange(minNumber, maxNumber); 77 numericAmount.SetRange(minNumber, maxNumber);
61 percentageAmount.SetRange(minPercent, maxPercent); 78 percentageAmount.SetRange(minPercent, maxPercent);
79
80 if (isRatioLimit)
81 {
82 if (minPercent == 100)
83 {
84 rbEquipAll.Active = true;
85 }
86 else
87 {
88 rbEquipPercent.Active = true;
89 }
90 }
91 else
92 {
93 rbEquipNumeric.Active = true;
94 }
95
96 SetEnabledState();
62 } 97 }
63 98
64 public void SetUnitEquipmentLimitsEnabled(bool isEnabled) 99 public void SetUnitEquipmentLimitsEnabled(bool isEnabled)
65 { 100 {
66 limitsEnabled = isEnabled; 101 limitsEnabled = isEnabled;
73 numericAmount.Sensitive = (limitsEnabled && !ratioLimited); 108 numericAmount.Sensitive = (limitsEnabled && !ratioLimited);
74 double minPercentage = GetMinPercentage(); 109 double minPercentage = GetMinPercentage();
75 rbEquipPercent.Sensitive = limitsEnabled && minPercentage != 100; 110 rbEquipPercent.Sensitive = limitsEnabled && minPercentage != 100;
76 percentageAmount.Sensitive = limitsEnabled && minPercentage != 100; 111 percentageAmount.Sensitive = limitsEnabled && minPercentage != 100;
77 double maxPercentage = GetMaxPercentage(); 112 double maxPercentage = GetMaxPercentage();
78 rbEquipAll.Sensitive = limitsEnabled && maxPercentage == 100; 113 rbEquipAll.Sensitive = limitsEnabled && ratioLimited && maxPercentage == 100;
79 lblEquipAll.Sensitive = limitsEnabled && maxPercentage == 100; 114 lblEquipAll.Sensitive = limitsEnabled && ratioLimited && maxPercentage == 100;
80 } 115 }
81 116
82 private double GetMaxPercentage() 117 private double GetMaxPercentage()
83 { 118 {
84 double min, max; 119 double min, max;
111 { 146 {
112 log.Debug("Okay clicked"); 147 log.Debug("Okay clicked");
113 Respond(ResponseType.Ok); 148 Respond(ResponseType.Ok);
114 } 149 }
115 150
151 public void SetOkayEnabledState (bool enabled)
152 {
153 buttonOk.Sensitive = enabled;
154 }
155
156 protected virtual void SpinButtonValueChanged (object sender, System.EventArgs e)
157 {
158 OnUnitEquipmentAmountChanged();
159 }
160
161 protected virtual void RadioButtonClicked(object sender, System.EventArgs e)
162 {
163 OnUnitEquipmentAmountTypeChanged();
164 }
165
166
116 public UnitEquipmentItem SelectedUnitEquipmentItem 167 public UnitEquipmentItem SelectedUnitEquipmentItem
117 { 168 {
118 get 169 get
119 { 170 {
120 return (UnitEquipmentItem)TreeUtils.GetSelectedItem(lstEquipment); 171 return (UnitEquipmentItem)TreeUtils.GetSelectedItem(lstEquipment);