Mercurial > repos > IBBoard.WarFoundry.GUI.GTK
comparison UIControl/AbstractBaseEquipmentUIControl.cs @ 98:fac0636ae13b
Re #308: Make GTK# UI translatable
* Make undo/redo menus translate on language change
* Organise English language file
* Resolve warnings by adding in dialogs that use translated strings when equipment amounts are out of range
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 02 Jan 2011 21:03:15 +0000 |
parents | 4b82515586ac |
children |
comparison
equal
deleted
inserted
replaced
97:6d2c8ad0d8f1 | 98:fac0636ae13b |
---|---|
19 protected UnitEquipmentItem equipItem; | 19 protected UnitEquipmentItem equipItem; |
20 protected double minPercentage, maxPercentage; | 20 protected double minPercentage, maxPercentage; |
21 protected int minNumber, maxNumber; | 21 protected int minNumber, maxNumber; |
22 protected bool isRatioAmount; | 22 protected bool isRatioAmount; |
23 protected double equipmentAmount; | 23 protected double equipmentAmount; |
24 | 24 |
25 public AbstractBaseEquipmentUIControl(Unit unit, CommandStack commandStack) | 25 public AbstractBaseEquipmentUIControl(Unit unit, CommandStack commandStack) |
26 { | 26 { |
27 this.unit = unit; | 27 this.unit = unit; |
28 this.commandStack = commandStack; | 28 this.commandStack = commandStack; |
29 } | 29 } |
54 | 54 |
55 protected virtual void CompleteUISetup() | 55 protected virtual void CompleteUISetup() |
56 { | 56 { |
57 //Do nothing | 57 //Do nothing |
58 } | 58 } |
59 | 59 |
60 protected void HandleUnitEquipmentAmountChanged() | 60 protected void HandleUnitEquipmentAmountChanged() |
61 { | 61 { |
62 SetUnitEquipmentValuesFromUI(); | 62 SetUnitEquipmentValuesFromUI(); |
63 } | 63 } |
64 | 64 |
65 protected void SetUnitEquipmentLimits(UnitEquipmentItem equip) | 65 protected void SetUnitEquipmentLimits(UnitEquipmentItem equip) |
66 { | 66 { |
67 ui.IgnoreWidgets(); | 67 ui.IgnoreWidgets(); |
68 | 68 |
69 if (equip != null) | 69 if (equip != null) |
88 ui.SetOkayEnabledState(false); | 88 ui.SetOkayEnabledState(false); |
89 } | 89 } |
90 | 90 |
91 ui.ListenToWidgets(); | 91 ui.ListenToWidgets(); |
92 } | 92 } |
93 | 93 |
94 protected void SetUnitEquipmentValuesFromEquipment(UnitEquipmentItem equip) | 94 protected void SetUnitEquipmentValuesFromEquipment(UnitEquipmentItem equip) |
95 { | 95 { |
96 isRatioAmount = UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, equip); | 96 isRatioAmount = UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, equip); |
97 equipmentAmount = UnitEquipmentUtil.GetEquipmentAmount(unit, equip); | 97 equipmentAmount = UnitEquipmentUtil.GetEquipmentAmount(unit, equip); |
98 SetUnitEquipmentValues(); | 98 SetUnitEquipmentValues(); |
117 equipmentAmount = equipmentIntAmount; | 117 equipmentAmount = equipmentIntAmount; |
118 } | 118 } |
119 | 119 |
120 SetUnitEquipmentValues(); | 120 SetUnitEquipmentValues(); |
121 } | 121 } |
122 | 122 |
123 private void SetUnitEquipmentValues() | 123 private void SetUnitEquipmentValues() |
124 { | 124 { |
125 ui.IgnoreWidgets(); | 125 ui.IgnoreWidgets(); |
126 | 126 |
127 if (isRatioAmount) | 127 if (isRatioAmount) |
142 { | 142 { |
143 if (equipAmount > maxPercentage) | 143 if (equipAmount > maxPercentage) |
144 { | 144 { |
145 string percentageTooLarge = Translation.GetTranslation("equipPercentageTooLarge", "the current percentage ({0}%) was larger than the maximum for the equipment item ({1}%) - the maximum value will be used instead", equipAmount, maxPercentage); | 145 string percentageTooLarge = Translation.GetTranslation("equipPercentageTooLarge", "the current percentage ({0}%) was larger than the maximum for the equipment item ({1}%) - the maximum value will be used instead", equipAmount, maxPercentage); |
146 string percentageTooLargeTitle = Translation.GetTranslation("equipPercentageTooLargeTitle", "equipment percentage too large"); | 146 string percentageTooLargeTitle = Translation.GetTranslation("equipPercentageTooLargeTitle", "equipment percentage too large"); |
147 // MessageBox.Show(ParentForm, percentageTooLarge, percentageTooLargeTitle); | 147 ShowMessage(percentageTooLarge, percentageTooLargeTitle); |
148 equipAmount = maxPercentage; | 148 equipAmount = maxPercentage; |
149 } | 149 } |
150 else | 150 else |
151 { | 151 { |
152 if (equipAmount < minPercentage) | 152 if (equipAmount < minPercentage) |
153 { | 153 { |
154 string percentageTooSmall = Translation.GetTranslation("equipPercentageTooSmall", "the current percentage ({0}%) was smaller than the minimum for the equipment item ({1}%) - the minimum value will be used instead", equipAmount, minPercentage); | 154 string percentageTooSmall = Translation.GetTranslation("equipPercentageTooSmall", "the current percentage ({0}%) was smaller than the minimum for the equipment item ({1}%) - the minimum value will be used instead", equipAmount, minPercentage); |
155 string percentageTooSmallTitle = Translation.GetTranslation("equipPercentageTooSmallTitle", "equipment percentage too small"); | 155 string percentageTooSmallTitle = Translation.GetTranslation("equipPercentageTooSmallTitle", "equipment percentage too small"); |
156 // MessageBox.Show(ParentForm, percentageTooSmall, percentageTooSmallTitle); | 156 ShowMessage(percentageTooSmall, percentageTooSmallTitle); |
157 equipAmount = minPercentage; | 157 equipAmount = minPercentage; |
158 } | 158 } |
159 | 159 |
160 } | 160 } |
161 ui.EquipmentNumericAmount = CalculateNumericValueFromPercentage(equipAmount); | 161 ui.EquipmentNumericAmount = CalculateNumericValueFromPercentage(equipAmount); |
166 { | 166 { |
167 int calcedAmount = (int)CustomMath.IBBMath.Round((unit.Size * (percent / 100.0)), equipItem.RoundNumberUp); | 167 int calcedAmount = (int)CustomMath.IBBMath.Round((unit.Size * (percent / 100.0)), equipItem.RoundNumberUp); |
168 return Math.Min(Math.Max(calcedAmount, minNumber), maxNumber); | 168 return Math.Min(Math.Max(calcedAmount, minNumber), maxNumber); |
169 } | 169 } |
170 | 170 |
171 private void ShowMessage(string message, string title) | |
172 { | |
173 Gtk.MessageDialog dialog = new Gtk.MessageDialog(null, Gtk.DialogFlags.Modal, Gtk.MessageType.Warning, Gtk.ButtonsType.Ok, false, message); | |
174 dialog.Title = title; | |
175 dialog.Run(); | |
176 dialog.Hide(); | |
177 dialog.Dispose(); | |
178 } | |
179 | |
171 private void SetEquipmentAmountsFromNumber(int equipAmount) | 180 private void SetEquipmentAmountsFromNumber(int equipAmount) |
172 { | 181 { |
173 if (equipAmount > maxNumber) | 182 if (equipAmount > maxNumber) |
174 { | 183 { |
175 string amountTooLarge = Translation.GetTranslation("equipNumberTooLarge", "the current amount ({0}) was larger than the maximum for the equipment item ({1}) - the maximum value will be used instead", equipAmount, maxNumber); | 184 string amountTooLarge = Translation.GetTranslation("equipNumberTooLarge", "the current amount ({0}) was larger than the maximum for the equipment item ({1}) - the maximum value will be used instead", equipAmount, maxNumber); |
176 string amountTooLargeTitle = Translation.GetTranslation("equipNumberTooLargeTitle", "equipment amount too large"); | 185 string amountTooLargeTitle = Translation.GetTranslation("equipNumberTooLargeTitle", "equipment amount too large"); |
177 //MessageBox.Show(ParentForm, amountTooLarge, amountTooLargeTitle); | 186 ShowMessage(amountTooLarge, amountTooLargeTitle); |
178 equipAmount = maxNumber; | 187 equipAmount = maxNumber; |
179 } | 188 } |
180 else | 189 else |
181 { | 190 { |
182 if (equipAmount < minNumber) | 191 if (equipAmount < minNumber) |
183 { | 192 { |
184 string amountTooSmall = Translation.GetTranslation("equipNumberTooSmall", "the current amount ({0}) was smaller than the minimum for the equipment item ({1}) - the minimum value will be used instead", equipAmount, minNumber); | 193 string amountTooSmall = Translation.GetTranslation("equipNumberTooSmall", "the current amount ({0}) was smaller than the minimum for the equipment item ({1}) - the minimum value will be used instead", equipAmount, minNumber); |
185 string amountTooSmallTitle = Translation.GetTranslation("equipNumberTooSmallTitle", "equipment amount too small"); | 194 string amountTooSmallTitle = Translation.GetTranslation("equipNumberTooSmallTitle", "equipment amount too small"); |
186 //MessageBox.Show(ParentForm, amountTooSmall, amountTooSmallTitle); | 195 ShowMessage(amountTooSmall, amountTooSmallTitle); |
187 equipAmount = minNumber; | 196 equipAmount = minNumber; |
188 } | 197 } |
189 | 198 |
190 } | 199 } |
191 ui.EquipmentPercentageAmount = CalcualtePercentageValueFromNumber(equipAmount); | 200 ui.EquipmentPercentageAmount = CalcualtePercentageValueFromNumber(equipAmount); |
219 protected int GetMaxNumericLimit(UnitEquipmentItem equip) | 228 protected int GetMaxNumericLimit(UnitEquipmentItem equip) |
220 { | 229 { |
221 int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip); | 230 int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip); |
222 return Math.Max(0, maxNumber); | 231 return Math.Max(0, maxNumber); |
223 } | 232 } |
224 | 233 |
225 protected int GetMinNumericLimit(UnitEquipmentItem equip) | 234 protected int GetMinNumericLimit(UnitEquipmentItem equip) |
226 { | 235 { |
227 int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip); | 236 int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip); |
228 return Math.Max(0, minNumber); | 237 return Math.Max(0, minNumber); |
229 } | 238 } |
246 | 255 |
247 private double RoundPercentage(double percent) | 256 private double RoundPercentage(double percent) |
248 { | 257 { |
249 return Math.Round(percent, 1); | 258 return Math.Round(percent, 1); |
250 } | 259 } |
251 | 260 |
252 public void Show() | 261 public void Show() |
253 { | 262 { |
254 SetupUI(); | 263 SetupUI(); |
255 bool okayed = ui.ShowControl(); | 264 bool okayed = ui.ShowControl(); |
256 | 265 |