Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
comparison FrmEditEquipment.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 | e3fe48c4d794 |
children | 7055b24cfc79 |
comparison
equal
deleted
inserted
replaced
69:3b4a646b4054 | 70:4b82515586ac |
---|---|
1 // This file (FrmEditEquipment.cs) is a part of the IBBoard.WarFoundry.GUI.GTK project and is copyright 2010 IBBoard | 1 // This file (FrmEditEquipment.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 FrmEditEquipment : Dialog, IEditEquipmentUI | 16 public partial class FrmEditEquipment : Dialog, IEditEquipmentUI |
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; | 26 |
23 private bool ratioLimited = false; | |
24 | |
25 public FrmEditEquipment() | 27 public FrmEditEquipment() |
26 { | 28 { |
27 this.Build(); | 29 this.Build(); |
28 TreeViewColumn equipColumn = new TreeViewColumn(); | 30 TreeViewColumn equipColumn = new TreeViewColumn(); |
29 equipColumn.Title = "Equipment"; | 31 equipColumn.Title = "Equipment"; |
30 CellRendererText equipCell = new CellRendererText(); | 32 CellRendererText equipCell = new CellRendererText(); |
31 equipColumn.PackStart(equipCell, true); | 33 equipColumn.PackStart(equipCell, true); |
32 equipColumn.SetCellDataFunc(equipCell, GtkWarFoundryUtil.RenderWarFoundryObjectName); | 34 equipColumn.SetCellDataFunc(equipCell, GtkWarFoundryUtil.RenderWarFoundryObjectName); |
33 } | 35 } |
34 | 36 |
37 public void ListenToWidgets() | |
38 { | |
39 rbEquipAll.Clicked += RadioButtonClicked; | |
40 rbEquipNumeric.Clicked += RadioButtonClicked; | |
41 rbEquipPercent.Clicked += RadioButtonClicked; | |
42 numericAmount.ValueChanged += SpinButtonValueChanged; | |
43 percentageAmount.ValueChanged += SpinButtonValueChanged; | |
44 } | |
45 | |
46 public void IgnoreWidgets() | |
47 { | |
48 rbEquipAll.Clicked -= RadioButtonClicked; | |
49 rbEquipNumeric.Clicked -= RadioButtonClicked; | |
50 rbEquipPercent.Clicked -= RadioButtonClicked; | |
51 numericAmount.ValueChanged -= SpinButtonValueChanged; | |
52 percentageAmount.ValueChanged -= SpinButtonValueChanged; | |
53 } | |
54 | |
35 private void OnUnitEquipmentAmountChanged() | 55 private void OnUnitEquipmentAmountChanged() |
36 { | 56 { |
37 if (UnitEquipmentAmountChanged != null) | 57 if (UnitEquipmentAmountChanged != null) |
38 { | 58 { |
39 UnitEquipmentAmountChanged(); | 59 UnitEquipmentAmountChanged(); |
49 } | 69 } |
50 | 70 |
51 public void SetUnitEquipmentLimits(bool isRatioLimit, double minPercent, double maxPercent, int minNumber, int maxNumber) | 71 public void SetUnitEquipmentLimits(bool isRatioLimit, double minPercent, double maxPercent, int minNumber, int maxNumber) |
52 { | 72 { |
53 log.DebugFormat("IsRatio? {0}. Limits: {1}->{2}, {3}%->{4}%", isRatioLimit, minNumber, maxNumber, minPercent, maxPercent); | 73 log.DebugFormat("IsRatio? {0}. Limits: {1}->{2}, {3}%->{4}%", isRatioLimit, minNumber, maxNumber, minPercent, maxPercent); |
54 ratioLimited = isRatioLimit; | |
55 numericAmount.SetRange(minNumber, maxNumber); | 74 numericAmount.SetRange(minNumber, maxNumber); |
56 percentageAmount.SetRange(minPercent, maxPercent); | 75 percentageAmount.SetRange(minPercent, maxPercent); |
57 | 76 SetEquipmentAmountType(isRatioLimit); |
58 if (isRatioLimit) | 77 isRatioLimited = isRatioLimit; |
59 { | 78 } |
60 if (minPercent == 100) | 79 |
80 public void SetEquipmentAmountType(bool isRatioAmount) | |
81 { | |
82 if (isRatioAmount) | |
83 { | |
84 if (percentageAmount.Value == 100) | |
61 { | 85 { |
62 rbEquipAll.Active = true; | 86 rbEquipAll.Active = true; |
63 } | 87 } |
64 else | 88 else |
65 { | 89 { |
96 { | 120 { |
97 log.Debug("Okay clicked"); | 121 log.Debug("Okay clicked"); |
98 Respond(ResponseType.Ok); | 122 Respond(ResponseType.Ok); |
99 } | 123 } |
100 | 124 |
101 public void SetOkayEnabledState (bool enabled) | 125 public void SetOkayEnabledState(bool enabled) |
102 { | 126 { |
103 buttonOk.Sensitive = enabled; | 127 buttonOk.Sensitive = enabled; |
104 } | 128 } |
105 | 129 |
106 protected virtual void SpinButtonValueChanged (object sender, System.EventArgs e) | 130 protected virtual void SpinButtonValueChanged(object sender, System.EventArgs e) |
107 { | 131 { |
108 OnUnitEquipmentAmountChanged(); | 132 OnUnitEquipmentAmountChanged(); |
109 } | 133 } |
110 | 134 |
111 protected virtual void RadioButtonClicked(object sender, System.EventArgs e) | 135 protected virtual void RadioButtonClicked(object sender, System.EventArgs e) |
112 { | 136 { |
113 OnUnitEquipmentAmountTypeChanged(); | 137 OnUnitEquipmentAmountTypeChanged(); |
114 } | 138 } |
115 | 139 |
116 public void SetNumericAmountEnabledState (bool enabled) | 140 public void SetNumericAmountEnabledState(bool enabled) |
117 { | 141 { |
118 rbEquipNumeric.Sensitive = enabled; | 142 double minPercent = GetMinPercentage(); |
119 numericAmount.Sensitive = enabled; | 143 rbEquipNumeric.Sensitive = enabled && !(isRatioLimited && minPercent == 100); |
144 numericAmount.Sensitive = rbEquipNumeric.Sensitive; | |
120 } | 145 } |
121 | 146 |
122 public void SetPercentageAmountEnabledState(bool enabled) | 147 public void SetPercentageAmountEnabledState(bool enabled) |
123 { | 148 { |
124 if (enabled) | 149 if (enabled) |
125 { | 150 { |
126 double minPercentage = GetMinPercentage(); | 151 double minPercentage = GetMinPercentage(); |
127 rbEquipPercent.Sensitive = minPercentage != 100; | 152 rbEquipPercent.Sensitive = isRatioLimited && minPercentage != 100; |
128 percentageAmount.Sensitive = minPercentage != 100; | 153 percentageAmount.Sensitive = rbEquipPercent.Sensitive; |
129 double maxPercentage = GetMaxPercentage(); | 154 double maxPercentage = GetMaxPercentage(); |
130 rbEquipAll.Sensitive = ratioLimited && maxPercentage == 100; | 155 rbEquipAll.Sensitive = isRatioLimited && maxPercentage == 100; |
131 lblEquipAll.Sensitive = ratioLimited && maxPercentage == 100; | 156 lblEquipAll.Sensitive = rbEquipAll.Sensitive; |
132 } | 157 } |
133 else | 158 else |
134 { | 159 { |
135 rbEquipPercent.Sensitive = false; | 160 rbEquipPercent.Sensitive = false; |
136 percentageAmount.Sensitive = false; | 161 percentageAmount.Sensitive = false; |
159 { | 184 { |
160 return !rbEquipNumeric.Active; | 185 return !rbEquipNumeric.Active; |
161 } | 186 } |
162 } | 187 } |
163 | 188 |
164 | |
165 public int EquipmentNumericAmount | 189 public int EquipmentNumericAmount |
166 { | 190 { |
167 get | 191 get |
168 { | 192 { |
169 return (int)numericAmount.Value; | 193 return (int)numericAmount.Value; |
173 { | 197 { |
174 numericAmount.Value = value; | 198 numericAmount.Value = value; |
175 } | 199 } |
176 } | 200 } |
177 | 201 |
178 | |
179 public double EquipmentPercentageAmount | 202 public double EquipmentPercentageAmount |
180 { | 203 { |
181 get | 204 get |
182 { | 205 { |
183 double percent; | 206 double percent; |