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