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