Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
comparison FrmAddEquipment.cs @ 70:4b82515586ac
Re #60: Add UI to add/remove/edit weapons in GTK
* Fix widget enabling/disabling (sometimes enabling ratio input for numeric limit)
* Correct behaviour of Edit dialog (setting wrong value on edit)
* Add setting of limits based on specific equipment item to base dialog controller
* Make sure that we catch all radio button click events from Edit dialog
* Add ability to ignore and listen to widgets to make sure that changes don't cascade
TODO: See if code can be tidied up and common classes created
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 06 Nov 2010 17:03:13 +0000 |
parents | c2d79b4209e3 |
children | 7055b24cfc79 |
comparison
equal
deleted
inserted
replaced
69:3b4a646b4054 | 70:4b82515586ac |
---|---|
1 // This file (FrmAddEquipment.cs) is a part of the IBBoard.WarFoundry.GUI.GTK project and is copyright 2010 IBBoard | 1 // This file (FrmAddEquipment.cs) is a part of the IBBoard.WarFoundry.GUI.GTK project and is copyright 2010 IBBoard |
2 // | 2 // |
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. | 3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. |
4 | |
4 using System; | 5 using System; |
5 using IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces; | 6 using IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces; |
6 using IBBoard.WarFoundry.API.Objects; | 7 using IBBoard.WarFoundry.API.Objects; |
7 using Gtk; | 8 using Gtk; |
8 using IBBoard.WarFoundry.GUI.GTK.Util; | 9 using IBBoard.WarFoundry.GUI.GTK.Util; |
9 using IBBoard.GtkSharp; | 10 using IBBoard.GtkSharp; |
10 using log4net.Repository.Hierarchy; | 11 using log4net.Repository.Hierarchy; |
11 using log4net; | 12 using log4net; |
13 | |
12 namespace IBBoard.WarFoundry.GUI.GTK | 14 namespace IBBoard.WarFoundry.GUI.GTK |
13 { | 15 { |
14 public partial class FrmAddEquipment : Dialog, IAddEquipmentUI | 16 public partial class FrmAddEquipment : Dialog, IAddEquipmentUI |
15 { | 17 { |
16 private static ILog log = LogManager.GetLogger(typeof(FrmAddEquipment)); | 18 private static ILog log = LogManager.GetLogger(typeof(FrmAddEquipment)); |
17 | 19 |
18 public event SingleArgMethodInvoker<UnitEquipmentItem> UnitEquipmentItemChoiceChanged; | 20 public event SingleArgMethodInvoker<UnitEquipmentItem> UnitEquipmentItemChoiceChanged; |
21 | |
19 public event MethodInvoker UnitEquipmentAmountTypeChanged; | 22 public event MethodInvoker UnitEquipmentAmountTypeChanged; |
23 | |
20 public event MethodInvoker UnitEquipmentAmountChanged; | 24 public event MethodInvoker UnitEquipmentAmountChanged; |
21 | 25 private bool isRatioLimited; |
22 private bool limitsEnabled = false; | |
23 private bool ratioLimited = false; | |
24 | 26 |
25 public FrmAddEquipment() | 27 public FrmAddEquipment() |
26 { | 28 { |
27 this.Build(); | 29 this.Build(); |
28 lstEquipment.Selection.Changed += OnSelectionChanged; | 30 lstEquipment.Selection.Changed += OnSelectionChanged; |
50 } | 52 } |
51 } | 53 } |
52 | 54 |
53 protected void OnSelectionChanged(object o, EventArgs e) | 55 protected void OnSelectionChanged(object o, EventArgs e) |
54 { | 56 { |
55 if (UnitEquipmentItemChoiceChanged!=null) | 57 if (UnitEquipmentItemChoiceChanged != null) |
56 { | 58 { |
57 UnitEquipmentItemChoiceChanged(SelectedUnitEquipmentItem); | 59 UnitEquipmentItemChoiceChanged(SelectedUnitEquipmentItem); |
58 } | 60 } |
59 } | 61 } |
60 | 62 |
71 } | 73 } |
72 | 74 |
73 public void SetUnitEquipmentLimits(bool isRatioLimit, double minPercent, double maxPercent, int minNumber, int maxNumber) | 75 public void SetUnitEquipmentLimits(bool isRatioLimit, double minPercent, double maxPercent, int minNumber, int maxNumber) |
74 { | 76 { |
75 log.DebugFormat("IsRatio? {0}. Limits: {1}->{2}, {3}%->{4}%", isRatioLimit, minNumber, maxNumber, minPercent, maxPercent); | 77 log.DebugFormat("IsRatio? {0}. Limits: {1}->{2}, {3}%->{4}%", isRatioLimit, minNumber, maxNumber, minPercent, maxPercent); |
76 ratioLimited = isRatioLimit; | |
77 numericAmount.SetRange(minNumber, maxNumber); | 78 numericAmount.SetRange(minNumber, maxNumber); |
78 percentageAmount.SetRange(minPercent, maxPercent); | 79 percentageAmount.SetRange(minPercent, maxPercent); |
79 | 80 |
80 if (isRatioLimit) | 81 if (isRatioLimit) |
81 { | 82 { |
90 } | 91 } |
91 else | 92 else |
92 { | 93 { |
93 rbEquipNumeric.Active = true; | 94 rbEquipNumeric.Active = true; |
94 } | 95 } |
96 | |
97 isRatioLimited = isRatioLimit; | |
95 } | 98 } |
96 | 99 |
97 public void SetUnitEquipmentLimitsEnabled(bool isEnabled) | 100 public void SetUnitEquipmentLimitsEnabled(bool isEnabled) |
98 { | 101 { |
99 SetNumericAmountEnabledState(isEnabled); | 102 SetNumericAmountEnabledState(isEnabled); |
118 { | 121 { |
119 log.Debug("Okay clicked"); | 122 log.Debug("Okay clicked"); |
120 Respond(ResponseType.Ok); | 123 Respond(ResponseType.Ok); |
121 } | 124 } |
122 | 125 |
123 public void SetOkayEnabledState (bool enabled) | 126 public void SetOkayEnabledState(bool enabled) |
124 { | 127 { |
125 buttonOk.Sensitive = enabled; | 128 buttonOk.Sensitive = enabled; |
126 } | 129 } |
127 | 130 |
128 protected virtual void SpinButtonValueChanged (object sender, System.EventArgs e) | 131 protected virtual void SpinButtonValueChanged(object sender, System.EventArgs e) |
129 { | 132 { |
130 OnUnitEquipmentAmountChanged(); | 133 OnUnitEquipmentAmountChanged(); |
131 } | 134 } |
132 | 135 |
133 protected virtual void RadioButtonClicked(object sender, System.EventArgs e) | 136 protected virtual void RadioButtonClicked(object sender, System.EventArgs e) |
134 { | 137 { |
135 OnUnitEquipmentAmountTypeChanged(); | 138 OnUnitEquipmentAmountTypeChanged(); |
136 } | 139 } |
137 | 140 |
138 public void SetNumericAmountEnabledState (bool enabled) | 141 public void SetNumericAmountEnabledState(bool enabled) |
139 { | 142 { |
140 rbEquipNumeric.Sensitive = enabled; | 143 double minPercent = GetMinPercentage(); |
141 numericAmount.Sensitive = enabled; | 144 rbEquipNumeric.Sensitive = enabled && !(isRatioLimited && minPercent == 100); |
145 numericAmount.Sensitive = rbEquipNumeric.Sensitive; | |
142 } | 146 } |
143 | 147 |
144 public void SetPercentageAmountEnabledState(bool enabled) | 148 public void SetPercentageAmountEnabledState(bool enabled) |
145 { | 149 { |
146 if (enabled) | 150 if (enabled) |
147 { | 151 { |
148 double minPercentage = GetMinPercentage(); | 152 double minPercentage = GetMinPercentage(); |
149 rbEquipPercent.Sensitive = minPercentage != 100; | 153 rbEquipPercent.Sensitive = isRatioLimited && minPercentage != 100; |
150 percentageAmount.Sensitive = minPercentage != 100; | 154 percentageAmount.Sensitive = rbEquipPercent.Sensitive; |
151 double maxPercentage = GetMaxPercentage(); | 155 double maxPercentage = GetMaxPercentage(); |
152 rbEquipAll.Sensitive = ratioLimited && maxPercentage == 100; | 156 rbEquipAll.Sensitive = isRatioLimited && maxPercentage == 100; |
153 lblEquipAll.Sensitive = ratioLimited && maxPercentage == 100; | 157 lblEquipAll.Sensitive = rbEquipAll.Sensitive; |
154 } | 158 } |
155 else | 159 else |
156 { | 160 { |
157 rbEquipPercent.Sensitive = false; | 161 rbEquipPercent.Sensitive = false; |
158 percentageAmount.Sensitive = false; | 162 percentageAmount.Sensitive = false; |
173 double min, max; | 177 double min, max; |
174 percentageAmount.GetRange(out min, out max); | 178 percentageAmount.GetRange(out min, out max); |
175 return min; | 179 return min; |
176 } | 180 } |
177 | 181 |
182 public void ListenToWidgets() | |
183 { | |
184 rbEquipAll.Clicked += RadioButtonClicked; | |
185 rbEquipNumeric.Clicked += RadioButtonClicked; | |
186 rbEquipPercent.Clicked += RadioButtonClicked; | |
187 numericAmount.ValueChanged += SpinButtonValueChanged; | |
188 percentageAmount.ValueChanged += SpinButtonValueChanged; | |
189 lstEquipment.Selection.Changed += OnSelectionChanged; | |
190 } | |
191 | |
192 public void IgnoreWidgets() | |
193 { | |
194 rbEquipAll.Clicked -= RadioButtonClicked; | |
195 rbEquipNumeric.Clicked -= RadioButtonClicked; | |
196 rbEquipPercent.Clicked -= RadioButtonClicked; | |
197 numericAmount.ValueChanged -= SpinButtonValueChanged; | |
198 percentageAmount.ValueChanged -= SpinButtonValueChanged; | |
199 lstEquipment.Selection.Changed -= OnSelectionChanged; | |
200 } | |
201 | |
178 public UnitEquipmentItem SelectedUnitEquipmentItem | 202 public UnitEquipmentItem SelectedUnitEquipmentItem |
179 { | 203 { |
180 get | 204 get |
181 { | 205 { |
182 return (UnitEquipmentItem)TreeUtils.GetSelectedItem(lstEquipment); | 206 return (UnitEquipmentItem)TreeUtils.GetSelectedItem(lstEquipment); |
183 } | 207 } |
184 } | 208 } |
185 | 209 |
186 | |
187 public bool IsRatioEquipmentAmount | 210 public bool IsRatioEquipmentAmount |
188 { | 211 { |
189 get | 212 get |
190 { | 213 { |
191 return !rbEquipNumeric.Active; | 214 return !rbEquipNumeric.Active; |
192 } | 215 } |
193 } | 216 } |
194 | 217 |
195 | |
196 public int EquipmentNumericAmount | 218 public int EquipmentNumericAmount |
197 { | 219 { |
198 get | 220 get |
199 { | 221 { |
200 return (int)numericAmount.Value; | 222 return (int)numericAmount.Value; |
203 set | 225 set |
204 { | 226 { |
205 numericAmount.Value = value; | 227 numericAmount.Value = value; |
206 } | 228 } |
207 } | 229 } |
208 | |
209 | 230 |
210 public double EquipmentPercentageAmount | 231 public double EquipmentPercentageAmount |
211 { | 232 { |
212 get | 233 get |
213 { | 234 { |