diff FrmEditUnitEquipment.cs @ 43:7ace7d2249ac

Fixes #117: Add percentage and number boxes to equipment item dialogs * Add value changing when changing radio button selection * Add logic to equipment amount editing control to perform value setting (but see #146) Also, fixes #114 by rebuilding everything in to a single control
author IBBoard <dev@ibboard.co.uk>
date Mon, 07 Sep 2009 20:10:40 +0000
parents d06c2e390a14
children 1576f669b3eb
line wrap: on
line diff
--- a/FrmEditUnitEquipment.cs	Sun Sep 06 19:58:39 2009 +0000
+++ b/FrmEditUnitEquipment.cs	Mon Sep 07 20:10:40 2009 +0000
@@ -134,53 +134,50 @@
 
 		private void bttnOkay_Click(object sender, System.EventArgs e)
 		{
-			if (setValue())
+			if (SetValue())
 			{
 				this.Close();
 			}
 		}
 
-		private bool setValue()
+		private bool SetValue()
 		{
-			return false;
-			//if (!bttnOkay.Enabled)
-			//{
-			//    if (equipItem.IsRequired)
-			//    {
-			//        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);
-			//        return false;
-			//    }
-			//    else
-			//    {
-			//        DialogResult dr = MessageBox.Show(this, "This will remove the item from the unit. Continue?", "Confirm remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
+			bool setValue = true;
+			double amount = equipmentAmount.EquipmentAmount;
 
-			//        if (dr!=DialogResult.Yes)
-			//        {
-			//            return false;
-			//        }
-			//    }
-			//}
+			if (amount == 0)
+			{
+				if (equipItem.IsRequired)
+				{
+					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);
+					setValue = false;
+				}
+				else
+				{
+					DialogResult dr = MessageBox.Show(this, "This will remove the item from the unit. Continue?", "Confirm remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
 
-			//if (cbEquipAll.Checked)
-			//{
-			//    if (equipAmount != WarFoundryCore.INFINITY)
-			//    {
-			//        commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, WarFoundryCore.INFINITY));
-			//    }
-			//}
-			//else if (numEquipAmount.Value != (decimal)equipAmount)
-			//{
-			//    if (equipItem.IsRatioLimit)
-			//    {
-			//        commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, (double)numEquipAmount.Value));
-			//    }
-			//    else
-			//    {
-			//        commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int)numEquipAmount.Value));
-			//    }
-			//}
+					if (dr != DialogResult.Yes)
+					{
+						setValue = false;
+					}
+				}
+			}
+
+			double oldAmount = unit.GetEquipmentAmount(equipItem);
 
-			//return true;
+			if (setValue && oldAmount != amount)
+			{
+				if (equipmentAmount.IsRatioEquipmentAmount)
+				{
+					commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, amount));
+				}
+				else
+				{
+					commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int)amount));
+				}
+			}
+
+			return setValue;
 		}
 
 		private void bttnCancel_Click(object sender, System.EventArgs e)
@@ -190,7 +187,7 @@
 
 		private void setOkayButton()
 		{
-			double equipAmount = 0;// equipmentAmount.EquipmentAmount;
+			double equipAmount = equipmentAmount.EquipmentAmount;
 			bttnOkay.Enabled = equipAmount > 0 || equipAmount == WarFoundryCore.INFINITY || !equipItem.IsRequired;
 		}