diff FrmReplaceUnitEquipment.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
line wrap: on
line diff
--- a/FrmReplaceUnitEquipment.cs	Sat Mar 07 21:08:31 2009 +0000
+++ b/FrmReplaceUnitEquipment.cs	Sun Apr 05 13:50:41 2009 +0000
@@ -21,7 +21,7 @@
 	public class FrmReplaceUnitEquipment : System.Windows.Forms.Form
 	{
 		private Unit unit;
-		private EquipmentItem oldItem;
+		private UnitEquipmentItem oldItem;
 		private bool required;
 		private CommandStack commandStack;
 
@@ -42,7 +42,7 @@
 		{
 			commandStack = stack;
 			this.unit = unit;
-			oldItem = item.EquipmentItem;
+			oldItem = item;
 			InitializeComponent();
 			this.Text = "Replace " + item.EquipmentItem.Name + " with new equipment";
 			object[] items = Arrays.Subtract(unit.UnitType.GetEquipmentItemsByExclusionGroup(item.MutexGroup), unit.GetEquipment());
@@ -191,21 +191,20 @@
 		private void setValue()
 		{
 			UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem;
-			EquipmentItem equip = equipItem.EquipmentItem;
 
 			if (cbEquipAll.Checked)
 			{
-				commandStack.Execute(new ReplaceUnitEquipmentCommand(unit, oldItem, equip, -1));
+                commandStack.Execute(new ReplaceUnitEquipmentCommand(unit, oldItem, equipItem, -1));
 			}
 			else
 			{
-				if (equip.IsRatioLimit)
+                if (equipItem.IsRatioLimit)
 				{
-					commandStack.Execute(new ReplaceUnitEquipmentCommand(unit, oldItem, equip, (float)((double)numEquipAmount.Value / 100.0)));
+                    commandStack.Execute(new ReplaceUnitEquipmentCommand(unit, oldItem, equipItem, (double)numEquipAmount.Value / 100.0));
 				}
 				else
 				{
-					commandStack.Execute(new ReplaceUnitEquipmentCommand(unit, oldItem, equip, (float)numEquipAmount.Value));
+                    commandStack.Execute(new ReplaceUnitEquipmentCommand(unit, oldItem, equipItem, (double)numEquipAmount.Value));
 				}
 			}
 		}
@@ -217,7 +216,7 @@
 
 		private void cbEquipAll_CheckedChanged(object sender, System.EventArgs e)
 		{
-			numEquipAmount.Enabled = ((UnitEquipmentItem)listItems.SelectedItem).EquipmentItem.MinNumber != -1 && !cbEquipAll.Checked;
+			numEquipAmount.Enabled = ((UnitEquipmentItem)listItems.SelectedItem).MinNumber != WarFoundryCore.INFINITY && !cbEquipAll.Checked;
 			setOkayButton();
 		}
 
@@ -232,13 +231,12 @@
 			if (listItems.SelectedIndex > -1)
 			{
 				UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem;
-				EquipmentItem equip = equipItem.EquipmentItem;
 				required = equipItem.IsRequired;
 
-				if (equip.IsRatioLimit)
+                if (equipItem.IsRatioLimit)
 				{
-					numEquipAmount.Minimum = (decimal)Math.Round(equip.MinNumber * 100, 2);
-					numEquipAmount.Maximum = (decimal)Math.Round(equip.MaxNumber * 100, 2);
+                    numEquipAmount.Minimum = (decimal)Math.Round(equipItem.MinNumber * 100.0, 2);
+                    numEquipAmount.Maximum = (decimal)Math.Round(equipItem.MaxNumber * 100.0, 2);
 					numEquipAmount.Value = numEquipAmount.Minimum;
 					cbEquipAll.Enabled = false;
 					lblPercent.Visible = true;
@@ -246,11 +244,11 @@
 				}
 				else
 				{
-					numEquipAmount.Minimum = (decimal)(equip.MinNumber != -1 ? equip.MinNumber : unit.Size);
-					numEquipAmount.Maximum = (decimal)(equip.MaxNumber != -1 ? equip.MaxNumber : unit.Size);
+                    numEquipAmount.Minimum = (decimal)(equipItem.MinNumber != -1 ? equipItem.MinNumber : unit.Size);
+                    numEquipAmount.Maximum = (decimal)(equipItem.MaxNumber != -1 ? equipItem.MaxNumber : unit.Size);
 					numEquipAmount.Value = numEquipAmount.Minimum;
-					cbEquipAll.Enabled = (equip.MaxNumber == -1 && equip.MinNumber != -1);
-					cbEquipAll.Checked = equip.MinNumber == -1;
+                    cbEquipAll.Enabled = (equipItem.MaxNumber == -1 && equipItem.MinNumber != -1);
+                    cbEquipAll.Checked = equipItem.MinNumber == -1;
 					numEquipAmount.Width = 144;
 				}
 			}