annotate UI/EquipmentAmountControl.cs @ 85:0bb9f40d44eb

Re #88: Complete initial WinForms UI * Add basic initial "about" box * Translations (below) Re #179: Make sure that translations are used throughout UI * Make all controls translatable * Supply translations for all controls Re #204: Use new limits in WinForms UI * Warn the user and cap the number if we try to go out of range for equipment
author IBBoard <dev@ibboard.co.uk>
date Sat, 31 Oct 2009 20:54:42 +0000
parents 6d5cb8c7b6ed
children 340e711ca4c3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
85
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
1 using System;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
2 using System.Collections.Generic;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
3 using System.ComponentModel;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
4 using System.Drawing;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
5 using System.Data;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
6 using System.Text;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
7 using System.Windows.Forms;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
8 using IBBoard.CustomMath;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
9 using IBBoard.Lang;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
10 using IBBoard.Limits;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
11 using IBBoard.WarFoundry.API;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
12 using IBBoard.WarFoundry.API.Objects;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
13 using IBBoard.WarFoundry.API.Util;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
14
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
15 namespace IBBoard.WarFoundry.GUI.WinForms.UI
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
16 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
17 public partial class EquipmentAmountControl : UserControl
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
18 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
19 private Unit unit;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
20 private UnitEquipmentItem equip;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
21 public event EventHandler ValueChanged;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
22
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
23 public EquipmentAmountControl()
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
24 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
25 InitializeComponent();
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
26 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
27
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
28 public void SetUnit(Unit equipUnit)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
29 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
30 unit = equipUnit;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
31 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
32
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
33 public void SetUnitEquipmentItem(UnitEquipmentItem unitEquipment)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
34 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
35 equip = unitEquipment;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
36 SetWidgetValues();
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
37 SetUnitEquipmentItemAmount();
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
38 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
39
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
40 private void OnValueChanged()
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
41 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
42 if (ValueChanged != null)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
43 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
44 ValueChanged(this, new EventArgs());
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
45 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
46 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
47
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
48 private void SetWidgetValues()
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
49 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
50 if (equip != null)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
51 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
52 bool equipIsRatioLimit = UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
53 double maxPercent = UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
54 double minPercent = UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
55 int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
56 int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
57
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
58 SetUpDownControlMinMaxes(minPercent, maxPercent, minNumber, maxNumber);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
59
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
60 if (equipIsRatioLimit)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
61 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
62 SetEquipmentAmountsFromPercentage(minPercent);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
63 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
64 else
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
65 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
66 SetEquipmentAmountsFromNumber(minNumber);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
67 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
68
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
69 rbEquipAll.Enabled = equipIsRatioLimit && maxPercent == 100;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
70 rbEquipAll.Checked = equipIsRatioLimit && minPercent == 100;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
71 percentage.Enabled = equipIsRatioLimit && minPercent != 100;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
72 rbPercentage.Enabled = percentage.Enabled;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
73 rbPercentage.Checked = equipIsRatioLimit && !rbEquipAll.Checked;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
74 numeric.Enabled = !equipIsRatioLimit || minPercent != 100;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
75 rbNumeric.Enabled = numeric.Enabled;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
76 rbNumeric.Checked = !equipIsRatioLimit;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
77 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
78 else
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
79 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
80 Enabled = false;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
81 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
82 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
83
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
84 private void SetUpDownControlMinMaxes(double minPercent, double maxPercent, int minNumber, int maxNumber)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
85 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
86 percentage.ValueChanged -= percentage_ValueChanged;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
87 numeric.ValueChanged -= numeric_ValueChanged;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
88 SetUpDownControlMinMax(percentage, minPercent, maxPercent);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
89 SetUpDownControlMinMax(numeric, (decimal) minNumber, (decimal) maxNumber);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
90 percentage.ValueChanged += percentage_ValueChanged;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
91 numeric.ValueChanged += numeric_ValueChanged;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
92 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
93
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
94 private void SetUpDownControlMinMax(NumericUpDown upDownControl, double min, double max)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
95 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
96 SetUpDownControlMinMax(upDownControl, (decimal)min, (decimal)max);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
97 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
98
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
99 private void SetUpDownControlMinMax(NumericUpDown upDownControl, decimal min, decimal max)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
100 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
101 upDownControl.Minimum = min;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
102 upDownControl.Maximum = max;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
103 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
104
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
105 private void rbEquipAll_CheckedChanged(object sender, EventArgs e)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
106 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
107 bool equipAll = rbEquipAll.Checked;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
108 numeric.Enabled = !equipAll;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
109 percentage.Enabled = !equipAll;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
110
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
111 if (equipAll)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
112 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
113 numeric.Value = unit.Size;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
114 percentage.Value = 100;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
115 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
116
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
117 radioCheckedChanged(sender, e);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
118 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
119
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
120 private void percentage_ValueChanged(object sender, EventArgs e)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
121 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
122 SetNumericValueFromPercentage();
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
123 rbEquipAll.Checked = (percentage.Value == 100 && !rbNumeric.Checked);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
124 OnValueChanged();
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
125 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
126
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
127 private void SetNumericValueFromPercentage()
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
128 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
129 numeric.Value = CalculateNumericValueFromPercentage(percentage.Value);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
130 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
131
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
132 private decimal CalculateNumericValueFromPercentage(decimal percent)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
133 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
134 return (decimal) IBBoard.CustomMath.IBBMath.Round((double)(unit.Size * (percent / 100)), equip.RoundNumberUp);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
135 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
136
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
137 private void numeric_ValueChanged(object sender, EventArgs e)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
138 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
139 SetPercentageValueFromNumeric();
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
140 OnValueChanged();
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
141 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
142
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
143 private void SetPercentageValueFromNumeric()
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
144 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
145 int number = (int)numeric.Value;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
146 percentage.Value = CalcualtePercentageValueFromNumber(number);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
147 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
148
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
149 private decimal CalcualtePercentageValueFromNumber(int number)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
150 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
151 return (decimal) Math.Round((number / (unit.Size * 1.0)) * 100, 1);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
152 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
153
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
154 public double EquipmentAmount
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
155 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
156 get
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
157 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
158 double val = 0;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
159
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
160 if (rbNumeric.Checked)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
161 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
162 val = (double) numeric.Value;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
163 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
164 else if (rbPercentage.Checked)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
165 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
166 val = (double) percentage.Value;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
167 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
168 else if (rbEquipAll.Checked)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
169 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
170 val = 100;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
171 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
172 else
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
173 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
174 val = 0;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
175 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
176
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
177 return val;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
178 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
179 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
180
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
181 public bool IsRatioEquipmentAmount
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
182 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
183 get
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
184 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
185 return !rbNumeric.Checked;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
186 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
187 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
188
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
189 private void SetUnitEquipmentItemAmount()
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
190 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
191 double equipAmountNum = unit.GetEquipmentAmount(equip);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
192
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
193 if (equipAmountNum > 0)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
194 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
195 bool isRatio = unit.GetEquipmentAmountIsRatio(equip);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
196
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
197 if (isRatio)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
198 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
199 SetEquipmentAmountsFromPercentage(equipAmountNum);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
200 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
201 else
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
202 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
203 int equipAmount = (int) equipAmountNum;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
204 SetEquipmentAmountsFromNumber(equipAmount);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
205 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
206 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
207 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
208
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
209 private void SetEquipmentAmountsFromPercentage(double equipAmountNum)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
210 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
211 decimal decEquipAmount = (decimal) equipAmountNum;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
212
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
213 if (decEquipAmount > percentage.Maximum)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
214 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
215 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);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
216 string percentageTooLargeTitle = Translation.GetTranslation("equipPercentageTooLargeTitle", "Equipment percentage too large");
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
217 MessageBox.Show(ParentForm, percentageTooLarge, percentageTooLargeTitle);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
218 decEquipAmount = percentage.Maximum;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
219 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
220 else if (decEquipAmount < percentage.Minimum)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
221 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
222 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);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
223 string percentageTooSmallTitle = Translation.GetTranslation("equipPercentageTooSmallTitle", "Equipment percentage too small");
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
224 MessageBox.Show(ParentForm, percentageTooSmall, percentageTooSmallTitle);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
225 decEquipAmount = percentage.Minimum;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
226 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
227
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
228 numeric.Value = CalculateNumericValueFromPercentage(decEquipAmount);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
229 percentage.Value = decEquipAmount;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
230 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
231
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
232 private void SetEquipmentAmountsFromNumber(int equipAmount)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
233 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
234 if (equipAmount > numeric.Maximum)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
235 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
236 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);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
237 string amountTooLargeTitle = Translation.GetTranslation("equipNumberTooLargeTitle", "Equipment amount too large");
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
238 MessageBox.Show(ParentForm, amountTooLarge, amountTooLargeTitle);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
239 equipAmount = (int)numeric.Maximum;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
240 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
241 else if (equipAmount < numeric.Minimum)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
242 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
243 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);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
244 string amountTooSmallTitle = Translation.GetTranslation("equipNumberTooSmallTitle", "Equipment amount too small");
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
245 MessageBox.Show(ParentForm, amountTooSmall, amountTooSmallTitle);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
246 equipAmount = (int) numeric.Minimum;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
247 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
248
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
249 percentage.Value = CalcualtePercentageValueFromNumber(equipAmount);
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
250 numeric.Value = equipAmount;
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
251 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
252
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
253 private void radioCheckedChanged(object sender, EventArgs e)
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
254 {
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
255 OnValueChanged();
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
256 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
257 }
0bb9f40d44eb Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents: 83
diff changeset
258 }