Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.WinForms
annotate FrmEditUnitEquipment.cs @ 17:475d3cdb75f4
* White space cleanup
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 17 Jun 2009 14:05:31 +0000 |
parents | 19bdbb80999c |
children | 7c366fe55635 |
rev | line source |
---|---|
3
8935971e307c
Fixes #1 - Correctly license code
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
1 // This file (FrmEditUnitEquipment.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard. |
8935971e307c
Fixes #1 - Correctly license code
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
2 // |
8935971e307c
Fixes #1 - Correctly license code
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. |
8935971e307c
Fixes #1 - Correctly license code
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
4 |
0 | 5 using System; |
6 using System.Drawing; | |
7 using System.Collections; | |
8 using System.ComponentModel; | |
9 using System.Windows.Forms; | |
10 using IBBoard.Commands; | |
11 using IBBoard.WarFoundry.API; | |
12 using IBBoard.WarFoundry.API.Commands; | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
13 using IBBoard.WarFoundry.API.Objects; |
0 | 14 |
15 namespace IBBoard.WarFoundry | |
16 { | |
17 /// <summary> | |
18 /// Summary description for FrmEditUnitEquipment. | |
19 /// </summary> | |
20 public class FrmEditUnitEquipment : System.Windows.Forms.Form | |
21 { | |
22 private Unit unit; | |
23 private UnitEquipmentItem equipItem; | |
8
755e60be28be
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
3
diff
changeset
|
24 private double equipAmount; |
0 | 25 private CommandStack commandStack; |
26 | |
27 private System.Windows.Forms.NumericUpDown numEquipAmount; | |
28 private System.Windows.Forms.Label lblPercent; | |
29 private System.Windows.Forms.Label lblAmount; | |
30 private System.Windows.Forms.Button bttnCancel; | |
31 private System.Windows.Forms.Button bttnOkay; | |
32 private System.Windows.Forms.CheckBox cbEquipAll; | |
33 /// <summary> | |
34 /// Required designer variable. | |
35 /// </summary> | |
36 private System.ComponentModel.Container components = null; | |
37 | |
38 public FrmEditUnitEquipment(Unit unit, UnitEquipmentItem equipItem, CommandStack stack) | |
39 { | |
40 commandStack = stack; | |
41 this.unit = unit; | |
42 this.equipItem = equipItem; | |
43 InitializeComponent(); | |
10
19bdbb80999c
Closes #47 - Remove magic numbers
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
44 this.Text = equipItem.Name + " for " + unit.Name; |
19bdbb80999c
Closes #47 - Remove magic numbers
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
45 equipAmount = unit.GetEquipmentAmount(equipItem); |
0 | 46 |
10
19bdbb80999c
Closes #47 - Remove magic numbers
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
47 if (equipItem.IsRatioLimit) |
0 | 48 { |
10
19bdbb80999c
Closes #47 - Remove magic numbers
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
49 numEquipAmount.Minimum = (decimal)Math.Round(equipItem.MinNumber * 100.0, 2); |
19bdbb80999c
Closes #47 - Remove magic numbers
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
50 numEquipAmount.Maximum = (decimal)Math.Round(equipItem.MaxNumber * 100.0, 2); |
0 | 51 numEquipAmount.Value = (decimal)Math.Round(equipAmount * 100, 2); |
52 cbEquipAll.Enabled = false; | |
53 lblPercent.Visible = true; | |
54 numEquipAmount.Width = 120; | |
55 } | |
56 else | |
57 { | |
10
19bdbb80999c
Closes #47 - Remove magic numbers
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
58 numEquipAmount.Minimum = (decimal)(equipItem.MinNumber != WarFoundryCore.INFINITY ? equipItem.MinNumber : unit.Size); |
19bdbb80999c
Closes #47 - Remove magic numbers
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
59 numEquipAmount.Maximum = (decimal)(equipItem.MaxNumber != WarFoundryCore.INFINITY ? equipItem.MaxNumber : unit.Size); |
19bdbb80999c
Closes #47 - Remove magic numbers
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
60 numEquipAmount.Value = (decimal)(equipAmount == WarFoundryCore.INFINITY ? unit.Size : equipAmount); |
19bdbb80999c
Closes #47 - Remove magic numbers
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
61 cbEquipAll.Checked = (equipAmount == WarFoundryCore.INFINITY); |
19bdbb80999c
Closes #47 - Remove magic numbers
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
62 cbEquipAll.Enabled = (equipItem.MaxNumber == WarFoundryCore.INFINITY && equipItem.MinNumber != WarFoundryCore.INFINITY); |
19bdbb80999c
Closes #47 - Remove magic numbers
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
63 numEquipAmount.Enabled = !cbEquipAll.Checked && equipItem.MinNumber != WarFoundryCore.INFINITY; |
0 | 64 numEquipAmount.Width = 144; |
65 } | |
66 | |
67 bttnOkay.Enabled = false; | |
68 } | |
69 | |
70 /// <summary> | |
71 /// Clean up any resources being used. | |
72 /// </summary> | |
73 protected override void Dispose( bool disposing ) | |
74 { | |
75 if( disposing ) | |
76 { | |
77 if(components != null) | |
78 { | |
79 components.Dispose(); | |
80 } | |
81 } | |
82 base.Dispose( disposing ); | |
83 } | |
84 | |
85 #region Windows Form Designer generated code | |
86 /// <summary> | |
87 /// Required method for Designer support - do not modify | |
88 /// the contents of this method with the code editor. | |
89 /// </summary> | |
90 private void InitializeComponent() | |
91 { | |
92 this.numEquipAmount = new System.Windows.Forms.NumericUpDown(); | |
93 this.lblPercent = new System.Windows.Forms.Label(); | |
94 this.lblAmount = new System.Windows.Forms.Label(); | |
95 this.bttnCancel = new System.Windows.Forms.Button(); | |
96 this.bttnOkay = new System.Windows.Forms.Button(); | |
97 this.cbEquipAll = new System.Windows.Forms.CheckBox(); | |
98 ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).BeginInit(); | |
99 this.SuspendLayout(); | |
100 // | |
101 // numEquipAmount | |
102 // | |
103 this.numEquipAmount.Location = new System.Drawing.Point(88, 8); | |
104 this.numEquipAmount.Name = "numEquipAmount"; | |
105 this.numEquipAmount.Size = new System.Drawing.Size(144, 20); | |
106 this.numEquipAmount.TabIndex = 0; | |
107 this.numEquipAmount.ValueChanged += new System.EventHandler(this.numEquipAmount_ValueChanged); | |
108 // | |
109 // lblPercent | |
110 // | |
111 this.lblPercent.Location = new System.Drawing.Point(208, 8); | |
112 this.lblPercent.Name = "lblPercent"; | |
113 this.lblPercent.Size = new System.Drawing.Size(16, 16); | |
114 this.lblPercent.TabIndex = 1; | |
115 this.lblPercent.Text = "%"; | |
116 this.lblPercent.Visible = false; | |
117 // | |
118 // lblAmount | |
119 // | |
120 this.lblAmount.Location = new System.Drawing.Point(8, 8); | |
121 this.lblAmount.Name = "lblAmount"; | |
122 this.lblAmount.Size = new System.Drawing.Size(72, 23); | |
123 this.lblAmount.TabIndex = 2; | |
124 this.lblAmount.Text = "amount"; | |
125 this.lblAmount.TextAlign = System.Drawing.ContentAlignment.TopRight; | |
126 // | |
127 // bttnCancel | |
128 // | |
129 this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; | |
130 this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; | |
131 this.bttnCancel.Location = new System.Drawing.Point(160, 64); | |
132 this.bttnCancel.Name = "bttnCancel"; | |
133 this.bttnCancel.TabIndex = 3; | |
134 this.bttnCancel.Text = "cancel"; | |
135 this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click); | |
136 // | |
137 // bttnOkay | |
138 // | |
139 this.bttnOkay.Enabled = false; | |
140 this.bttnOkay.FlatStyle = System.Windows.Forms.FlatStyle.System; | |
141 this.bttnOkay.Location = new System.Drawing.Point(8, 64); | |
142 this.bttnOkay.Name = "bttnOkay"; | |
143 this.bttnOkay.TabIndex = 4; | |
144 this.bttnOkay.Text = "okay"; | |
145 this.bttnOkay.Click += new System.EventHandler(this.bttnOkay_Click); | |
146 // | |
147 // cbEquipAll | |
148 // | |
149 this.cbEquipAll.Enabled = false; | |
150 this.cbEquipAll.FlatStyle = System.Windows.Forms.FlatStyle.System; | |
151 this.cbEquipAll.Location = new System.Drawing.Point(88, 32); | |
152 this.cbEquipAll.Name = "cbEquipAll"; | |
153 this.cbEquipAll.TabIndex = 5; | |
154 this.cbEquipAll.Text = "equip all"; | |
155 this.cbEquipAll.CheckedChanged += new System.EventHandler(this.cbEquipAll_CheckedChanged); | |
156 // | |
157 // FrmEditUnitEquipment | |
158 // | |
159 this.AcceptButton = this.bttnOkay; | |
160 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); | |
161 this.CancelButton = this.bttnCancel; | |
162 this.ClientSize = new System.Drawing.Size(240, 92); | |
163 this.ControlBox = false; | |
164 this.Controls.Add(this.cbEquipAll); | |
165 this.Controls.Add(this.bttnOkay); | |
166 this.Controls.Add(this.bttnCancel); | |
167 this.Controls.Add(this.lblAmount); | |
168 this.Controls.Add(this.numEquipAmount); | |
169 this.Controls.Add(this.lblPercent); | |
170 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; | |
171 this.Name = "FrmEditUnitEquipment"; | |
172 this.ShowInTaskbar = false; | |
173 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; | |
174 this.Text = "FrmEditUnitEquipment"; | |
175 ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).EndInit(); | |
176 this.ResumeLayout(false); | |
177 | |
178 } | |
179 #endregion | |
180 | |
181 private void bttnOkay_Click(object sender, System.EventArgs e) | |
182 { | |
183 if (setValue()) | |
184 { | |
185 this.Close(); | |
186 } | |
187 } | |
188 | |
189 private bool setValue() | |
8
755e60be28be
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
3
diff
changeset
|
190 { |
10
19bdbb80999c
Closes #47 - Remove magic numbers
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
191 if ((!numEquipAmount.Enabled || numEquipAmount.Value == 0) && !cbEquipAll.Checked && unit.GetEquipmentAmount(equipItem) != 0) |
0 | 192 { |
193 if (equipItem.IsRequired) | |
194 { | |
195 MessageBox.Show(this, "This item is required and cannot be removed. It must have a quantity of at least one or be replaced by an alternative.", "Required item", MessageBoxButtons.OK, MessageBoxIcon.Warning); | |
196 return false; | |
197 } | |
198 else | |
199 { | |
200 DialogResult dr = MessageBox.Show(this, "This will remove the item from the unit. Continue?", "Confirm remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); | |
201 | |
202 if (dr!=DialogResult.Yes) | |
203 { | |
204 return false; | |
205 } | |
206 } | |
207 } | |
208 | |
209 if (cbEquipAll.Checked) | |
210 { | |
10
19bdbb80999c
Closes #47 - Remove magic numbers
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
211 if (equipAmount != WarFoundryCore.INFINITY) |
0 | 212 { |
10
19bdbb80999c
Closes #47 - Remove magic numbers
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
213 commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, WarFoundryCore.INFINITY)); |
0 | 214 } |
215 } | |
216 else if (numEquipAmount.Value != (decimal)equipAmount) | |
217 { | |
10
19bdbb80999c
Closes #47 - Remove magic numbers
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
218 if (equipItem.IsRatioLimit) |
0 | 219 { |
10
19bdbb80999c
Closes #47 - Remove magic numbers
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
220 commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, ((double)numEquipAmount.Value / 100.0))); |
0 | 221 } |
222 else | |
223 { | |
10
19bdbb80999c
Closes #47 - Remove magic numbers
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
224 commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, (double)numEquipAmount.Value)); |
0 | 225 } |
226 } | |
227 | |
228 return true; | |
229 } | |
230 | |
231 private void bttnCancel_Click(object sender, System.EventArgs e) | |
232 { | |
233 this.Close(); | |
234 } | |
235 | |
236 private void cbEquipAll_CheckedChanged(object sender, System.EventArgs e) | |
237 { | |
10
19bdbb80999c
Closes #47 - Remove magic numbers
IBBoard <dev@ibboard.co.uk>
parents:
8
diff
changeset
|
238 numEquipAmount.Enabled = !cbEquipAll.Checked && equipItem.MinNumber != WarFoundryCore.INFINITY; |
0 | 239 setOkayButton(); |
240 } | |
241 | |
242 private void setOkayButton() | |
243 { | |
244 bttnOkay.Enabled = (cbEquipAll.Checked || (numEquipAmount.Enabled && (numEquipAmount.Value > 0 || !equipItem.IsRequired))); | |
245 } | |
246 | |
247 private void numEquipAmount_ValueChanged(object sender, System.EventArgs e) | |
248 { | |
249 setOkayButton(); | |
250 } | |
251 } | |
252 } |