comparison FrmNewUnitEquipment.cs @ 40:740350673006

Re #117: Add percentage and number boxes to equipment item dialogs * Add a new EquipmentAmountControl to bundle the controls with some initial implementation * Add new control to "new equipment" dialog and remove old controls Also: * Update some namespaces
author IBBoard <dev@ibboard.co.uk>
date Sun, 06 Sep 2009 18:01:54 +0000
parents 6ab7ddc038f9
children 4fc87d6e6119
comparison
equal deleted inserted replaced
39:25dfeb1db285 40:740350673006
11 using IBBoard.Commands; 11 using IBBoard.Commands;
12 using IBBoard.Lang; 12 using IBBoard.Lang;
13 using IBBoard.WarFoundry.API; 13 using IBBoard.WarFoundry.API;
14 using IBBoard.WarFoundry.API.Commands; 14 using IBBoard.WarFoundry.API.Commands;
15 using IBBoard.WarFoundry.API.Objects; 15 using IBBoard.WarFoundry.API.Objects;
16 16 using IBBoard.WarFoundry.GUI.WinForms.Util;
17 namespace IBBoard.WarFoundry 17
18 namespace IBBoard.WarFoundry.GUI.WinForms
18 { 19 {
19 /// <summary> 20 /// <summary>
20 /// Summary description for FrmNewUnitEquipment. 21 /// Summary description for FrmNewUnitEquipment.
21 /// </summary> 22 /// </summary>
22 public class FrmNewUnitEquipment : System.Windows.Forms.Form 23 public class FrmNewUnitEquipment : System.Windows.Forms.Form
23 { 24 {
24 private Unit unit; 25 private Unit unit;
25 private bool required;
26 private CommandStack commandStack; 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; 27 private System.Windows.Forms.Label lblAmount;
31 private System.Windows.Forms.Button bttnCancel; 28 private System.Windows.Forms.Button bttnCancel;
32 private System.Windows.Forms.Button bttnOkay; 29 private System.Windows.Forms.Button bttnOkay;
33 private System.Windows.Forms.CheckBox cbEquipAll;
34 private System.Windows.Forms.Label lblItem; 30 private System.Windows.Forms.Label lblItem;
35 private System.Windows.Forms.ListBox listItems; 31 private System.Windows.Forms.ListBox listItems;
32 private IBBoard.WarFoundry.GUI.WinForms.UI.EquipmentAmountControl equipmentAmount;
36 /// <summary> 33 /// <summary>
37 /// Required designer variable. 34 /// Required designer variable.
38 /// </summary> 35 /// </summary>
39 private System.ComponentModel.Container components = null; 36 private System.ComponentModel.Container components = null;
40 37
68 /// Required method for Designer support - do not modify 65 /// Required method for Designer support - do not modify
69 /// the contents of this method with the code editor. 66 /// the contents of this method with the code editor.
70 /// </summary> 67 /// </summary>
71 private void InitializeComponent() 68 private void InitializeComponent()
72 { 69 {
73 this.numEquipAmount = new System.Windows.Forms.NumericUpDown();
74 this.lblPercent = new System.Windows.Forms.Label();
75 this.lblAmount = new System.Windows.Forms.Label(); 70 this.lblAmount = new System.Windows.Forms.Label();
76 this.bttnCancel = new System.Windows.Forms.Button(); 71 this.bttnCancel = new System.Windows.Forms.Button();
77 this.bttnOkay = new System.Windows.Forms.Button(); 72 this.bttnOkay = new System.Windows.Forms.Button();
78 this.cbEquipAll = new System.Windows.Forms.CheckBox();
79 this.lblItem = new System.Windows.Forms.Label(); 73 this.lblItem = new System.Windows.Forms.Label();
80 this.listItems = new System.Windows.Forms.ListBox(); 74 this.listItems = new System.Windows.Forms.ListBox();
81 ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).BeginInit(); 75 this.equipmentAmount = new IBBoard.WarFoundry.GUI.WinForms.UI.EquipmentAmountControl();
82 this.SuspendLayout(); 76 this.SuspendLayout();
83 //
84 // numEquipAmount
85 //
86 this.numEquipAmount.Enabled = false;
87 this.numEquipAmount.Location = new System.Drawing.Point(88, 80);
88 this.numEquipAmount.Name = "numEquipAmount";
89 this.numEquipAmount.Size = new System.Drawing.Size(144, 20);
90 this.numEquipAmount.TabIndex = 0;
91 this.numEquipAmount.ValueChanged += new System.EventHandler(this.numEquipAmount_ValueChanged);
92 //
93 // lblPercent
94 //
95 this.lblPercent.Location = new System.Drawing.Point(208, 80);
96 this.lblPercent.Name = "lblPercent";
97 this.lblPercent.Size = new System.Drawing.Size(16, 16);
98 this.lblPercent.TabIndex = 1;
99 this.lblPercent.Text = "%";
100 this.lblPercent.Visible = false;
101 // 77 //
102 // lblAmount 78 // lblAmount
103 // 79 //
104 this.lblAmount.Location = new System.Drawing.Point(8, 80); 80 this.lblAmount.Location = new System.Drawing.Point(8, 80);
105 this.lblAmount.Name = "lblAmount"; 81 this.lblAmount.Name = "lblAmount";
110 // 86 //
111 // bttnCancel 87 // bttnCancel
112 // 88 //
113 this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; 89 this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
114 this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; 90 this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
115 this.bttnCancel.Location = new System.Drawing.Point(160, 136); 91 this.bttnCancel.Location = new System.Drawing.Point(158, 162);
116 this.bttnCancel.Name = "bttnCancel"; 92 this.bttnCancel.Name = "bttnCancel";
93 this.bttnCancel.Size = new System.Drawing.Size(75, 23);
117 this.bttnCancel.TabIndex = 3; 94 this.bttnCancel.TabIndex = 3;
118 this.bttnCancel.Text = "cancel"; 95 this.bttnCancel.Text = "cancel";
119 this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click); 96 this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click);
120 // 97 //
121 // bttnOkay 98 // bttnOkay
122 // 99 //
123 this.bttnOkay.Enabled = false; 100 this.bttnOkay.Enabled = false;
124 this.bttnOkay.FlatStyle = System.Windows.Forms.FlatStyle.System; 101 this.bttnOkay.FlatStyle = System.Windows.Forms.FlatStyle.System;
125 this.bttnOkay.Location = new System.Drawing.Point(8, 136); 102 this.bttnOkay.Location = new System.Drawing.Point(12, 162);
126 this.bttnOkay.Name = "bttnOkay"; 103 this.bttnOkay.Name = "bttnOkay";
104 this.bttnOkay.Size = new System.Drawing.Size(75, 23);
127 this.bttnOkay.TabIndex = 4; 105 this.bttnOkay.TabIndex = 4;
128 this.bttnOkay.Text = "okay"; 106 this.bttnOkay.Text = "okay";
129 this.bttnOkay.Click += new System.EventHandler(this.bttnOkay_Click); 107 this.bttnOkay.Click += new System.EventHandler(this.bttnOkay_Click);
130 //
131 // cbEquipAll
132 //
133 this.cbEquipAll.Enabled = false;
134 this.cbEquipAll.FlatStyle = System.Windows.Forms.FlatStyle.System;
135 this.cbEquipAll.Location = new System.Drawing.Point(88, 104);
136 this.cbEquipAll.Name = "cbEquipAll";
137 this.cbEquipAll.TabIndex = 5;
138 this.cbEquipAll.Text = "equip all";
139 this.cbEquipAll.CheckedChanged += new System.EventHandler(this.cbEquipAll_CheckedChanged);
140 // 108 //
141 // lblItem 109 // lblItem
142 // 110 //
143 this.lblItem.Location = new System.Drawing.Point(0, 8); 111 this.lblItem.Location = new System.Drawing.Point(0, 8);
144 this.lblItem.Name = "lblItem"; 112 this.lblItem.Name = "lblItem";
149 // 117 //
150 // listItems 118 // listItems
151 // 119 //
152 this.listItems.Location = new System.Drawing.Point(88, 8); 120 this.listItems.Location = new System.Drawing.Point(88, 8);
153 this.listItems.Name = "listItems"; 121 this.listItems.Name = "listItems";
154 this.listItems.Size = new System.Drawing.Size(144, 69); 122 this.listItems.Size = new System.Drawing.Size(145, 69);
155 this.listItems.TabIndex = 7; 123 this.listItems.TabIndex = 7;
156 this.listItems.SelectedIndexChanged += new System.EventHandler(this.listItems_SelectedIndexChanged); 124 this.listItems.SelectedIndexChanged += new System.EventHandler(this.listItems_SelectedIndexChanged);
125 //
126 // equipmentAmount
127 //
128 this.equipmentAmount.Location = new System.Drawing.Point(88, 80);
129 this.equipmentAmount.Name = "equipmentAmount";
130 this.equipmentAmount.Size = new System.Drawing.Size(155, 77);
131 this.equipmentAmount.TabIndex = 8;
157 // 132 //
158 // FrmNewUnitEquipment 133 // FrmNewUnitEquipment
159 // 134 //
160 this.AcceptButton = this.bttnOkay; 135 this.AcceptButton = this.bttnOkay;
161 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); 136 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
162 this.CancelButton = this.bttnCancel; 137 this.CancelButton = this.bttnCancel;
163 this.ClientSize = new System.Drawing.Size(240, 164); 138 this.ClientSize = new System.Drawing.Size(245, 190);
164 this.ControlBox = false; 139 this.ControlBox = false;
140 this.Controls.Add(this.equipmentAmount);
165 this.Controls.Add(this.listItems); 141 this.Controls.Add(this.listItems);
166 this.Controls.Add(this.lblItem); 142 this.Controls.Add(this.lblItem);
167 this.Controls.Add(this.cbEquipAll);
168 this.Controls.Add(this.bttnOkay); 143 this.Controls.Add(this.bttnOkay);
169 this.Controls.Add(this.bttnCancel); 144 this.Controls.Add(this.bttnCancel);
170 this.Controls.Add(this.lblAmount); 145 this.Controls.Add(this.lblAmount);
171 this.Controls.Add(this.numEquipAmount);
172 this.Controls.Add(this.lblPercent);
173 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; 146 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
174 this.Name = "FrmNewUnitEquipment"; 147 this.Name = "FrmNewUnitEquipment";
175 this.ShowInTaskbar = false; 148 this.ShowInTaskbar = false;
176 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; 149 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
177 this.Text = "FrmEditUnitEquipment"; 150 this.Text = "FrmEditUnitEquipment";
178 ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).EndInit();
179 this.ResumeLayout(false); 151 this.ResumeLayout(false);
180 152
181 } 153 }
182 #endregion 154 #endregion
183 155
184 private void bttnOkay_Click(object sender, System.EventArgs e) 156 private void bttnOkay_Click(object sender, System.EventArgs e)
185 { 157 {
186 setValue(); 158 SetValue();
187 this.Close(); 159 this.Close();
188 } 160 }
189 161
190 private void setValue() 162 private void SetValue()
191 { 163 {
192 UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem; 164 UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem;
193 165
194 if (cbEquipAll.Checked) 166 if (equipmentAmount.IsRatioEquipmentAmount)
195 { 167 {
196 commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, WarFoundryCore.INFINITY)); 168 commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, equipmentAmount.EquipmentAmount));
197 } 169 }
198 else 170 else
199 { 171 {
200 if (equipItem.IsRatioLimit) 172 //Just cast here - we should be returned a whole number anyway
201 { 173 commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int) equipmentAmount.EquipmentAmount));
202 commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, (double)numEquipAmount.Value / 100.0));
203 }
204 else
205 {
206 commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int)numEquipAmount.Value));
207 }
208 } 174 }
209 } 175 }
210 176
211 private void bttnCancel_Click(object sender, System.EventArgs e) 177 private void bttnCancel_Click(object sender, System.EventArgs e)
212 { 178 {
213 this.Close(); 179 this.Close();
214 } 180 }
215 181
216 private void cbEquipAll_CheckedChanged(object sender, System.EventArgs e) 182 private void cbEquipAll_CheckedChanged(object sender, System.EventArgs e)
217 { 183 {
218 numEquipAmount.Enabled = ((UnitEquipmentItem)listItems.SelectedItem).MinNumber != WarFoundryCore.INFINITY && !cbEquipAll.Checked; 184 //numEquipAmount.Enabled = ((UnitEquipmentItem) listItems.SelectedItem).MinNumber != WarFoundryCore.INFINITY && !rbEquipAll.Checked;
219 setOkayButton(); 185 setOkayButton();
220 } 186 }
221 187
222 private void listItems_SelectedIndexChanged(object sender, System.EventArgs e) 188 private void listItems_SelectedIndexChanged(object sender, System.EventArgs e)
223 { 189 {
225 setOkayButton(); 191 setOkayButton();
226 } 192 }
227 193
228 private void refreshNumber() 194 private void refreshNumber()
229 { 195 {
196 /*
230 if (listItems.SelectedIndex > -1) 197 if (listItems.SelectedIndex > -1)
231 { 198 {
232 UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem; 199 UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem;
233 required = equipItem.IsRequired; 200 required = equipItem.IsRequired;
234 201
236 { 203 {
237 numEquipAmount.Minimum = (decimal) equipItem.MinPercentage; 204 numEquipAmount.Minimum = (decimal) equipItem.MinPercentage;
238 numEquipAmount.Maximum = (decimal) equipItem.MaxPercentage; 205 numEquipAmount.Maximum = (decimal) equipItem.MaxPercentage;
239 numEquipAmount.Enabled = true; 206 numEquipAmount.Enabled = true;
240 numEquipAmount.Value = numEquipAmount.Minimum; 207 numEquipAmount.Value = numEquipAmount.Minimum;
241 cbEquipAll.Enabled = false; 208 rbEquipAll.Enabled = false;
242 lblPercent.Visible = true; 209 lblPercent.Visible = true;
243 numEquipAmount.Width = 120; 210 numEquipAmount.Width = 120;
244 } 211 }
245 else 212 else
246 { 213 {
247 numEquipAmount.Minimum = (decimal)(equipItem.MinNumber != WarFoundryCore.INFINITY ? Math.Min(equipItem.MinNumber, unit.Size) : unit.Size); 214 numEquipAmount.Minimum = (decimal)(equipItem.MinNumber != WarFoundryCore.INFINITY ? Math.Min(equipItem.MinNumber, unit.Size) : unit.Size);
248 numEquipAmount.Maximum = (decimal)(equipItem.MaxNumber != WarFoundryCore.INFINITY ? Math.Min(equipItem.MaxNumber, unit.Size) : unit.Size); 215 numEquipAmount.Maximum = (decimal)(equipItem.MaxNumber != WarFoundryCore.INFINITY ? Math.Min(equipItem.MaxNumber, unit.Size) : unit.Size);
249 numEquipAmount.Value = numEquipAmount.Minimum; 216 numEquipAmount.Value = numEquipAmount.Minimum;
250 numEquipAmount.Enabled = equipItem.MinNumber != WarFoundryCore.INFINITY; 217 numEquipAmount.Enabled = equipItem.MinNumber != WarFoundryCore.INFINITY;
251 cbEquipAll.Enabled = equipItem.MinNumber != WarFoundryCore.INFINITY && equipItem.MaxNumber == WarFoundryCore.INFINITY; 218 rbEquipAll.Enabled = equipItem.MinNumber != WarFoundryCore.INFINITY && equipItem.MaxNumber == WarFoundryCore.INFINITY;
252 cbEquipAll.Checked = equipItem.MinNumber == WarFoundryCore.INFINITY; 219 rbEquipAll.Checked = equipItem.MinNumber == WarFoundryCore.INFINITY;
253 lblPercent.Visible = false; 220 lblPercent.Visible = false;
254 numEquipAmount.Width = 144; 221 numEquipAmount.Width = 144;
255 } 222 }
256 } 223 }
257 else 224 else
258 { 225 {
259 numEquipAmount.Minimum = 0; 226 numEquipAmount.Minimum = 0;
260 numEquipAmount.Value = 0; 227 numEquipAmount.Value = 0;
261 numEquipAmount.Enabled = false; 228 numEquipAmount.Enabled = false;
262 cbEquipAll.Enabled = false; 229 rbEquipAll.Enabled = false;
263 } 230 }*/
264 } 231 }
265 232
266 private void setOkayButton() 233 private void setOkayButton()
267 { 234 {
268 bttnOkay.Enabled = listItems.SelectedIndex > -1 && (cbEquipAll.Checked || (numEquipAmount.Enabled && numEquipAmount.Value > 0)); 235 bttnOkay.Enabled = listItems.SelectedIndex > -1;// && (rbEquipAll.Checked || (numEquipAmount.Enabled && numEquipAmount.Value > 0));
269 } 236 }
270 237
271 private void numEquipAmount_ValueChanged(object sender, System.EventArgs e) 238 private void numEquipAmount_ValueChanged(object sender, System.EventArgs e)
272 { 239 {
273 setOkayButton(); 240 setOkayButton();