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