annotate UI/EquipmentAmountControl.cs @ 165:2c17714ad71b

Fixes #295: Index out of bounds when changing unit size and clicking in equipment list * Remove forced refresh of equipment on unit size change * Revert r620 and remove code for unlistening and relistening
author IBBoard <dev@ibboard.co.uk>
date Wed, 14 Jul 2010 20:02:20 +0000
parents e00332dc1618
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
132
e00332dc1618 Fixes #259: "Equip All" doesn't get translated
IBBoard <dev@ibboard.co.uk>
parents: 114
diff changeset
12 using IBBoard.Windows.Forms;
113
c1a3993297b1 Re #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents: 107
diff changeset
13 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
14 using IBBoard.Windows.Forms.Util;
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
15 using IBBoard.WarFoundry.API;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
16 using IBBoard.WarFoundry.API.Objects;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
17 using IBBoard.WarFoundry.API.Util;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
18
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
19 namespace IBBoard.WarFoundry.GUI.WinForms.UI
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
20 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
21 public partial class EquipmentAmountControl : UserControl
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
22 {
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
23 private ILog log = LogManager.GetLogger(typeof(EquipmentAmountControl));
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
24 private Unit unit;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
25 private UnitEquipmentItem equip;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
26 public event EventHandler ValueChanged;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
27
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
28 public EquipmentAmountControl()
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
29 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
30 InitializeComponent();
113
c1a3993297b1 Re #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents: 107
diff changeset
31 ControlTranslator.TranslateControl(this);
90
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
34 public void SetUnit(Unit equipUnit)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
35 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
36 unit = equipUnit;
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
37 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
38 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
39
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
40 public void SetUnitEquipmentItem(UnitEquipmentItem unitEquipment)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
41 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
42 equip = unitEquipment;
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
43 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
44 SetWidgetValues();
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
47 private void OnValueChanged()
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
48 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
49 if (ValueChanged != null)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
50 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
51 ValueChanged(this, new EventArgs());
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
55 private void SetWidgetValues()
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
56 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
57 if (equip != null)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
58 {
98
c7afc7824f50 Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
59 IgnoreWidgets();
c7afc7824f50 Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
60
107
775a34b78051 Fixes #225: Equipment amount control occasionally disables all options
IBBoard <dev@ibboard.co.uk>
parents: 105
diff changeset
61 Enabled = true;
775a34b78051 Fixes #225: Equipment amount control occasionally disables all options
IBBoard <dev@ibboard.co.uk>
parents: 105
diff changeset
62
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
63 log.Debug("Equipment update");
89
971f7801f984 Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 88
diff changeset
64 bool equipIsRatioLimit = UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip);
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
65 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
66 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
67 maxPercent = Math.Max(0, maxPercent);
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
68 log.Debug("Equipment max percentage: " + maxPercent);
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
69 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
70 minPercent = Math.Max(0, minPercent);
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
71 log.Debug("Equipment min percentage: " + minPercent);
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
72 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
73 maxNumber = Math.Max(0, maxNumber);
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
74 log.Debug("Equipment max count: " + maxNumber);
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
75 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
76 minNumber = Math.Max(0, minNumber);
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
77 log.Debug("Equipment min count: " + minNumber);
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
78
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
79 SetUpDownControlMinMaxes(minPercent, maxPercent, minNumber, maxNumber);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
80
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
81 if (equipIsRatioLimit)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
82 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
83 SetEquipmentAmountsFromPercentage(minPercent);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
84 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
85 else
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
86 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
87 SetEquipmentAmountsFromNumber(minNumber);
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
90 rbEquipAll.Enabled = equipIsRatioLimit && maxPercent == 100;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
91 rbEquipAll.Checked = equipIsRatioLimit && minPercent == 100;
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
92 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
93 percentage.Enabled = equipIsRatioLimit && minPercent != 100;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
94 rbPercentage.Enabled = percentage.Enabled;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
95 rbPercentage.Checked = equipIsRatioLimit && !rbEquipAll.Checked;
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
96 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
97 numeric.Enabled = !equipIsRatioLimit || minPercent != 100;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
98 rbNumeric.Enabled = numeric.Enabled;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
99 rbNumeric.Checked = !equipIsRatioLimit;
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
100 log.Debug("rbNumeric: " + (rbNumeric.Enabled ? "enabled" : "disabled") + " " + (rbNumeric.Checked ? "checked" : "unchecked"));
91
e1e3957db129 Fixes #206:
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
101 SetUnitEquipmentItemAmount();
98
c7afc7824f50 Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
102
c7afc7824f50 Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
103 ListenToWidgets();
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
104 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
105 else
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
106 {
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
107 log.Debug("Null equipment - no widget update");
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
108 Enabled = false;
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 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
111
98
c7afc7824f50 Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
112 private void IgnoreWidgets()
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
113 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
114 percentage.ValueChanged -= percentage_ValueChanged;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
115 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
116 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
117 rbNumeric.CheckedChanged -= radioCheckedChanged;
c7afc7824f50 Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
118 rbPercentage.CheckedChanged -= radioCheckedChanged;
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
c7afc7824f50 Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
121 private void ListenToWidgets()
c7afc7824f50 Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
122 {
c7afc7824f50 Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
123 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
124 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
125 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
126 rbNumeric.CheckedChanged += radioCheckedChanged;
c7afc7824f50 Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
127 rbPercentage.CheckedChanged += radioCheckedChanged;
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
c7afc7824f50 Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents: 97
diff changeset
130 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
131 {
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
132 SetUpDownControlMinMax(percentage, minPercent, maxPercent);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
133 SetUpDownControlMinMax(numeric, (decimal) minNumber, (decimal) maxNumber);
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
136 private void SetUpDownControlMinMax(NumericUpDown upDownControl, double min, double max)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
137 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
138 SetUpDownControlMinMax(upDownControl, (decimal)min, (decimal)max);
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
141 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
142 {
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
143 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
144 upDownControl.Minimum = min;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
145 upDownControl.Maximum = max;
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
148 private void rbEquipAll_CheckedChanged(object sender, EventArgs e)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
149 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
150 bool equipAll = rbEquipAll.Checked;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
151 numeric.Enabled = !equipAll;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
152 percentage.Enabled = !equipAll;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
153
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
154 if (equipAll)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
155 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
156 numeric.Value = unit.Size;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
157 percentage.Value = 100;
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
160 radioCheckedChanged(sender, e);
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
163 private void percentage_ValueChanged(object sender, EventArgs e)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
164 {
113
c1a3993297b1 Re #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents: 107
diff changeset
165 PerformPercentageValueChanged();
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
c1a3993297b1 Re #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents: 107
diff changeset
168 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
169 {
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
170 log.Debug("Percentage value changed");
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
171 SetNumericValueFromPercentage();
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
172 rbEquipAll.Checked = (percentage.Value == 100 && !rbNumeric.Checked);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
173 OnValueChanged();
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
176 private void SetNumericValueFromPercentage()
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
177 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
178 numeric.ValueChanged -= numeric_ValueChanged;
88
340e711ca4c3 Re #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
179 numeric.Value = CalculateNumericValueFromPercentage(percentage.Value);
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
180 numeric.ValueChanged += numeric_ValueChanged;
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
183 private decimal CalculateNumericValueFromPercentage(decimal percent)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
184 {
96
057498981bde Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 93
diff changeset
185 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
186 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
187 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
188 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
189
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
190 private void numeric_ValueChanged(object sender, EventArgs e)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
191 {
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
192 log.Debug("Numeric value changed");
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
193 SetPercentageValueFromNumeric();
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
194 OnValueChanged();
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
197 private void SetPercentageValueFromNumeric()
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
198 {
88
340e711ca4c3 Re #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
199 int number = (int)numeric.Value;
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
200 percentage.ValueChanged -= percentage_ValueChanged;
88
340e711ca4c3 Re #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
201 percentage.Value = CalcualtePercentageValueFromNumber(number);
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
202 percentage.ValueChanged += percentage_ValueChanged;
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
205 private decimal CalcualtePercentageValueFromNumber(int number)
89
971f7801f984 Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 88
diff changeset
206 {
96
057498981bde Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 93
diff changeset
207 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
208 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
209 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
210 }
971f7801f984 Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 88
diff changeset
211
971f7801f984 Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 88
diff changeset
212 private double RoundPercentage(double percent)
971f7801f984 Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 88
diff changeset
213 {
971f7801f984 Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 88
diff changeset
214 return Math.Round(percent, 1);
90
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
217 public double EquipmentAmount
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
218 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
219 get
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
220 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
221 double val = 0;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
222
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
223 if (rbNumeric.Checked)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
224 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
225 val = (double) numeric.Value;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
226 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
227 else if (rbPercentage.Checked)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
228 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
229 val = (double) percentage.Value;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
230 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
231 else if (rbEquipAll.Checked)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
232 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
233 val = 100;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
234 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
235 else
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
236 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
237 val = 0;
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
240 return val;
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
244 public bool IsRatioEquipmentAmount
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
245 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
246 get
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
247 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
248 return !rbNumeric.Checked;
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
252 private void SetUnitEquipmentItemAmount()
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
253 {
101
3e78af88ceb3 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
254 double equipAmountNum = UnitEquipmentUtil.GetEquipmentAmount(unit, equip);
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
255
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
256 if (equipAmountNum > 0)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
257 {
101
3e78af88ceb3 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 98
diff changeset
258 bool isRatio = UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, equip);
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
259
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
260 if (isRatio)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
261 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
262 SetEquipmentAmountsFromPercentage(equipAmountNum);
93
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
263
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
264 if (equipAmountNum == 100)
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
265 {
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
266 rbEquipAll.Checked = true;
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
267 }
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
268 else
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
269 {
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
270 rbPercentage.Checked = true;
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
271 }
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
272 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
273 else
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
274 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
275 int equipAmount = (int) equipAmountNum;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
276 SetEquipmentAmountsFromNumber(equipAmount);
93
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
277 rbNumeric.Checked = true;
90
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 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
281
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
282 private void SetEquipmentAmountsFromPercentage(double equipAmount)
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
283 {
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
284 log.Debug("Set equipment amount from percentage: " + equipAmount);
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
285 decimal decEquipAmount = (decimal) equipAmount;
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
286
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
287 if (decEquipAmount > percentage.Maximum)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
288 {
105
e598c0d2584d Re #203: Translate WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 101
diff changeset
289 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);
e598c0d2584d Re #203: Translate WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 101
diff changeset
290 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
291 MessageBox.Show(ParentForm, percentageTooLarge, percentageTooLargeTitle);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
292 decEquipAmount = percentage.Maximum;
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
293 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
294 OnValueChanged();
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
295 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
296 else if (decEquipAmount < percentage.Minimum)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
297 {
105
e598c0d2584d Re #203: Translate WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 101
diff changeset
298 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);
e598c0d2584d Re #203: Translate WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 101
diff changeset
299 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
300 MessageBox.Show(ParentForm, percentageTooSmall, percentageTooSmallTitle);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
301 decEquipAmount = percentage.Minimum;
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
302 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
303 OnValueChanged();
90
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
306 numeric.Value = CalculateNumericValueFromPercentage(decEquipAmount);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
307 percentage.Value = decEquipAmount;
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
310 private void SetEquipmentAmountsFromNumber(int equipAmount)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
311 {
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
312 log.Debug("Set equipment percentage from amount: " + equipAmount);
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
313
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
314 if (equipAmount > numeric.Maximum)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
315 {
105
e598c0d2584d Re #203: Translate WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 101
diff changeset
316 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);
e598c0d2584d Re #203: Translate WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 101
diff changeset
317 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
318 MessageBox.Show(ParentForm, amountTooLarge, amountTooLargeTitle);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
319 equipAmount = (int)numeric.Maximum;
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
320 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
321 OnValueChanged();
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
322 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
323 else if (equipAmount < numeric.Minimum)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
324 {
105
e598c0d2584d Re #203: Translate WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 101
diff changeset
325 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);
e598c0d2584d Re #203: Translate WarFoundry
IBBoard <dev@ibboard.co.uk>
parents: 101
diff changeset
326 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
327 MessageBox.Show(ParentForm, amountTooSmall, amountTooSmallTitle);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
328 equipAmount = (int) numeric.Minimum;
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
329 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
330 OnValueChanged();
90
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
333 percentage.Value = CalcualtePercentageValueFromNumber(equipAmount);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
334 numeric.Value = equipAmount;
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
337 private void radioCheckedChanged(object sender, EventArgs e)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
338 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
339 OnValueChanged();
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
340 }
114
727c1b0e49a6 Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents: 113
diff changeset
341
727c1b0e49a6 Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents: 113
diff changeset
342 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
343 {
727c1b0e49a6 Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents: 113
diff changeset
344 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
345
727c1b0e49a6 Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents: 113
diff changeset
346 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
347 {
727c1b0e49a6 Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents: 113
diff changeset
348 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
349 {
727c1b0e49a6 Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents: 113
diff changeset
350 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
351 }
727c1b0e49a6 Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents: 113
diff changeset
352 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
353 {
727c1b0e49a6 Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents: 113
diff changeset
354 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
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
727c1b0e49a6 Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents: 113
diff changeset
358 if (!processed)
727c1b0e49a6 Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents: 113
diff changeset
359 {
727c1b0e49a6 Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents: 113
diff changeset
360 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
361 }
727c1b0e49a6 Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents: 113
diff changeset
362
727c1b0e49a6 Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents: 113
diff changeset
363 return processed;
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
727c1b0e49a6 Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents: 113
diff changeset
366 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
367 {
727c1b0e49a6 Fixes #115: Typing number for equipment amount doesn't update Okay button
IBBoard <dev@ibboard.co.uk>
parents: 113
diff changeset
368 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
369 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
370 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
371 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
372 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
373 }
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
374 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
375 }