Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.WinForms
comparison UI/EquipmentAmountControl.cs @ 89:971f7801f984
Fixes #205: Odd/prime numbers causes a crash
* Fix crash with number out of range by rounding our min/max percentage the same as we round the calculated value
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 02 Nov 2009 20:11:18 +0000 |
parents | 340e711ca4c3 |
children | 63ca28bd8ada |
comparison
equal
deleted
inserted
replaced
88:340e711ca4c3 | 89:971f7801f984 |
---|---|
48 private void SetWidgetValues() | 48 private void SetWidgetValues() |
49 { | 49 { |
50 if (equip != null) | 50 if (equip != null) |
51 { | 51 { |
52 bool equipIsRatioLimit = UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip); | 52 bool equipIsRatioLimit = UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip); |
53 double maxPercent = UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip); | 53 double maxPercent = RoundPercentage(UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); |
54 double minPercent = UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip); | 54 double minPercent = RoundPercentage(UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
55 int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip); | 55 int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip); |
56 int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip); | 56 int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip); |
57 | 57 |
58 SetUpDownControlMinMaxes(minPercent, maxPercent, minNumber, maxNumber); | 58 SetUpDownControlMinMaxes(minPercent, maxPercent, minNumber, maxNumber); |
59 | 59 |
150 percentage.ValueChanged += percentage_ValueChanged; | 150 percentage.ValueChanged += percentage_ValueChanged; |
151 } | 151 } |
152 | 152 |
153 private decimal CalcualtePercentageValueFromNumber(int number) | 153 private decimal CalcualtePercentageValueFromNumber(int number) |
154 { | 154 { |
155 return (decimal) Math.Round((number / (unit.Size * 1.0)) * 100, 1); | 155 return (decimal) RoundPercentage((number / (unit.Size * 1.0)) * 100); |
156 } | |
157 | |
158 private double RoundPercentage(double percent) | |
159 { | |
160 return Math.Round(percent, 1); | |
156 } | 161 } |
157 | 162 |
158 public double EquipmentAmount | 163 public double EquipmentAmount |
159 { | 164 { |
160 get | 165 get |