annotate UI/EquipmentAmountControl.cs @ 93:37126221efa6

Re #208 * Make sure that the appropriate radio button is set when editing existing equipment instead of defaulting to the equipment type's radio button selection no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Mon, 09 Nov 2009 12:31:42 +0000
parents e1e3957db129
children 057498981bde
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;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
8 using IBBoard.CustomMath;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
9 using IBBoard.Lang;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
10 using IBBoard.Limits;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
11 using IBBoard.WarFoundry.API;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
12 using IBBoard.WarFoundry.API.Objects;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
13 using IBBoard.WarFoundry.API.Util;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
14
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
15 namespace IBBoard.WarFoundry.GUI.WinForms.UI
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
16 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
17 public partial class EquipmentAmountControl : UserControl
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 private Unit unit;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
20 private UnitEquipmentItem equip;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
21 public event EventHandler ValueChanged;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
22
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
23 public EquipmentAmountControl()
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
24 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
25 InitializeComponent();
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
26 rbEquipAll.Text = Translation.GetTranslation("rbEquipAll", "equip all");
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
29 public void SetUnit(Unit equipUnit)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
30 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
31 unit = equipUnit;
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 SetUnitEquipmentItem(UnitEquipmentItem unitEquipment)
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 equip = unitEquipment;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
37 SetWidgetValues();
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 private void OnValueChanged()
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 if (ValueChanged != null)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
43 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
44 ValueChanged(this, new EventArgs());
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
48 private void SetWidgetValues()
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 if (equip != null)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
51 {
89
971f7801f984 Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 88
diff changeset
52 bool equipIsRatioLimit = UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip);
971f7801f984 Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 88
diff changeset
53 double maxPercent = RoundPercentage(UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
54 double minPercent = RoundPercentage(UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
55 int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
56 int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
57
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
58 SetUpDownControlMinMaxes(minPercent, maxPercent, minNumber, maxNumber);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
59
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
60 if (equipIsRatioLimit)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
61 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
62 SetEquipmentAmountsFromPercentage(minPercent);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
63 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
64 else
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
65 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
66 SetEquipmentAmountsFromNumber(minNumber);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
67 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
68
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
69 rbEquipAll.Enabled = equipIsRatioLimit && maxPercent == 100;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
70 rbEquipAll.Checked = equipIsRatioLimit && minPercent == 100;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
71 percentage.Enabled = equipIsRatioLimit && minPercent != 100;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
72 rbPercentage.Enabled = percentage.Enabled;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
73 rbPercentage.Checked = equipIsRatioLimit && !rbEquipAll.Checked;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
74 numeric.Enabled = !equipIsRatioLimit || minPercent != 100;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
75 rbNumeric.Enabled = numeric.Enabled;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
76 rbNumeric.Checked = !equipIsRatioLimit;
91
e1e3957db129 Fixes #206:
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
77
e1e3957db129 Fixes #206:
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
78 SetUnitEquipmentItemAmount();
90
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 else
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 Enabled = false;
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 }
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 private void SetUpDownControlMinMaxes(double minPercent, double maxPercent, int minNumber, int maxNumber)
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 percentage.ValueChanged -= percentage_ValueChanged;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
89 numeric.ValueChanged -= numeric_ValueChanged;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
90 SetUpDownControlMinMax(percentage, minPercent, maxPercent);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
91 SetUpDownControlMinMax(numeric, (decimal) minNumber, (decimal) maxNumber);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
92 percentage.ValueChanged += percentage_ValueChanged;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
93 numeric.ValueChanged += numeric_ValueChanged;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
94 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
95
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
96 private void SetUpDownControlMinMax(NumericUpDown upDownControl, double min, double max)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
97 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
98 SetUpDownControlMinMax(upDownControl, (decimal)min, (decimal)max);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
99 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
100
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
101 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
102 {
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
103 upDownControl.Minimum = min;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
104 upDownControl.Maximum = max;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
105 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
106
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
107 private void rbEquipAll_CheckedChanged(object sender, EventArgs e)
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 bool equipAll = rbEquipAll.Checked;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
110 numeric.Enabled = !equipAll;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
111 percentage.Enabled = !equipAll;
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 if (equipAll)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
114 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
115 numeric.Value = unit.Size;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
116 percentage.Value = 100;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
117 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
118
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
119 radioCheckedChanged(sender, e);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
120 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
121
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
122 private void percentage_ValueChanged(object sender, EventArgs e)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
123 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
124 SetNumericValueFromPercentage();
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
125 rbEquipAll.Checked = (percentage.Value == 100 && !rbNumeric.Checked);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
126 OnValueChanged();
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
127 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
128
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
129 private void SetNumericValueFromPercentage()
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
130 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
131 numeric.ValueChanged -= numeric_ValueChanged;
88
340e711ca4c3 Re #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
132 numeric.Value = CalculateNumericValueFromPercentage(percentage.Value);
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
133 numeric.ValueChanged += numeric_ValueChanged;
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 decimal CalculateNumericValueFromPercentage(decimal percent)
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 return (decimal) IBBoard.CustomMath.IBBMath.Round((double)(unit.Size * (percent / 100)), equip.RoundNumberUp);
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 numeric_ValueChanged(object sender, EventArgs e)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
142 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
143 SetPercentageValueFromNumeric();
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
144 OnValueChanged();
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 SetPercentageValueFromNumeric()
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
148 {
88
340e711ca4c3 Re #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
149 int number = (int)numeric.Value;
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
150 percentage.ValueChanged -= percentage_ValueChanged;
88
340e711ca4c3 Re #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
151 percentage.Value = CalcualtePercentageValueFromNumber(number);
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
152 percentage.ValueChanged += percentage_ValueChanged;
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
155 private decimal CalcualtePercentageValueFromNumber(int number)
89
971f7801f984 Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 88
diff changeset
156 {
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
157 return (decimal) RoundPercentage((number / (unit.Size * 1.0)) * 100);
89
971f7801f984 Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 88
diff changeset
158 }
971f7801f984 Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 88
diff changeset
159
971f7801f984 Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 88
diff changeset
160 private double RoundPercentage(double percent)
971f7801f984 Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 88
diff changeset
161 {
971f7801f984 Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 88
diff changeset
162 return Math.Round(percent, 1);
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
163 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
164
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
165 public double EquipmentAmount
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
166 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
167 get
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
168 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
169 double val = 0;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
170
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
171 if (rbNumeric.Checked)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
172 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
173 val = (double) numeric.Value;
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 else if (rbPercentage.Checked)
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 val = (double) percentage.Value;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
178 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
179 else if (rbEquipAll.Checked)
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 val = 100;
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 else
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
184 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
185 val = 0;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
186 }
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 return val;
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 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
191
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
192 public bool IsRatioEquipmentAmount
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
193 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
194 get
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 return !rbNumeric.Checked;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
197 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
198 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
199
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
200 private void SetUnitEquipmentItemAmount()
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
201 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
202 double equipAmountNum = unit.GetEquipmentAmount(equip);
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 if (equipAmountNum > 0)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
205 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
206 bool isRatio = unit.GetEquipmentAmountIsRatio(equip);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
207
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
208 if (isRatio)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
209 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
210 SetEquipmentAmountsFromPercentage(equipAmountNum);
93
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
211
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
212 if (equipAmountNum == 100)
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
213 {
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
214 rbEquipAll.Checked = true;
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
215 }
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
216 else
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
217 {
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
218 rbPercentage.Checked = true;
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
219 }
90
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 else
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 int equipAmount = (int) equipAmountNum;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
224 SetEquipmentAmountsFromNumber(equipAmount);
93
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
225 rbNumeric.Checked = true;
90
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 }
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
230 private void SetEquipmentAmountsFromPercentage(double equipAmountNum)
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 decimal decEquipAmount = (decimal) equipAmountNum;
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 if (decEquipAmount > percentage.Maximum)
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 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.", equipAmountNum, percentage.Maximum);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
237 string percentageTooLargeTitle = Translation.GetTranslation("equipPercentageTooLargeTitle", "Equipment percentage too large");
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
238 MessageBox.Show(ParentForm, percentageTooLarge, percentageTooLargeTitle);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
239 decEquipAmount = percentage.Maximum;
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 else if (decEquipAmount < percentage.Minimum)
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 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.", equipAmountNum, percentage.Minimum);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
244 string percentageTooSmallTitle = Translation.GetTranslation("equipPercentageTooSmallTitle", "Equipment percentage too small");
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
245 MessageBox.Show(ParentForm, percentageTooSmall, percentageTooSmallTitle);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
246 decEquipAmount = percentage.Minimum;
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
249 numeric.Value = CalculateNumericValueFromPercentage(decEquipAmount);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
250 percentage.Value = decEquipAmount;
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
253 private void SetEquipmentAmountsFromNumber(int equipAmount)
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 (equipAmount > numeric.Maximum)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
256 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
257 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);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
258 string amountTooLargeTitle = Translation.GetTranslation("equipNumberTooLargeTitle", "Equipment amount too large");
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
259 MessageBox.Show(ParentForm, amountTooLarge, amountTooLargeTitle);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
260 equipAmount = (int)numeric.Maximum;
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 else if (equipAmount < numeric.Minimum)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
263 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
264 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);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
265 string amountTooSmallTitle = Translation.GetTranslation("equipNumberTooSmallTitle", "Equipment amount too small");
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
266 MessageBox.Show(ParentForm, amountTooSmall, amountTooSmallTitle);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
267 equipAmount = (int) numeric.Minimum;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
268 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
269
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
270 percentage.Value = CalcualtePercentageValueFromNumber(equipAmount);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
271 numeric.Value = equipAmount;
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
274 private void radioCheckedChanged(object sender, EventArgs e)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
275 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
276 OnValueChanged();
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 }