diff UI/EquipmentAmountControl.cs @ 81:e749b748e7ea

Re #198: Add slots with counts to units * Update EquipmentAmountControl to resolve errors Also: * Use lower-case slot name for StatColumnStyle check for "Name"
author IBBoard <dev@ibboard.co.uk>
date Mon, 26 Oct 2009 20:56:09 +0000
parents c243b043aa62
children 9dc22147c2db
line wrap: on
line diff
--- a/UI/EquipmentAmountControl.cs	Wed Oct 21 20:11:18 2009 +0000
+++ b/UI/EquipmentAmountControl.cs	Mon Oct 26 20:56:09 2009 +0000
@@ -6,6 +6,7 @@
 using System.Text;
 using System.Windows.Forms;
 using IBBoard.CustomMath;
+using IBBoard.Limits;
 using IBBoard.WarFoundry.API;
 using IBBoard.WarFoundry.API.Objects;
 
@@ -47,10 +48,12 @@
 		{
 			if (equip != null)
 			{
-				if (equip.IsRatioLimit)
+				AbstractLimit limit = unit.UnitType.GetEquipmentSlotLimit(equip.SlotName);
+
+				if (equip.IsRatioLimit && limit is IPercentageLimit)
 				{
-					double minPercent = equip.MinPercentage;
-					double maxPercent = equip.MaxPercentage;
+					double minPercent = ((IPercentageLimit)equip.MinLimit).Percentage;
+					double maxPercent = ((IPercentageLimit)equip.MaxLimit).Percentage;
 					int minNumber = (int) CalculateNumericValueFromPercentage(minPercent);
 					int maxNumber = (int) CalculateNumericValueFromPercentage(maxPercent);
 
@@ -77,8 +80,8 @@
 				}
 				else
 				{
-					int minNumber = equip.MinNumber;
-					int maxNumber = equip.MaxNumber;
+					int minNumber = equip.MinLimit.GetLimit(unit.Size);
+					int maxNumber = GetMaxNumber(limit);
 					double minPercent = (double) CalcualtePercentageValueFromNumber(minNumber);
 					double maxPercent = (double) CalcualtePercentageValueFromNumber(maxNumber);
 
@@ -108,6 +111,19 @@
 			}
 		}
 
+		private int GetMaxNumber(AbstractLimit limit)
+		{
+			int maxNumber = equip.MaxLimit.GetLimit(unit.Size);
+
+			if (!(limit is UnlimitedLimit))
+			{
+				int slotMax = limit.GetLimit(unit.Size) - unit.GetEquipmentAmountInSlot(equip.SlotName);
+				maxNumber = Math.Min(slotMax, maxNumber);
+			}
+
+			return maxNumber;
+		}
+
 		private void SetUpDownControlMinMaxes(double minPercent, double maxPercent, int minNumber, int maxNumber)
 		{
 			percentage.ValueChanged -= percentage_ValueChanged;