Mercurial > repos > IBBoard.WarFoundry.GUI.WinForms
annotate UI/EquipmentAmountControl.cs @ 116:1e92802391e3
* Mark v0.1 beta 7 dev (pre) in main form
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 24 Dec 2009 20:31:22 +0000 |
parents | 727c1b0e49a6 |
children | e00332dc1618 |
rev | line source |
---|---|
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
1 using System; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
2 using System.Collections.Generic; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
3 using System.ComponentModel; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
4 using System.Drawing; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
5 using System.Data; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
6 using System.Text; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
7 using System.Windows.Forms; |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
8 using log4net; |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
9 using IBBoard.CustomMath; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
10 using IBBoard.Lang; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
11 using IBBoard.Limits; |
113
c1a3993297b1
Re #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
107
diff
changeset
|
12 using IBBoard.Windows.Forms.I18N; |
114
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
13 using IBBoard.Windows.Forms.Util; |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
14 using IBBoard.WarFoundry.API; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
15 using IBBoard.WarFoundry.API.Objects; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
16 using IBBoard.WarFoundry.API.Util; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
17 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
18 namespace IBBoard.WarFoundry.GUI.WinForms.UI |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
19 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
20 public partial class EquipmentAmountControl : UserControl |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
21 { |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
22 private ILog log = LogManager.GetLogger(typeof(EquipmentAmountControl)); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
23 private Unit unit; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
24 private UnitEquipmentItem equip; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
25 public event EventHandler ValueChanged; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
26 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
27 public EquipmentAmountControl() |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
28 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
29 InitializeComponent(); |
113
c1a3993297b1
Re #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
107
diff
changeset
|
30 ControlTranslator.TranslateControl(this); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
31 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
32 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
33 public void SetUnit(Unit equipUnit) |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
34 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
35 unit = equipUnit; |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
36 log.Debug("Set unit to: " + (unit == null ? "null" : unit.Name)); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
37 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
38 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
39 public void SetUnitEquipmentItem(UnitEquipmentItem unitEquipment) |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
40 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
41 equip = unitEquipment; |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
42 log.Debug("Set equipment to: " + (equip == null ? "null" : equip.Name)); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
43 SetWidgetValues(); |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
44 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
45 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
46 private void OnValueChanged() |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
47 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
48 if (ValueChanged != null) |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
49 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
50 ValueChanged(this, new EventArgs()); |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
51 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
52 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
53 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
54 private void SetWidgetValues() |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
55 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
56 if (equip != null) |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
57 { |
98
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
58 IgnoreWidgets(); |
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
59 |
107
775a34b78051
Fixes #225: Equipment amount control occasionally disables all options
IBBoard <dev@ibboard.co.uk>
parents:
105
diff
changeset
|
60 Enabled = true; |
775a34b78051
Fixes #225: Equipment amount control occasionally disables all options
IBBoard <dev@ibboard.co.uk>
parents:
105
diff
changeset
|
61 |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
62 log.Debug("Equipment update"); |
89
971f7801f984
Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents:
88
diff
changeset
|
63 bool equipIsRatioLimit = UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip); |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
64 log.Debug("Equipment is ratio? " + (equipIsRatioLimit ? "yes" : "no")); |
89
971f7801f984
Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents:
88
diff
changeset
|
65 double maxPercent = RoundPercentage(UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); |
98
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
66 maxPercent = Math.Max(0, maxPercent); |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
67 log.Debug("Equipment max percentage: " + maxPercent); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
68 double minPercent = RoundPercentage(UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
98
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
69 minPercent = Math.Max(0, minPercent); |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
70 log.Debug("Equipment min percentage: " + minPercent); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
71 int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip); |
98
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
72 maxNumber = Math.Max(0, maxNumber); |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
73 log.Debug("Equipment max count: " + maxNumber); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
74 int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip); |
98
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
75 minNumber = Math.Max(0, minNumber); |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
76 log.Debug("Equipment min count: " + minNumber); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
77 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
78 SetUpDownControlMinMaxes(minPercent, maxPercent, minNumber, maxNumber); |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
79 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
80 if (equipIsRatioLimit) |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
81 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
82 SetEquipmentAmountsFromPercentage(minPercent); |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
83 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
84 else |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
85 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
86 SetEquipmentAmountsFromNumber(minNumber); |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
87 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
88 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
89 rbEquipAll.Enabled = equipIsRatioLimit && maxPercent == 100; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
90 rbEquipAll.Checked = equipIsRatioLimit && minPercent == 100; |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
91 log.Debug("rbEquipAll: " + (rbEquipAll.Enabled ? "enabled":"disabled") + " " + (rbEquipAll.Checked ? "checked" : "unchecked")); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
92 percentage.Enabled = equipIsRatioLimit && minPercent != 100; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
93 rbPercentage.Enabled = percentage.Enabled; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
94 rbPercentage.Checked = equipIsRatioLimit && !rbEquipAll.Checked; |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
95 log.Debug("rbPercentage: " + (rbPercentage.Enabled ? "enabled" : "disabled") + " " + (rbPercentage.Checked ? "checked" : "unchecked")); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
96 numeric.Enabled = !equipIsRatioLimit || minPercent != 100; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
97 rbNumeric.Enabled = numeric.Enabled; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
98 rbNumeric.Checked = !equipIsRatioLimit; |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
99 log.Debug("rbNumeric: " + (rbNumeric.Enabled ? "enabled" : "disabled") + " " + (rbNumeric.Checked ? "checked" : "unchecked")); |
91 | 100 SetUnitEquipmentItemAmount(); |
98
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
101 |
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
102 ListenToWidgets(); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
103 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
104 else |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
105 { |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
106 log.Debug("Null equipment - no widget update"); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
107 Enabled = false; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
108 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
109 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
110 |
98
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
111 private void IgnoreWidgets() |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
112 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
113 percentage.ValueChanged -= percentage_ValueChanged; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
114 numeric.ValueChanged -= numeric_ValueChanged; |
98
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
115 rbEquipAll.CheckedChanged -= rbEquipAll_CheckedChanged; |
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
116 rbNumeric.CheckedChanged -= radioCheckedChanged; |
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
117 rbPercentage.CheckedChanged -= radioCheckedChanged; |
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
118 } |
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
119 |
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
120 private void ListenToWidgets() |
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
121 { |
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
122 percentage.ValueChanged += percentage_ValueChanged; |
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
123 numeric.ValueChanged += numeric_ValueChanged; |
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
124 rbEquipAll.CheckedChanged += rbEquipAll_CheckedChanged; |
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
125 rbNumeric.CheckedChanged += radioCheckedChanged; |
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
126 rbPercentage.CheckedChanged += radioCheckedChanged; |
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
127 } |
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
128 |
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
129 private void SetUpDownControlMinMaxes(double minPercent, double maxPercent, int minNumber, int maxNumber) |
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
130 { |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
131 SetUpDownControlMinMax(percentage, minPercent, maxPercent); |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
132 SetUpDownControlMinMax(numeric, (decimal) minNumber, (decimal) maxNumber); |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
133 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
134 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
135 private void SetUpDownControlMinMax(NumericUpDown upDownControl, double min, double max) |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
136 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
137 SetUpDownControlMinMax(upDownControl, (decimal)min, (decimal)max); |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
138 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
139 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
140 private void SetUpDownControlMinMax(NumericUpDown upDownControl, decimal min, decimal max) |
88
340e711ca4c3
Re #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
141 { |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
142 log.Debug("Set "+upDownControl.Name+" min and max to: "+min+", "+max); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
143 upDownControl.Minimum = min; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
144 upDownControl.Maximum = max; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
145 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
146 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
147 private void rbEquipAll_CheckedChanged(object sender, EventArgs e) |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
148 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
149 bool equipAll = rbEquipAll.Checked; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
150 numeric.Enabled = !equipAll; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
151 percentage.Enabled = !equipAll; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
152 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
153 if (equipAll) |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
154 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
155 numeric.Value = unit.Size; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
156 percentage.Value = 100; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
157 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
158 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
159 radioCheckedChanged(sender, e); |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
160 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
161 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
162 private void percentage_ValueChanged(object sender, EventArgs e) |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
163 { |
113
c1a3993297b1
Re #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
107
diff
changeset
|
164 PerformPercentageValueChanged(); |
c1a3993297b1
Re #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
107
diff
changeset
|
165 } |
c1a3993297b1
Re #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
107
diff
changeset
|
166 |
c1a3993297b1
Re #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
107
diff
changeset
|
167 private void PerformPercentageValueChanged() |
c1a3993297b1
Re #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
107
diff
changeset
|
168 { |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
169 log.Debug("Percentage value changed"); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
170 SetNumericValueFromPercentage(); |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
171 rbEquipAll.Checked = (percentage.Value == 100 && !rbNumeric.Checked); |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
172 OnValueChanged(); |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
173 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
174 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
175 private void SetNumericValueFromPercentage() |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
176 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
177 numeric.ValueChanged -= numeric_ValueChanged; |
88
340e711ca4c3
Re #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
178 numeric.Value = CalculateNumericValueFromPercentage(percentage.Value); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
179 numeric.ValueChanged += numeric_ValueChanged; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
180 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
181 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
182 private decimal CalculateNumericValueFromPercentage(decimal percent) |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
183 { |
96
057498981bde
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
93
diff
changeset
|
184 decimal calcedAmount = (decimal) IBBoard.CustomMath.IBBMath.Round((double)(unit.Size * (percent / 100)), equip.RoundNumberUp); |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
185 log.Debug("Numeric value calculated from percentage: "+percent+"% -> "+calcedAmount); |
96
057498981bde
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
93
diff
changeset
|
186 return Math.Min(Math.Max(calcedAmount, numeric.Minimum), numeric.Maximum); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
187 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
188 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
189 private void numeric_ValueChanged(object sender, EventArgs e) |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
190 { |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
191 log.Debug("Numeric value changed"); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
192 SetPercentageValueFromNumeric(); |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
193 OnValueChanged(); |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
194 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
195 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
196 private void SetPercentageValueFromNumeric() |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
197 { |
88
340e711ca4c3
Re #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
198 int number = (int)numeric.Value; |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
199 percentage.ValueChanged -= percentage_ValueChanged; |
88
340e711ca4c3
Re #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
200 percentage.Value = CalcualtePercentageValueFromNumber(number); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
201 percentage.ValueChanged += percentage_ValueChanged; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
202 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
203 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
204 private decimal CalcualtePercentageValueFromNumber(int number) |
89
971f7801f984
Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents:
88
diff
changeset
|
205 { |
96
057498981bde
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
93
diff
changeset
|
206 decimal calcedAmount = (decimal) RoundPercentage(IBBoard.CustomMath.IBBMath.Percentage(number, unit.Size)); |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
207 log.Debug("Numeric value calculated from percentage: " + number + " -> " + calcedAmount+"%"); |
96
057498981bde
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
93
diff
changeset
|
208 return Math.Min(Math.Max(calcedAmount, percentage.Minimum), percentage.Maximum); |
89
971f7801f984
Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents:
88
diff
changeset
|
209 } |
971f7801f984
Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents:
88
diff
changeset
|
210 |
971f7801f984
Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents:
88
diff
changeset
|
211 private double RoundPercentage(double percent) |
971f7801f984
Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents:
88
diff
changeset
|
212 { |
971f7801f984
Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents:
88
diff
changeset
|
213 return Math.Round(percent, 1); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
214 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
215 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
216 public double EquipmentAmount |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
217 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
218 get |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
219 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
220 double val = 0; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
221 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
222 if (rbNumeric.Checked) |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
223 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
224 val = (double) numeric.Value; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
225 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
226 else if (rbPercentage.Checked) |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
227 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
228 val = (double) percentage.Value; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
229 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
230 else if (rbEquipAll.Checked) |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
231 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
232 val = 100; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
233 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
234 else |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
235 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
236 val = 0; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
237 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
238 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
239 return val; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
240 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
241 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
242 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
243 public bool IsRatioEquipmentAmount |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
244 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
245 get |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
246 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
247 return !rbNumeric.Checked; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
248 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
249 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
250 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
251 private void SetUnitEquipmentItemAmount() |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
252 { |
101
3e78af88ceb3
Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
253 double equipAmountNum = UnitEquipmentUtil.GetEquipmentAmount(unit, equip); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
254 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
255 if (equipAmountNum > 0) |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
256 { |
101
3e78af88ceb3
Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents:
98
diff
changeset
|
257 bool isRatio = UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, equip); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
258 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
259 if (isRatio) |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
260 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
261 SetEquipmentAmountsFromPercentage(equipAmountNum); |
93 | 262 |
263 if (equipAmountNum == 100) | |
264 { | |
265 rbEquipAll.Checked = true; | |
266 } | |
267 else | |
268 { | |
269 rbPercentage.Checked = true; | |
270 } | |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
271 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
272 else |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
273 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
274 int equipAmount = (int) equipAmountNum; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
275 SetEquipmentAmountsFromNumber(equipAmount); |
93 | 276 rbNumeric.Checked = true; |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
277 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
278 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
279 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
280 |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
281 private void SetEquipmentAmountsFromPercentage(double equipAmount) |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
282 { |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
283 log.Debug("Set equipment amount from percentage: " + equipAmount); |
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
284 decimal decEquipAmount = (decimal) equipAmount; |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
285 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
286 if (decEquipAmount > percentage.Maximum) |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
287 { |
105 | 288 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, percentage.Maximum); |
289 string percentageTooLargeTitle = Translation.GetTranslation("equipPercentageTooLargeTitle", "equipment percentage too large"); | |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
290 MessageBox.Show(ParentForm, percentageTooLarge, percentageTooLargeTitle); |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
291 decEquipAmount = percentage.Maximum; |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
292 log.Debug("Limited equipment amount to " + decEquipAmount); |
98
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
293 OnValueChanged(); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
294 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
295 else if (decEquipAmount < percentage.Minimum) |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
296 { |
105 | 297 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, percentage.Minimum); |
298 string percentageTooSmallTitle = Translation.GetTranslation("equipPercentageTooSmallTitle", "equipment percentage too small"); | |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
299 MessageBox.Show(ParentForm, percentageTooSmall, percentageTooSmallTitle); |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
300 decEquipAmount = percentage.Minimum; |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
301 log.Debug("Limited equipment amount to " + decEquipAmount); |
98
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
302 OnValueChanged(); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
303 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
304 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
305 numeric.Value = CalculateNumericValueFromPercentage(decEquipAmount); |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
306 percentage.Value = decEquipAmount; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
307 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
308 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
309 private void SetEquipmentAmountsFromNumber(int equipAmount) |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
310 { |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
311 log.Debug("Set equipment percentage from amount: " + equipAmount); |
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
312 |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
313 if (equipAmount > numeric.Maximum) |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
314 { |
105 | 315 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, numeric.Maximum); |
316 string amountTooLargeTitle = Translation.GetTranslation("equipNumberTooLargeTitle", "equipment amount too large"); | |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
317 MessageBox.Show(ParentForm, amountTooLarge, amountTooLargeTitle); |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
318 equipAmount = (int)numeric.Maximum; |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
319 log.Debug("Limited equipment amount to " + equipAmount); |
98
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
320 OnValueChanged(); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
321 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
322 else if (equipAmount < numeric.Minimum) |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
323 { |
105 | 324 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, numeric.Minimum); |
325 string amountTooSmallTitle = Translation.GetTranslation("equipNumberTooSmallTitle", "equipment amount too small"); | |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
326 MessageBox.Show(ParentForm, amountTooSmall, amountTooSmallTitle); |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
327 equipAmount = (int) numeric.Minimum; |
97
e356134d73c4
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
96
diff
changeset
|
328 log.Debug("Limited equipment amount to " + equipAmount); |
98
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
97
diff
changeset
|
329 OnValueChanged(); |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
330 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
331 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
332 percentage.Value = CalcualtePercentageValueFromNumber(equipAmount); |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
333 numeric.Value = equipAmount; |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
334 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
335 |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
336 private void radioCheckedChanged(object sender, EventArgs e) |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
337 { |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
338 OnValueChanged(); |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
339 } |
114
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
340 |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
341 protected override bool ProcessDialogKey(Keys keyData) |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
342 { |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
343 bool processed = false; |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
344 |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
345 if (keyData == Keys.Enter) |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
346 { |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
347 if (numeric.Focused) |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
348 { |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
349 processed = ForceUpDownControlUpdate(numeric); |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
350 } |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
351 else if (percentage.Focused) |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
352 { |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
353 processed = ForceUpDownControlUpdate(percentage); |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
354 } |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
355 } |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
356 |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
357 if (!processed) |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
358 { |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
359 processed = base.ProcessDialogKey(keyData); |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
360 } |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
361 |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
362 return processed; |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
363 } |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
364 |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
365 private bool ForceUpDownControlUpdate(NumericUpDown control) |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
366 { |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
367 ControlValueChangedChecker checker = new ControlValueChangedChecker(); |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
368 control.ValueChanged += checker.ValueChanged; |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
369 decimal val = control.Value; |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
370 control.ValueChanged -= checker.ValueChanged; |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
371 return checker.valueChanged; |
727c1b0e49a6
Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents:
113
diff
changeset
|
372 } |
90
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
373 } |
63ca28bd8ada
Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
374 } |