comparison FrmEditUnitEquipment.cs @ 8:755e60be28be

Re #61 - Complete structure of WarFoundry API objects * Update to using UnitEquipmentItem where properties have moved from EquipmentItem * Add UnitEquipmentChoice as replacement for UnitEquipmentItemObj
author IBBoard <dev@ibboard.co.uk>
date Sun, 05 Apr 2009 13:50:41 +0000
parents 8935971e307c
children 19bdbb80999c
comparison
equal deleted inserted replaced
7:9828ba4f3f36 8:755e60be28be
19 /// </summary> 19 /// </summary>
20 public class FrmEditUnitEquipment : System.Windows.Forms.Form 20 public class FrmEditUnitEquipment : System.Windows.Forms.Form
21 { 21 {
22 private Unit unit; 22 private Unit unit;
23 private UnitEquipmentItem equipItem; 23 private UnitEquipmentItem equipItem;
24 private EquipmentItem equip; 24 private double equipAmount;
25 private float equipAmount;
26 private CommandStack commandStack; 25 private CommandStack commandStack;
27 26
28 private System.Windows.Forms.NumericUpDown numEquipAmount; 27 private System.Windows.Forms.NumericUpDown numEquipAmount;
29 private System.Windows.Forms.Label lblPercent; 28 private System.Windows.Forms.Label lblPercent;
30 private System.Windows.Forms.Label lblAmount; 29 private System.Windows.Forms.Label lblAmount;
39 public FrmEditUnitEquipment(Unit unit, UnitEquipmentItem equipItem, CommandStack stack) 38 public FrmEditUnitEquipment(Unit unit, UnitEquipmentItem equipItem, CommandStack stack)
40 { 39 {
41 commandStack = stack; 40 commandStack = stack;
42 this.unit = unit; 41 this.unit = unit;
43 this.equipItem = equipItem; 42 this.equipItem = equipItem;
44 equip = equipItem.EquipmentItem;
45 InitializeComponent(); 43 InitializeComponent();
46 this.Text = equip.Name + " for " + unit.Name; 44 this.Text = equipItem.Name + " for " + unit.Name;
47 equipAmount = unit.GetEquipmentAmount(equip.ID); 45 equipAmount = unit.GetEquipmentAmount(equipItem);
48 46
49 if (equip.IsRatioLimit) 47 if (equipItem.IsRatioLimit)
50 { 48 {
51 numEquipAmount.Minimum = (decimal)Math.Round(equip.MinNumber * 100, 2); 49 numEquipAmount.Minimum = (decimal)Math.Round(equipItem.MinNumber * 100.0, 2);
52 numEquipAmount.Maximum = (decimal)Math.Round(equip.MaxNumber * 100, 2); 50 numEquipAmount.Maximum = (decimal)Math.Round(equipItem.MaxNumber * 100.0, 2);
53 numEquipAmount.Value = (decimal)Math.Round(equipAmount * 100, 2); 51 numEquipAmount.Value = (decimal)Math.Round(equipAmount * 100, 2);
54 cbEquipAll.Enabled = false; 52 cbEquipAll.Enabled = false;
55 lblPercent.Visible = true; 53 lblPercent.Visible = true;
56 numEquipAmount.Width = 120; 54 numEquipAmount.Width = 120;
57 } 55 }
58 else 56 else
59 { 57 {
60 numEquipAmount.Minimum = (decimal)(equip.MinNumber != -1 ? equip.MinNumber : unit.Size); 58 numEquipAmount.Minimum = (decimal)(equipItem.MinNumber != -1 ? equipItem.MinNumber : unit.Size);
61 numEquipAmount.Maximum = (decimal)(equip.MaxNumber != -1 ? equip.MaxNumber : unit.Size); 59 numEquipAmount.Maximum = (decimal)(equipItem.MaxNumber != -1 ? equipItem.MaxNumber : unit.Size);
62 numEquipAmount.Value = (decimal)(equipAmount == -1 ? unit.Size : equipAmount); 60 numEquipAmount.Value = (decimal)(equipAmount == -1 ? unit.Size : equipAmount);
63 cbEquipAll.Checked = (equipAmount == -1); 61 cbEquipAll.Checked = (equipAmount == -1);
64 cbEquipAll.Enabled = (equip.MaxNumber == -1 && equip.MinNumber != -1); 62 cbEquipAll.Enabled = (equipItem.MaxNumber == -1 && equipItem.MinNumber != -1);
65 numEquipAmount.Enabled = !cbEquipAll.Checked && equip.MinNumber != -1; 63 numEquipAmount.Enabled = !cbEquipAll.Checked && equipItem.MinNumber != -1;
66 numEquipAmount.Width = 144; 64 numEquipAmount.Width = 144;
67 } 65 }
68 66
69 bttnOkay.Enabled = false; 67 bttnOkay.Enabled = false;
70 } 68 }
187 this.Close(); 185 this.Close();
188 } 186 }
189 } 187 }
190 188
191 private bool setValue() 189 private bool setValue()
192 { 190 {
193 if ((!numEquipAmount.Enabled || numEquipAmount.Value == 0) && !cbEquipAll.Checked && unit.GetEquipmentAmount(equip.ID) != 0) 191 if ((!numEquipAmount.Enabled || numEquipAmount.Value == 0) && !cbEquipAll.Checked && unit.GetEquipmentAmount(equipItem) != 0)
194 { 192 {
195 if (equipItem.IsRequired) 193 if (equipItem.IsRequired)
196 { 194 {
197 MessageBox.Show(this, "This item is required and cannot be removed. It must have a quantity of at least one or be replaced by an alternative.", "Required item", MessageBoxButtons.OK, MessageBoxIcon.Warning); 195 MessageBox.Show(this, "This item is required and cannot be removed. It must have a quantity of at least one or be replaced by an alternative.", "Required item", MessageBoxButtons.OK, MessageBoxIcon.Warning);
198 return false; 196 return false;
210 208
211 if (cbEquipAll.Checked) 209 if (cbEquipAll.Checked)
212 { 210 {
213 if (equipAmount!=-1) 211 if (equipAmount!=-1)
214 { 212 {
215 commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equip, -1)); 213 commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, -1));
216 } 214 }
217 } 215 }
218 else if (numEquipAmount.Value != (decimal)equipAmount) 216 else if (numEquipAmount.Value != (decimal)equipAmount)
219 { 217 {
220 if (equip.IsRatioLimit) 218 if (equipItem.IsRatioLimit)
221 { 219 {
222 commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equip, (float)((double)numEquipAmount.Value / 100.0))); 220 commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, ((double)numEquipAmount.Value / 100.0)));
223 } 221 }
224 else 222 else
225 { 223 {
226 commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equip, (float)numEquipAmount.Value)); 224 commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, (double)numEquipAmount.Value));
227 } 225 }
228 } 226 }
229 227
230 return true; 228 return true;
231 } 229 }
235 this.Close(); 233 this.Close();
236 } 234 }
237 235
238 private void cbEquipAll_CheckedChanged(object sender, System.EventArgs e) 236 private void cbEquipAll_CheckedChanged(object sender, System.EventArgs e)
239 { 237 {
240 numEquipAmount.Enabled = !cbEquipAll.Checked && equip.MinNumber != -1; 238 numEquipAmount.Enabled = !cbEquipAll.Checked && equipItem.MinNumber != -1;
241 setOkayButton(); 239 setOkayButton();
242 } 240 }
243 241
244 private void setOkayButton() 242 private void setOkayButton()
245 { 243 {