# HG changeset patch # User IBBoard # Date 1256590569 0 # Node ID e749b748e7ea6713298f40d58803dc510e53a307 # Parent c243b043aa624cbfd045678af54a0891339d1bcb Re #198: Add slots with counts to units * Update EquipmentAmountControl to resolve errors Also: * Use lower-case slot name for StatColumnStyle check for "Name" diff -r c243b043aa62 -r e749b748e7ea UI/EquipmentAmountControl.cs --- 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; diff -r c243b043aa62 -r e749b748e7ea UI/StatColumnStyle.cs --- a/UI/StatColumnStyle.cs Wed Oct 21 20:11:18 2009 +0000 +++ b/UI/StatColumnStyle.cs Mon Oct 26 20:56:09 2009 +0000 @@ -22,7 +22,7 @@ { Stat stat = (Stat) obj; StringFormat stringFormat = new StringFormat(); - stringFormat.Alignment = (stat.ParentSlotName == "Name" ? StringAlignment.Near : StringAlignment.Center); + stringFormat.Alignment = (stat.ParentSlotName == "name" ? StringAlignment.Near : StringAlignment.Center);//TODO: make "name" a constrant g.DrawString(stat.SlotValueString, GetFont(), foreBrush, rect, stringFormat); } else