Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
annotate UIControl/AbstractBaseEquipmentUIControl.cs @ 66:100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
* Rip apart UI controls and put all the common code in a base class
* Add additional interfaces for common UI behaviour between equipment widgets
Not tested, but should provide a base for Replace widget
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 04 Sep 2010 20:11:05 +0000 |
parents | |
children | 3b4a646b4054 |
rev | line source |
---|---|
66
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 // This file (AbstractBaseEquipmentUIControl.cs) is a part of the IBBoard.WarFoundry.GUI.GTK project and is copyright 2010 IBBoard |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 // |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
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. |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 using System; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 using IBBoard.Commands; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 using IBBoard.WarFoundry.API.Objects; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 using IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 using IBBoard.Lang; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 using IBBoard.WarFoundry.API.Util; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 namespace IBBoard.WarFoundry.GUI.GTK.UIControl |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 public abstract class AbstractBaseEquipmentUIControl<UI_TYPE> where UI_TYPE : IBaseEquipmentUI |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 protected CommandStack commandStack; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 protected Unit unit; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 protected UI_TYPE ui; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 protected UnitEquipmentItem equipItem; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 protected double minPercentage, maxPercentage; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 protected int minNumber, maxNumber; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 protected bool isRatioAmount; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 protected double equipmentAmount; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
22 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 public AbstractBaseEquipmentUIControl(Unit unit, CommandStack commandStack) |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 this.unit = unit; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 this.commandStack = commandStack; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 SetupUI(); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
30 private void SetupUI() |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
31 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
32 ui = CreateEquipmentUI(); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
33 ui.SetUnitEquipmentLimitsEnabled(false); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
34 ui.SetOkayEnabledState(false); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
35 ui.UnitEquipmentAmountChanged += SetUnitEquipmentValues; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
36 ui.UnitEquipmentAmountTypeChanged += SetUnitEquipmentValues; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
37 CompleteUISetup(); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
38 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
39 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
40 /// <summary> |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
41 /// Creates the UI component that will be displayed to the user and returns it |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
42 /// </summary> |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
43 /// <returns> |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
44 /// the UI component to display to the user |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
45 /// </returns> |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
46 protected abstract UI_TYPE CreateEquipmentUI(); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
47 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
48 /// <summary> |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
49 /// Completes any additional user interface setup. |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
50 /// </summary> |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
51 protected virtual void CompleteUISetup() |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
52 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
53 //Do nothing |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
54 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
55 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
56 protected void HandleUnitEquipmentAmountChanged() |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
57 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
58 SetUnitEquipmentValues(); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
59 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
60 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
61 /// <summary> |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
62 /// Sets the unit equipment values on the UI |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
63 /// </summary> |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
64 protected void SetUnitEquipmentValues() |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
65 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
66 ui.SetOkayEnabledState(HasNonZeroEquipmentAmount()); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
67 isRatioAmount = ui.IsRatioEquipmentAmount; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
68 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
69 if (isRatioAmount) |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
70 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
71 equipmentAmount = ui.EquipmentPercentageAmount; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
72 SetEquipmentAmountsFromPercentage(equipmentAmount); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
73 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
74 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
75 else |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
76 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
77 int equipmentIntAmount = ui.EquipmentNumericAmount; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
78 equipmentAmount = equipmentIntAmount; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
79 SetEquipmentAmountsFromNumber(equipmentIntAmount); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
80 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
81 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
82 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
83 private void SetEquipmentAmountsFromPercentage(double equipAmount) |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
84 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
85 if (equipAmount > maxPercentage) |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
86 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
87 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); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
88 string percentageTooLargeTitle = Translation.GetTranslation("equipPercentageTooLargeTitle", "equipment percentage too large"); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
89 // MessageBox.Show(ParentForm, percentageTooLarge, percentageTooLargeTitle); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
90 equipAmount = maxPercentage; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
91 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
92 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
93 else if (equipAmount < minPercentage) |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
94 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
95 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); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
96 string percentageTooSmallTitle = Translation.GetTranslation("equipPercentageTooSmallTitle", "equipment percentage too small"); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
97 // MessageBox.Show(ParentForm, percentageTooSmall, percentageTooSmallTitle); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
98 equipAmount = minPercentage; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
99 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
100 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
101 ui.EquipmentNumericAmount = CalculateNumericValueFromPercentage(equipAmount); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
102 ui.EquipmentPercentageAmount = equipAmount; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
103 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
104 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
105 private int CalculateNumericValueFromPercentage(double percent) |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
106 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
107 int calcedAmount = (int)CustomMath.IBBMath.Round((unit.Size * (percent / 100.0)), equipItem.RoundNumberUp); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
108 return Math.Min(Math.Max(calcedAmount, minNumber), maxNumber); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
109 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
110 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
111 private void SetEquipmentAmountsFromNumber(int equipAmount) |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
112 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
113 if (equipAmount > maxNumber) |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
114 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
115 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); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
116 string amountTooLargeTitle = Translation.GetTranslation("equipNumberTooLargeTitle", "equipment amount too large"); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
117 //MessageBox.Show(ParentForm, amountTooLarge, amountTooLargeTitle); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
118 equipAmount = maxNumber; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
119 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
120 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
121 else if (equipAmount < minNumber) |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
122 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
123 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); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
124 string amountTooSmallTitle = Translation.GetTranslation("equipNumberTooSmallTitle", "equipment amount too small"); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
125 //MessageBox.Show(ParentForm, amountTooSmall, amountTooSmallTitle); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
126 equipAmount = minNumber; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
127 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
128 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
129 ui.EquipmentPercentageAmount = CalcualtePercentageValueFromNumber(equipAmount); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
130 ui.EquipmentNumericAmount = equipAmount; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
131 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
132 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
133 private double CalcualtePercentageValueFromNumber(int number) |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
134 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
135 double calcedAmount = RoundPercentage(CustomMath.IBBMath.Percentage(number, unit.Size)); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
136 return Math.Min(Math.Max(calcedAmount, minPercentage), maxPercentage); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
137 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
138 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
139 protected void SetEquipmentAmountControlEnabledStates() |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
140 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
141 ui.SetNumericAmountEnabledState(!isRatioAmount); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
142 ui.SetPercentageAmountEnabledState(true); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
143 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
144 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
145 protected double GetMaxPercentageLimit(UnitEquipmentItem equip) |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
146 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
147 double maxPercent = RoundPercentage(UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
148 return Math.Max(0, maxPercent); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
149 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
150 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
151 protected double GetMinPercentageLimit(UnitEquipmentItem equip) |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
152 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
153 double minPercent = RoundPercentage(UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
154 return Math.Max(0, minPercent); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
155 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
156 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
157 protected int GetMaxNumericLimit(UnitEquipmentItem equip) |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
158 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
159 int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
160 return Math.Max(0, maxNumber); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
161 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
162 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
163 protected int GetMinNumericLimit(UnitEquipmentItem equip) |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
164 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
165 int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
166 return Math.Max(0, minNumber); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
167 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
168 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
169 protected bool HasNonZeroEquipmentAmount() |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
170 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
171 bool nonZero; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
172 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
173 if (isRatioAmount) |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
174 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
175 nonZero = (ui.EquipmentPercentageAmount > 0); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
176 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
177 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
178 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
179 else |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
180 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
181 nonZero = (ui.EquipmentNumericAmount > 0); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
182 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
183 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
184 return nonZero; |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
185 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
186 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
187 private double RoundPercentage(double percent) |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
188 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
189 return Math.Round(percent, 1); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
190 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
191 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
192 public void Show() |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
193 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
194 bool okayed = ui.ShowControl(); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
195 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
196 if (okayed) |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
197 { |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
198 DoProcessing(); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
199 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
200 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
201 ui.Dispose(); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
202 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
203 |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
204 /// <summary> |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
205 /// Does the processing required for the control when the "OK" button was clicked |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
206 /// </summary> |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
207 protected abstract void DoProcessing(); |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
208 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
209 } |
100626381159
Re #60: Add UI to add/remove/edit weapons in GTK
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
210 |