Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.WinForms
annotate FrmReplaceUnitEquipment.cs @ 9:ffb49ec86df7
Closes #42 - Update translations file to use Schema (WinForms)
* Update WinForms GUI translations to use namespace for schema instead of DTD
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 19 May 2009 11:10:07 +0000 |
parents | 755e60be28be |
children | 19bdbb80999c |
rev | line source |
---|---|
3
8935971e307c
Fixes #1 - Correctly license code
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
1 // This file (FrmReplaceUnitEquipment.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; | |
11 using IBBoard.Commands; | |
12 using IBBoard.WarFoundry.API; | |
13 using IBBoard.WarFoundry.API.Commands; | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
14 using IBBoard.WarFoundry.API.Objects; |
0 | 15 |
16 namespace IBBoard.WarFoundry | |
17 { | |
18 /// <summary> | |
19 /// Summary description for FrmNewUnitEquipment. | |
20 /// </summary> | |
21 public class FrmReplaceUnitEquipment : System.Windows.Forms.Form | |
22 { | |
23 private Unit unit; | |
8
755e60be28be
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
3
diff
changeset
|
24 private UnitEquipmentItem oldItem; |
0 | 25 private bool required; |
26 private CommandStack commandStack; | |
27 | |
28 private System.Windows.Forms.NumericUpDown numEquipAmount; | |
29 private System.Windows.Forms.Label lblPercent; | |
30 private System.Windows.Forms.Label lblAmount; | |
31 private System.Windows.Forms.Button bttnCancel; | |
32 private System.Windows.Forms.Button bttnOkay; | |
33 private System.Windows.Forms.CheckBox cbEquipAll; | |
34 private System.Windows.Forms.Label lblItem; | |
35 private System.Windows.Forms.ListBox listItems; | |
36 /// <summary> | |
37 /// Required designer variable. | |
38 /// </summary> | |
39 private System.ComponentModel.Container components = null; | |
40 | |
41 public FrmReplaceUnitEquipment(Unit unit, UnitEquipmentItem item, CommandStack stack) | |
42 { | |
43 commandStack = stack; | |
44 this.unit = unit; | |
8
755e60be28be
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
3
diff
changeset
|
45 oldItem = item; |
0 | 46 InitializeComponent(); |
47 this.Text = "Replace " + item.EquipmentItem.Name + " with new equipment"; | |
48 object[] items = Arrays.Subtract(unit.UnitType.GetEquipmentItemsByExclusionGroup(item.MutexGroup), unit.GetEquipment()); | |
49 listItems.Items.AddRange(items); | |
50 } | |
51 | |
52 /// <summary> | |
53 /// Clean up any resources being used. | |
54 /// </summary> | |
55 protected override void Dispose( bool disposing ) | |
56 { | |
57 if( disposing ) | |
58 { | |
59 if(components != null) | |
60 { | |
61 components.Dispose(); | |
62 } | |
63 } | |
64 base.Dispose( disposing ); | |
65 } | |
66 | |
67 #region Windows Form Designer generated code | |
68 /// <summary> | |
69 /// Required method for Designer support - do not modify | |
70 /// the contents of this method with the code editor. | |
71 /// </summary> | |
72 private void InitializeComponent() | |
73 { | |
74 this.numEquipAmount = new System.Windows.Forms.NumericUpDown(); | |
75 this.lblPercent = new System.Windows.Forms.Label(); | |
76 this.lblAmount = new System.Windows.Forms.Label(); | |
77 this.bttnCancel = new System.Windows.Forms.Button(); | |
78 this.bttnOkay = new System.Windows.Forms.Button(); | |
79 this.cbEquipAll = new System.Windows.Forms.CheckBox(); | |
80 this.lblItem = new System.Windows.Forms.Label(); | |
81 this.listItems = new System.Windows.Forms.ListBox(); | |
82 ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).BeginInit(); | |
83 this.SuspendLayout(); | |
84 // | |
85 // numEquipAmount | |
86 // | |
87 this.numEquipAmount.Enabled = false; | |
88 this.numEquipAmount.Location = new System.Drawing.Point(88, 80); | |
89 this.numEquipAmount.Name = "numEquipAmount"; | |
90 this.numEquipAmount.Size = new System.Drawing.Size(144, 20); | |
91 this.numEquipAmount.TabIndex = 0; | |
92 this.numEquipAmount.ValueChanged += new System.EventHandler(this.numEquipAmount_ValueChanged); | |
93 // | |
94 // lblPercent | |
95 // | |
96 this.lblPercent.Location = new System.Drawing.Point(208, 80); | |
97 this.lblPercent.Name = "lblPercent"; | |
98 this.lblPercent.Size = new System.Drawing.Size(16, 16); | |
99 this.lblPercent.TabIndex = 1; | |
100 this.lblPercent.Text = "%"; | |
101 this.lblPercent.Visible = false; | |
102 // | |
103 // lblAmount | |
104 // | |
105 this.lblAmount.Location = new System.Drawing.Point(8, 80); | |
106 this.lblAmount.Name = "lblAmount"; | |
107 this.lblAmount.Size = new System.Drawing.Size(72, 23); | |
108 this.lblAmount.TabIndex = 2; | |
109 this.lblAmount.Text = "amount"; | |
110 this.lblAmount.TextAlign = System.Drawing.ContentAlignment.TopRight; | |
111 // | |
112 // bttnCancel | |
113 // | |
114 this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; | |
115 this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; | |
116 this.bttnCancel.Location = new System.Drawing.Point(160, 136); | |
117 this.bttnCancel.Name = "bttnCancel"; | |
118 this.bttnCancel.TabIndex = 3; | |
119 this.bttnCancel.Text = "cancel"; | |
120 this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click); | |
121 // | |
122 // bttnOkay | |
123 // | |
124 this.bttnOkay.Enabled = false; | |
125 this.bttnOkay.FlatStyle = System.Windows.Forms.FlatStyle.System; | |
126 this.bttnOkay.Location = new System.Drawing.Point(8, 136); | |
127 this.bttnOkay.Name = "bttnOkay"; | |
128 this.bttnOkay.TabIndex = 4; | |
129 this.bttnOkay.Text = "okay"; | |
130 this.bttnOkay.Click += new System.EventHandler(this.bttnOkay_Click); | |
131 // | |
132 // cbEquipAll | |
133 // | |
134 this.cbEquipAll.Enabled = false; | |
135 this.cbEquipAll.FlatStyle = System.Windows.Forms.FlatStyle.System; | |
136 this.cbEquipAll.Location = new System.Drawing.Point(88, 104); | |
137 this.cbEquipAll.Name = "cbEquipAll"; | |
138 this.cbEquipAll.TabIndex = 5; | |
139 this.cbEquipAll.Text = "equip all"; | |
140 this.cbEquipAll.CheckedChanged += new System.EventHandler(this.cbEquipAll_CheckedChanged); | |
141 // | |
142 // lblItem | |
143 // | |
144 this.lblItem.Location = new System.Drawing.Point(0, 8); | |
145 this.lblItem.Name = "lblItem"; | |
146 this.lblItem.Size = new System.Drawing.Size(80, 23); | |
147 this.lblItem.TabIndex = 6; | |
148 this.lblItem.Text = "item"; | |
149 this.lblItem.TextAlign = System.Drawing.ContentAlignment.TopRight; | |
150 // | |
151 // listItems | |
152 // | |
153 this.listItems.Location = new System.Drawing.Point(88, 8); | |
154 this.listItems.Name = "listItems"; | |
155 this.listItems.Size = new System.Drawing.Size(144, 69); | |
156 this.listItems.TabIndex = 7; | |
157 this.listItems.SelectedIndexChanged += new System.EventHandler(this.listItems_SelectedIndexChanged); | |
158 // | |
159 // FrmReplaceUnitEquipment | |
160 // | |
161 this.AcceptButton = this.bttnOkay; | |
162 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); | |
163 this.CancelButton = this.bttnCancel; | |
164 this.ClientSize = new System.Drawing.Size(240, 164); | |
165 this.ControlBox = false; | |
166 this.Controls.Add(this.listItems); | |
167 this.Controls.Add(this.lblItem); | |
168 this.Controls.Add(this.cbEquipAll); | |
169 this.Controls.Add(this.bttnOkay); | |
170 this.Controls.Add(this.bttnCancel); | |
171 this.Controls.Add(this.lblAmount); | |
172 this.Controls.Add(this.numEquipAmount); | |
173 this.Controls.Add(this.lblPercent); | |
174 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; | |
175 this.Name = "FrmReplaceUnitEquipment"; | |
176 this.ShowInTaskbar = false; | |
177 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; | |
178 this.Text = "FrmEditUnitEquipment"; | |
179 ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).EndInit(); | |
180 this.ResumeLayout(false); | |
181 | |
182 } | |
183 #endregion | |
184 | |
185 private void bttnOkay_Click(object sender, System.EventArgs e) | |
186 { | |
187 setValue(); | |
188 this.Close(); | |
189 } | |
190 | |
191 private void setValue() | |
192 { | |
193 UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem; | |
194 | |
195 if (cbEquipAll.Checked) | |
196 { | |
8
755e60be28be
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
3
diff
changeset
|
197 commandStack.Execute(new ReplaceUnitEquipmentCommand(unit, oldItem, equipItem, -1)); |
0 | 198 } |
199 else | |
200 { | |
8
755e60be28be
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
3
diff
changeset
|
201 if (equipItem.IsRatioLimit) |
0 | 202 { |
8
755e60be28be
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
3
diff
changeset
|
203 commandStack.Execute(new ReplaceUnitEquipmentCommand(unit, oldItem, equipItem, (double)numEquipAmount.Value / 100.0)); |
0 | 204 } |
205 else | |
206 { | |
8
755e60be28be
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
3
diff
changeset
|
207 commandStack.Execute(new ReplaceUnitEquipmentCommand(unit, oldItem, equipItem, (double)numEquipAmount.Value)); |
0 | 208 } |
209 } | |
210 } | |
211 | |
212 private void bttnCancel_Click(object sender, System.EventArgs e) | |
213 { | |
214 this.Close(); | |
215 } | |
216 | |
217 private void cbEquipAll_CheckedChanged(object sender, System.EventArgs e) | |
218 { | |
8
755e60be28be
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
3
diff
changeset
|
219 numEquipAmount.Enabled = ((UnitEquipmentItem)listItems.SelectedItem).MinNumber != WarFoundryCore.INFINITY && !cbEquipAll.Checked; |
0 | 220 setOkayButton(); |
221 } | |
222 | |
223 private void listItems_SelectedIndexChanged(object sender, System.EventArgs e) | |
224 { | |
225 refreshNumber(); | |
226 setOkayButton(); | |
227 } | |
228 | |
229 private void refreshNumber() | |
230 { | |
231 if (listItems.SelectedIndex > -1) | |
232 { | |
233 UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem; | |
234 required = equipItem.IsRequired; | |
235 | |
8
755e60be28be
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
3
diff
changeset
|
236 if (equipItem.IsRatioLimit) |
0 | 237 { |
8
755e60be28be
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
3
diff
changeset
|
238 numEquipAmount.Minimum = (decimal)Math.Round(equipItem.MinNumber * 100.0, 2); |
755e60be28be
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
3
diff
changeset
|
239 numEquipAmount.Maximum = (decimal)Math.Round(equipItem.MaxNumber * 100.0, 2); |
0 | 240 numEquipAmount.Value = numEquipAmount.Minimum; |
241 cbEquipAll.Enabled = false; | |
242 lblPercent.Visible = true; | |
243 numEquipAmount.Width = 120; | |
244 } | |
245 else | |
246 { | |
8
755e60be28be
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
3
diff
changeset
|
247 numEquipAmount.Minimum = (decimal)(equipItem.MinNumber != -1 ? equipItem.MinNumber : unit.Size); |
755e60be28be
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
3
diff
changeset
|
248 numEquipAmount.Maximum = (decimal)(equipItem.MaxNumber != -1 ? equipItem.MaxNumber : unit.Size); |
0 | 249 numEquipAmount.Value = numEquipAmount.Minimum; |
8
755e60be28be
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
3
diff
changeset
|
250 cbEquipAll.Enabled = (equipItem.MaxNumber == -1 && equipItem.MinNumber != -1); |
755e60be28be
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
3
diff
changeset
|
251 cbEquipAll.Checked = equipItem.MinNumber == -1; |
0 | 252 numEquipAmount.Width = 144; |
253 } | |
254 } | |
255 else | |
256 { | |
257 numEquipAmount.Minimum = 0; | |
258 numEquipAmount.Value = 0; | |
259 numEquipAmount.Enabled = false; | |
260 cbEquipAll.Enabled = false; | |
261 } | |
262 } | |
263 | |
264 private void setOkayButton() | |
265 { | |
266 bttnOkay.Enabled = listItems.SelectedIndex > -1 && (cbEquipAll.Checked || (numEquipAmount.Enabled && numEquipAmount.Value > 0)); | |
267 } | |
268 | |
269 private void numEquipAmount_ValueChanged(object sender, System.EventArgs e) | |
270 { | |
271 setOkayButton(); | |
272 } | |
273 } | |
274 } |