annotate UI/EquipmentAmountControl.cs @ 97:e356134d73c4

Re #209: equipmentslot Value problem * Add lots of debugging in the hope of tracking down Snowblizz's continued problems!
author IBBoard <dev@ibboard.co.uk>
date Mon, 16 Nov 2009 20:56:54 +0000
parents 057498981bde
children c7afc7824f50
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;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
12 using IBBoard.WarFoundry.API;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
13 using IBBoard.WarFoundry.API.Objects;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
14 using IBBoard.WarFoundry.API.Util;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
15
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
16 namespace IBBoard.WarFoundry.GUI.WinForms.UI
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
17 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
18 public partial class EquipmentAmountControl : UserControl
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
19 {
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
20 private ILog log = LogManager.GetLogger(typeof(EquipmentAmountControl));
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
21 private Unit unit;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
22 private UnitEquipmentItem equip;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
23 public event EventHandler ValueChanged;
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 public EquipmentAmountControl()
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
26 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
27 InitializeComponent();
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
28 rbEquipAll.Text = Translation.GetTranslation("rbEquipAll", "equip all");
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
31 public void SetUnit(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 unit = equipUnit;
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
34 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
35 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
36
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
37 public void SetUnitEquipmentItem(UnitEquipmentItem unitEquipment)
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 equip = unitEquipment;
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
40 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
41 SetWidgetValues();
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
42 }
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 private void OnValueChanged()
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 if (ValueChanged != null)
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 ValueChanged(this, new EventArgs());
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 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
51
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
52 private void SetWidgetValues()
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 if (equip != null)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
55 {
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
56 log.Debug("Equipment update");
89
971f7801f984 Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 88
diff changeset
57 bool equipIsRatioLimit = UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip);
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
58 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
59 double maxPercent = RoundPercentage(UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
60 log.Debug("Equipment max percentage: " + maxPercent);
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
61 double minPercent = RoundPercentage(UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
62 log.Debug("Equipment min percentage: " + minPercent);
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
63 int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip);
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
64 log.Debug("Equipment max count: " + maxNumber);
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
65 int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip);
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
66 log.Debug("Equipment min count: " + minNumber);
90
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 SetUpDownControlMinMaxes(minPercent, maxPercent, minNumber, maxNumber);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
69
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
70 if (equipIsRatioLimit)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
71 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
72 SetEquipmentAmountsFromPercentage(minPercent);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
73 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
74 else
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
75 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
76 SetEquipmentAmountsFromNumber(minNumber);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
77 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
78
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
79 rbEquipAll.Enabled = equipIsRatioLimit && maxPercent == 100;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
80 rbEquipAll.Checked = equipIsRatioLimit && minPercent == 100;
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
81 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
82 percentage.Enabled = equipIsRatioLimit && minPercent != 100;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
83 rbPercentage.Enabled = percentage.Enabled;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
84 rbPercentage.Checked = equipIsRatioLimit && !rbEquipAll.Checked;
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
85 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
86 numeric.Enabled = !equipIsRatioLimit || minPercent != 100;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
87 rbNumeric.Enabled = numeric.Enabled;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
88 rbNumeric.Checked = !equipIsRatioLimit;
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
89 log.Debug("rbNumeric: " + (rbNumeric.Enabled ? "enabled" : "disabled") + " " + (rbNumeric.Checked ? "checked" : "unchecked"));
91
e1e3957db129 Fixes #206:
IBBoard <dev@ibboard.co.uk>
parents: 90
diff changeset
90 SetUnitEquipmentItemAmount();
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
91 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
92 else
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
93 {
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
94 log.Debug("Null equipment - no widget update");
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
95 Enabled = false;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
96 }
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
99 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
100 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
101 percentage.ValueChanged -= percentage_ValueChanged;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
102 numeric.ValueChanged -= numeric_ValueChanged;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
103 SetUpDownControlMinMax(percentage, minPercent, maxPercent);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
104 SetUpDownControlMinMax(numeric, (decimal) minNumber, (decimal) maxNumber);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
105 percentage.ValueChanged += percentage_ValueChanged;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
106 numeric.ValueChanged += numeric_ValueChanged;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
107 }
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 private void SetUpDownControlMinMax(NumericUpDown upDownControl, double min, double max)
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 SetUpDownControlMinMax(upDownControl, (decimal)min, (decimal)max);
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
114 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
115 {
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
116 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
117 upDownControl.Minimum = min;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
118 upDownControl.Maximum = max;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
119 }
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 private void rbEquipAll_CheckedChanged(object sender, EventArgs e)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
122 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
123 bool equipAll = rbEquipAll.Checked;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
124 numeric.Enabled = !equipAll;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
125 percentage.Enabled = !equipAll;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
126
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
127 if (equipAll)
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 numeric.Value = unit.Size;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
130 percentage.Value = 100;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
131 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
132
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
133 radioCheckedChanged(sender, e);
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 percentage_ValueChanged(object sender, EventArgs e)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
137 {
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
138 log.Debug("Percentage value changed");
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
139 SetNumericValueFromPercentage();
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
140 rbEquipAll.Checked = (percentage.Value == 100 && !rbNumeric.Checked);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
141 OnValueChanged();
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
144 private void SetNumericValueFromPercentage()
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 numeric.ValueChanged -= numeric_ValueChanged;
88
340e711ca4c3 Re #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
147 numeric.Value = CalculateNumericValueFromPercentage(percentage.Value);
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
148 numeric.ValueChanged += numeric_ValueChanged;
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
151 private decimal CalculateNumericValueFromPercentage(decimal percent)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
152 {
96
057498981bde Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 93
diff changeset
153 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
154 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
155 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
156 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
157
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
158 private void numeric_ValueChanged(object sender, EventArgs e)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
159 {
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
160 log.Debug("Numeric value changed");
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
161 SetPercentageValueFromNumeric();
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
162 OnValueChanged();
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 private void SetPercentageValueFromNumeric()
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
166 {
88
340e711ca4c3 Re #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
167 int number = (int)numeric.Value;
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
168 percentage.ValueChanged -= percentage_ValueChanged;
88
340e711ca4c3 Re #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 85
diff changeset
169 percentage.Value = CalcualtePercentageValueFromNumber(number);
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
170 percentage.ValueChanged += percentage_ValueChanged;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
171 }
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 private decimal CalcualtePercentageValueFromNumber(int number)
89
971f7801f984 Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 88
diff changeset
174 {
96
057498981bde Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 93
diff changeset
175 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
176 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
177 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
178 }
971f7801f984 Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 88
diff changeset
179
971f7801f984 Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 88
diff changeset
180 private double RoundPercentage(double percent)
971f7801f984 Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 88
diff changeset
181 {
971f7801f984 Fixes #205: Odd/prime numbers causes a crash
IBBoard <dev@ibboard.co.uk>
parents: 88
diff changeset
182 return Math.Round(percent, 1);
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
183 }
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 public double EquipmentAmount
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 get
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 double val = 0;
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 if (rbNumeric.Checked)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
192 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
193 val = (double) numeric.Value;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
194 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
195 else if (rbPercentage.Checked)
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 val = (double) percentage.Value;
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 else if (rbEquipAll.Checked)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
200 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
201 val = 100;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
202 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
203 else
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 val = 0;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
206 }
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 return val;
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 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
211
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
212 public bool IsRatioEquipmentAmount
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
213 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
214 get
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 return !rbNumeric.Checked;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
217 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
218 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
219
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
220 private void SetUnitEquipmentItemAmount()
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
221 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
222 double equipAmountNum = unit.GetEquipmentAmount(equip);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
223
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
224 if (equipAmountNum > 0)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
225 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
226 bool isRatio = unit.GetEquipmentAmountIsRatio(equip);
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 if (isRatio)
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 SetEquipmentAmountsFromPercentage(equipAmountNum);
93
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
231
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
232 if (equipAmountNum == 100)
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
233 {
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
234 rbEquipAll.Checked = true;
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
235 }
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
236 else
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
237 {
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
238 rbPercentage.Checked = true;
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
239 }
90
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
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 int equipAmount = (int) equipAmountNum;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
244 SetEquipmentAmountsFromNumber(equipAmount);
93
37126221efa6 Re #208
IBBoard <dev@ibboard.co.uk>
parents: 91
diff changeset
245 rbNumeric.Checked = true;
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
246 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
247 }
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
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
250 private void SetEquipmentAmountsFromPercentage(double equipAmount)
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
251 {
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
252 log.Debug("Set equipment amount from percentage: " + equipAmount);
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
253 decimal decEquipAmount = (decimal) equipAmount;
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
254
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
255 if (decEquipAmount > percentage.Maximum)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
256 {
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
257 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);
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
258 string percentageTooLargeTitle = Translation.GetTranslation("equipPercentageTooLargeTitle", "Equipment percentage too large");
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
259 MessageBox.Show(ParentForm, percentageTooLarge, percentageTooLargeTitle);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
260 decEquipAmount = percentage.Maximum;
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
261 log.Debug("Limited equipment amount to " + decEquipAmount);
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
262 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
263 else if (decEquipAmount < percentage.Minimum)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
264 {
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
265 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);
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
266 string percentageTooSmallTitle = Translation.GetTranslation("equipPercentageTooSmallTitle", "Equipment percentage too small");
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
267 MessageBox.Show(ParentForm, percentageTooSmall, percentageTooSmallTitle);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
268 decEquipAmount = percentage.Minimum;
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
269 log.Debug("Limited equipment amount to " + decEquipAmount);
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
270 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
271
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
272 numeric.Value = CalculateNumericValueFromPercentage(decEquipAmount);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
273 percentage.Value = decEquipAmount;
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
276 private void SetEquipmentAmountsFromNumber(int equipAmount)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
277 {
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
278 log.Debug("Set equipment percentage from amount: " + equipAmount);
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
279
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
280 if (equipAmount > numeric.Maximum)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
281 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
282 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
283 string amountTooLargeTitle = Translation.GetTranslation("equipNumberTooLargeTitle", "Equipment amount too large");
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
284 MessageBox.Show(ParentForm, amountTooLarge, amountTooLargeTitle);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
285 equipAmount = (int)numeric.Maximum;
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
286 log.Debug("Limited equipment amount to " + equipAmount);
90
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
287 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
288 else if (equipAmount < numeric.Minimum)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
289 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
290 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
291 string amountTooSmallTitle = Translation.GetTranslation("equipNumberTooSmallTitle", "Equipment amount too small");
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
292 MessageBox.Show(ParentForm, amountTooSmall, amountTooSmallTitle);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
293 equipAmount = (int) numeric.Minimum;
97
e356134d73c4 Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents: 96
diff changeset
294 log.Debug("Limited equipment amount to " + equipAmount);
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
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
297 percentage.Value = CalcualtePercentageValueFromNumber(equipAmount);
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
298 numeric.Value = equipAmount;
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
299 }
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
300
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
301 private void radioCheckedChanged(object sender, EventArgs e)
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
302 {
63ca28bd8ada Re #179: Translations throughout GUI
IBBoard <dev@ibboard.co.uk>
parents: 89
diff changeset
303 OnValueChanged();
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 }