annotate UI/EquipmentAmountControl.cs @ 41:4fc87d6e6119

Re #117: Add percentage and number boxes to equipment item dialogs * Add events and value setting in EquipmentAmount widget * Hook up "value changed" event on new equipment form Also fixes adding side of re #114 (Enabling/disabling of "equip all" and number for equipment is wrong) by rebuilding everything
author IBBoard <dev@ibboard.co.uk>
date Sun, 06 Sep 2009 19:31:49 +0000
parents 740350673006
children d06c2e390a14
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 using System;
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 using System.Collections.Generic;
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 using System.ComponentModel;
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 using System.Drawing;
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System.Data;
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using System.Text;
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using System.Windows.Forms;
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 using IBBoard.Lang;
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 using IBBoard.WarFoundry.API;
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 using IBBoard.WarFoundry.API.Objects;
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 namespace IBBoard.WarFoundry.GUI.WinForms.UI
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 {
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 public partial class EquipmentAmountControl : UserControl
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 {
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 private Unit unit;
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 private UnitEquipmentItem equip;
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 public EquipmentAmountControl()
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 {
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 InitializeComponent();
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 }
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 public void SetUnit(Unit equipUnit)
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 {
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 unit = equipUnit;
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 }
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 public void SetUnitEquipmentItem(UnitEquipmentItem unitEquipment)
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 {
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 equip = unitEquipment;
41
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
32 SetWidgetValues();
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
33 }
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
34
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
35 public event EventHandler ValueChanged;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
36
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
37 private void OnValueChanged()
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
38 {
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
39 if (ValueChanged != null)
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
40 {
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
41 ValueChanged(this, new EventArgs());
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
42 }
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
43 }
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
44
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
45 private void SetWidgetValues()
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
46 {
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
47 if (equip != null)
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
48 {
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
49 if (equip.IsRatioLimit)
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
50 {
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
51 double minPercent = equip.MinPercentage;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
52 double maxPercent = equip.MaxPercentage;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
53 SetUpDownControlMinMaxAndValue(percentage, minPercent, maxPercent);
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
54 SetUpDownControlMinMaxAndValue(numeric, CalculateNumericValueFromPercentage(minPercent), CalculateNumericValueFromPercentage(maxPercent));
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
55 rbEquipAll.Enabled = maxPercent == 100;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
56
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
57 if (minPercent == 100)
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
58 {
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
59 rbEquipAll.Checked = true;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
60 percentage.Enabled = false;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
61 rbPercentage.Enabled = false;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
62 numeric.Enabled = false;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
63 rbNumeric.Enabled = false;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
64 }
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
65 else
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
66 {
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
67 rbPercentage.Checked = true;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
68 percentage.Enabled = true;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
69 rbPercentage.Enabled = true;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
70 numeric.Enabled = true;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
71 rbNumeric.Enabled = true;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
72 }
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
73 }
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
74 else
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
75 {
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
76 percentage.Enabled = false;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
77 rbPercentage.Enabled = false;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
78 int minNumber = equip.MinNumber;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
79 int maxNumber = equip.MaxNumber;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
80 SetUpDownControlMinMaxAndValue(numeric, (decimal) minNumber, (decimal) maxNumber);
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
81 SetUpDownControlMinMaxAndValue(percentage, CalcualtePercentageValueFromNumber(minNumber), CalcualtePercentageValueFromNumber(maxNumber));
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
82 rbEquipAll.Enabled = maxNumber == WarFoundryCore.INFINITY;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
83
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
84 if (minNumber == WarFoundryCore.INFINITY)
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
85 {
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
86 rbEquipAll.Checked = true;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
87 numeric.Enabled = false;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
88 rbNumeric.Enabled = false;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
89 }
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
90 else
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
91 {
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
92 rbNumeric.Checked = true;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
93 numeric.Enabled = true;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
94 rbNumeric.Enabled = true;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
95 }
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
96 }
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
97 }
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
98 else
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
99 {
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
100 Enabled = false;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
101 }
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
102 }
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
103
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
104 private void SetUpDownControlMinMaxAndValue(NumericUpDown upDownControl, double min, double max)
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
105 {
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
106 SetUpDownControlMinMaxAndValue(upDownControl, (decimal)min, (decimal)max);
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
107 }
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
108
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
109 private void SetUpDownControlMinMaxAndValue(NumericUpDown upDownControl, decimal min, decimal max)
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
110 {
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
111 upDownControl.Minimum = (min == WarFoundryCore.INFINITY ? unit.Size : min);
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
112 upDownControl.Maximum = (max == WarFoundryCore.INFINITY ? unit.Size : max);
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
113 upDownControl.Value = upDownControl.Value;
40
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
114 }
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
115
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
116 private void rbEquipAll_CheckedChanged(object sender, EventArgs e)
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
117 {
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
118 bool equipAll = rbEquipAll.Checked;
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
119 numeric.Enabled = !equipAll;
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
120 percentage.Enabled = !equipAll;
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
121
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
122 if (equipAll)
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
123 {
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
124 numeric.Value = unit.Size;
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
125 percentage.Value = 100;
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
126 }
41
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
127
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
128 OnValueChanged();
40
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
129 }
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
130
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
131 private void percentage_ValueChanged(object sender, EventArgs e)
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
132 {
41
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
133 SetNumericValueFromPercentage();
40
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
134 rbEquipAll.Checked = (percentage.Value == 100);
41
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
135 OnValueChanged();
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
136 }
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
137
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
138 private void SetNumericValueFromPercentage()
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
139 {
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
140 double percent = (double)percentage.Value;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
141 numeric.Value = CalculateNumericValueFromPercentage(percent);
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
142 }
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
143
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
144 private decimal CalculateNumericValueFromPercentage(double percent)
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
145 {
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
146 return (decimal) IBBMath.Round(unit.Size * (percent / 100.0), equip.RoundNumberUp);
40
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
147 }
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
148
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
149 private void numeric_ValueChanged(object sender, EventArgs e)
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
150 {
41
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
151 SetPercentageValueFromNumeric();
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
152 OnValueChanged();
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
153 }
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
154
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
155 private void SetPercentageValueFromNumeric()
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
156 {
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
157 int number = (int)numeric.Value;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
158 percentage.Value = CalcualtePercentageValueFromNumber(number);
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
159 }
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
160
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
161 private decimal CalcualtePercentageValueFromNumber(int number)
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
162 {
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
163 decimal percent = 0;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
164
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
165 if (number > 0)
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
166 {
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
167 percent = (decimal) Math.Round((number / (unit.Size * 1.0)) * 100, 1);
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
168 }
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
169 else if (number == WarFoundryCore.INFINITY)
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
170 {
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
171 percent = 100;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
172 }
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
173
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
174 return percent;
40
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
175 }
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
176
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
177 public double EquipmentAmount
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
178 {
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
179 get
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
180 {
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
181 double val = 0;
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
182
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
183 if (rbNumeric.Checked)
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
184 {
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
185 val = (double) numeric.Value;
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
186 }
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
187 else if (rbPercentage.Enabled)
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
188 {
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
189 val = (double) percentage.Value / 100.0;
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
190 }
41
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
191 else if (rbEquipAll.Checked)
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
192 {
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
193 val = WarFoundryCore.INFINITY;
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
194 }
40
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
195 else
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
196 {
41
4fc87d6e6119 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 40
diff changeset
197 val = 0;
40
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
198 }
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
199
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
200 return val;
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
201 }
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
202 }
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
203
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
204 public bool IsRatioEquipmentAmount
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
205 {
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
206 get
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
207 {
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
208 return rbPercentage.Checked;
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
209 }
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
210 }
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
211 }
740350673006 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
212 }