Mercurial > repos > IBBoard.WarFoundry.GUI.WinForms
comparison 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 |
comparison
equal
deleted
inserted
replaced
80:c243b043aa62 | 81:e749b748e7ea |
---|---|
4 using System.Drawing; | 4 using System.Drawing; |
5 using System.Data; | 5 using System.Data; |
6 using System.Text; | 6 using System.Text; |
7 using System.Windows.Forms; | 7 using System.Windows.Forms; |
8 using IBBoard.CustomMath; | 8 using IBBoard.CustomMath; |
9 using IBBoard.Limits; | |
9 using IBBoard.WarFoundry.API; | 10 using IBBoard.WarFoundry.API; |
10 using IBBoard.WarFoundry.API.Objects; | 11 using IBBoard.WarFoundry.API.Objects; |
11 | 12 |
12 namespace IBBoard.WarFoundry.GUI.WinForms.UI | 13 namespace IBBoard.WarFoundry.GUI.WinForms.UI |
13 { | 14 { |
45 | 46 |
46 private void SetWidgetValues() | 47 private void SetWidgetValues() |
47 { | 48 { |
48 if (equip != null) | 49 if (equip != null) |
49 { | 50 { |
50 if (equip.IsRatioLimit) | 51 AbstractLimit limit = unit.UnitType.GetEquipmentSlotLimit(equip.SlotName); |
51 { | 52 |
52 double minPercent = equip.MinPercentage; | 53 if (equip.IsRatioLimit && limit is IPercentageLimit) |
53 double maxPercent = equip.MaxPercentage; | 54 { |
55 double minPercent = ((IPercentageLimit)equip.MinLimit).Percentage; | |
56 double maxPercent = ((IPercentageLimit)equip.MaxLimit).Percentage; | |
54 int minNumber = (int) CalculateNumericValueFromPercentage(minPercent); | 57 int minNumber = (int) CalculateNumericValueFromPercentage(minPercent); |
55 int maxNumber = (int) CalculateNumericValueFromPercentage(maxPercent); | 58 int maxNumber = (int) CalculateNumericValueFromPercentage(maxPercent); |
56 | 59 |
57 rbEquipAll.Enabled = maxPercent == 100; | 60 rbEquipAll.Enabled = maxPercent == 100; |
58 SetUpDownControlMinMaxes(minPercent, maxPercent, minNumber, maxNumber); | 61 SetUpDownControlMinMaxes(minPercent, maxPercent, minNumber, maxNumber); |
75 rbNumeric.Enabled = true; | 78 rbNumeric.Enabled = true; |
76 } | 79 } |
77 } | 80 } |
78 else | 81 else |
79 { | 82 { |
80 int minNumber = equip.MinNumber; | 83 int minNumber = equip.MinLimit.GetLimit(unit.Size); |
81 int maxNumber = equip.MaxNumber; | 84 int maxNumber = GetMaxNumber(limit); |
82 double minPercent = (double) CalcualtePercentageValueFromNumber(minNumber); | 85 double minPercent = (double) CalcualtePercentageValueFromNumber(minNumber); |
83 double maxPercent = (double) CalcualtePercentageValueFromNumber(maxNumber); | 86 double maxPercent = (double) CalcualtePercentageValueFromNumber(maxNumber); |
84 | 87 |
85 percentage.Enabled = false; | 88 percentage.Enabled = false; |
86 rbPercentage.Enabled = false; | 89 rbPercentage.Enabled = false; |
104 } | 107 } |
105 else | 108 else |
106 { | 109 { |
107 Enabled = false; | 110 Enabled = false; |
108 } | 111 } |
112 } | |
113 | |
114 private int GetMaxNumber(AbstractLimit limit) | |
115 { | |
116 int maxNumber = equip.MaxLimit.GetLimit(unit.Size); | |
117 | |
118 if (!(limit is UnlimitedLimit)) | |
119 { | |
120 int slotMax = limit.GetLimit(unit.Size) - unit.GetEquipmentAmountInSlot(equip.SlotName); | |
121 maxNumber = Math.Min(slotMax, maxNumber); | |
122 } | |
123 | |
124 return maxNumber; | |
109 } | 125 } |
110 | 126 |
111 private void SetUpDownControlMinMaxes(double minPercent, double maxPercent, int minNumber, int maxNumber) | 127 private void SetUpDownControlMinMaxes(double minPercent, double maxPercent, int minNumber, int maxNumber) |
112 { | 128 { |
113 percentage.ValueChanged -= percentage_ValueChanged; | 129 percentage.ValueChanged -= percentage_ValueChanged; |