Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
comparison FrmEditEquipment.cs @ 64:e3fe48c4d794
Re #60: Add UI to add/remove/edit weapons in GTK
* Add most of basic "edit" interface, based on "add" interface
TODO:
* Set initial values
* Warn when setting to 0
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 02 Sep 2010 20:12:21 +0000 |
parents | |
children | 4b82515586ac |
comparison
equal
deleted
inserted
replaced
63:c2d79b4209e3 | 64:e3fe48c4d794 |
---|---|
1 // This file (FrmEditEquipment.cs) is a part of the IBBoard.WarFoundry.GUI.GTK project and is copyright 2010 IBBoard | |
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. | |
4 using System; | |
5 using IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces; | |
6 using IBBoard.WarFoundry.API.Objects; | |
7 using Gtk; | |
8 using IBBoard.WarFoundry.GUI.GTK.Util; | |
9 using IBBoard.GtkSharp; | |
10 using log4net.Repository.Hierarchy; | |
11 using log4net; | |
12 namespace IBBoard.WarFoundry.GUI.GTK | |
13 { | |
14 public partial class FrmEditEquipment : Dialog, IEditEquipmentUI | |
15 { | |
16 private static ILog log = LogManager.GetLogger(typeof(FrmAddEquipment)); | |
17 | |
18 public event SingleArgMethodInvoker<UnitEquipmentItem> UnitEquipmentItemChoiceChanged; | |
19 public event MethodInvoker UnitEquipmentAmountTypeChanged; | |
20 public event MethodInvoker UnitEquipmentAmountChanged; | |
21 | |
22 private bool limitsEnabled = false; | |
23 private bool ratioLimited = false; | |
24 | |
25 public FrmEditEquipment() | |
26 { | |
27 this.Build(); | |
28 TreeViewColumn equipColumn = new TreeViewColumn(); | |
29 equipColumn.Title = "Equipment"; | |
30 CellRendererText equipCell = new CellRendererText(); | |
31 equipColumn.PackStart(equipCell, true); | |
32 equipColumn.SetCellDataFunc(equipCell, GtkWarFoundryUtil.RenderWarFoundryObjectName); | |
33 } | |
34 | |
35 private void OnUnitEquipmentAmountChanged() | |
36 { | |
37 if (UnitEquipmentAmountChanged != null) | |
38 { | |
39 UnitEquipmentAmountChanged(); | |
40 } | |
41 } | |
42 | |
43 private void OnUnitEquipmentAmountTypeChanged() | |
44 { | |
45 if (UnitEquipmentAmountChanged != null) | |
46 { | |
47 UnitEquipmentAmountTypeChanged(); | |
48 } | |
49 } | |
50 | |
51 public void SetUnitEquipmentLimits(bool isRatioLimit, double minPercent, double maxPercent, int minNumber, int maxNumber) | |
52 { | |
53 log.DebugFormat("IsRatio? {0}. Limits: {1}->{2}, {3}%->{4}%", isRatioLimit, minNumber, maxNumber, minPercent, maxPercent); | |
54 ratioLimited = isRatioLimit; | |
55 numericAmount.SetRange(minNumber, maxNumber); | |
56 percentageAmount.SetRange(minPercent, maxPercent); | |
57 | |
58 if (isRatioLimit) | |
59 { | |
60 if (minPercent == 100) | |
61 { | |
62 rbEquipAll.Active = true; | |
63 } | |
64 else | |
65 { | |
66 rbEquipPercent.Active = true; | |
67 } | |
68 } | |
69 else | |
70 { | |
71 rbEquipNumeric.Active = true; | |
72 } | |
73 } | |
74 | |
75 public void SetUnitEquipmentLimitsEnabled(bool isEnabled) | |
76 { | |
77 SetNumericAmountEnabledState(isEnabled); | |
78 SetPercentageAmountEnabledState(isEnabled); | |
79 } | |
80 | |
81 public bool ShowControl() | |
82 { | |
83 int result = Run(); | |
84 bool okayClicked = (result == (int)ResponseType.Ok); | |
85 this.Hide(); | |
86 return okayClicked; | |
87 } | |
88 | |
89 protected virtual void CancelButtonClicked(object sender, System.EventArgs e) | |
90 { | |
91 log.Debug("Cancel clicked"); | |
92 Respond(ResponseType.Cancel); | |
93 } | |
94 | |
95 protected virtual void OkayButtonClicked(object sender, System.EventArgs e) | |
96 { | |
97 log.Debug("Okay clicked"); | |
98 Respond(ResponseType.Ok); | |
99 } | |
100 | |
101 public void SetOkayEnabledState (bool enabled) | |
102 { | |
103 buttonOk.Sensitive = enabled; | |
104 } | |
105 | |
106 protected virtual void SpinButtonValueChanged (object sender, System.EventArgs e) | |
107 { | |
108 OnUnitEquipmentAmountChanged(); | |
109 } | |
110 | |
111 protected virtual void RadioButtonClicked(object sender, System.EventArgs e) | |
112 { | |
113 OnUnitEquipmentAmountTypeChanged(); | |
114 } | |
115 | |
116 public void SetNumericAmountEnabledState (bool enabled) | |
117 { | |
118 rbEquipNumeric.Sensitive = enabled; | |
119 numericAmount.Sensitive = enabled; | |
120 } | |
121 | |
122 public void SetPercentageAmountEnabledState(bool enabled) | |
123 { | |
124 if (enabled) | |
125 { | |
126 double minPercentage = GetMinPercentage(); | |
127 rbEquipPercent.Sensitive = minPercentage != 100; | |
128 percentageAmount.Sensitive = minPercentage != 100; | |
129 double maxPercentage = GetMaxPercentage(); | |
130 rbEquipAll.Sensitive = ratioLimited && maxPercentage == 100; | |
131 lblEquipAll.Sensitive = ratioLimited && maxPercentage == 100; | |
132 } | |
133 else | |
134 { | |
135 rbEquipPercent.Sensitive = false; | |
136 percentageAmount.Sensitive = false; | |
137 rbEquipAll.Sensitive = false; | |
138 lblEquipAll.Sensitive = false; | |
139 } | |
140 } | |
141 | |
142 private double GetMaxPercentage() | |
143 { | |
144 double min, max; | |
145 percentageAmount.GetRange(out min, out max); | |
146 return max; | |
147 } | |
148 | |
149 private double GetMinPercentage() | |
150 { | |
151 double min, max; | |
152 percentageAmount.GetRange(out min, out max); | |
153 return min; | |
154 } | |
155 | |
156 public bool IsRatioEquipmentAmount | |
157 { | |
158 get | |
159 { | |
160 return !rbEquipNumeric.Active; | |
161 } | |
162 } | |
163 | |
164 | |
165 public int EquipmentNumericAmount | |
166 { | |
167 get | |
168 { | |
169 return (int)numericAmount.Value; | |
170 } | |
171 | |
172 set | |
173 { | |
174 numericAmount.Value = value; | |
175 } | |
176 } | |
177 | |
178 | |
179 public double EquipmentPercentageAmount | |
180 { | |
181 get | |
182 { | |
183 double percent; | |
184 | |
185 if (rbEquipAll.Active) | |
186 { | |
187 percent = 100; | |
188 } | |
189 else | |
190 { | |
191 percent = percentageAmount.Value; | |
192 } | |
193 | |
194 return percent; | |
195 } | |
196 | |
197 set | |
198 { | |
199 percentageAmount.Value = value; | |
200 } | |
201 } | |
202 } | |
203 } | |
204 |