Mercurial > repos > IBBoard.WarFoundry.GUI.WinForms
changeset 97:e356134d73c4
Re #209: equipmentslot Value problem
* Add lots of debugging in the hope of tracking down Snowblizz's continued problems!
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 16 Nov 2009 20:56:54 +0000 |
parents | 057498981bde |
children | c7afc7824f50 |
files | UI/EquipmentAmountControl.cs |
diffstat | 1 files changed, 30 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/UI/EquipmentAmountControl.cs Mon Nov 09 20:58:18 2009 +0000 +++ b/UI/EquipmentAmountControl.cs Mon Nov 16 20:56:54 2009 +0000 @@ -5,6 +5,7 @@ using System.Data; using System.Text; using System.Windows.Forms; +using log4net; using IBBoard.CustomMath; using IBBoard.Lang; using IBBoard.Limits; @@ -16,6 +17,7 @@ { public partial class EquipmentAmountControl : UserControl { + private ILog log = LogManager.GetLogger(typeof(EquipmentAmountControl)); private Unit unit; private UnitEquipmentItem equip; public event EventHandler ValueChanged; @@ -29,11 +31,13 @@ public void SetUnit(Unit equipUnit) { unit = equipUnit; + log.Debug("Set unit to: " + (unit == null ? "null" : unit.Name)); } public void SetUnitEquipmentItem(UnitEquipmentItem unitEquipment) { equip = unitEquipment; + log.Debug("Set equipment to: " + (equip == null ? "null" : equip.Name)); SetWidgetValues(); } @@ -49,11 +53,17 @@ { if (equip != null) { + log.Debug("Equipment update"); bool equipIsRatioLimit = UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip); + log.Debug("Equipment is ratio? " + (equipIsRatioLimit ? "yes" : "no")); double maxPercent = RoundPercentage(UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); + log.Debug("Equipment max percentage: " + maxPercent); double minPercent = RoundPercentage(UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); + log.Debug("Equipment min percentage: " + minPercent); int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip); + log.Debug("Equipment max count: " + maxNumber); int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip); + log.Debug("Equipment min count: " + minNumber); SetUpDownControlMinMaxes(minPercent, maxPercent, minNumber, maxNumber); @@ -68,17 +78,20 @@ rbEquipAll.Enabled = equipIsRatioLimit && maxPercent == 100; rbEquipAll.Checked = equipIsRatioLimit && minPercent == 100; + log.Debug("rbEquipAll: " + (rbEquipAll.Enabled ? "enabled":"disabled") + " " + (rbEquipAll.Checked ? "checked" : "unchecked")); percentage.Enabled = equipIsRatioLimit && minPercent != 100; rbPercentage.Enabled = percentage.Enabled; rbPercentage.Checked = equipIsRatioLimit && !rbEquipAll.Checked; + log.Debug("rbPercentage: " + (rbPercentage.Enabled ? "enabled" : "disabled") + " " + (rbPercentage.Checked ? "checked" : "unchecked")); numeric.Enabled = !equipIsRatioLimit || minPercent != 100; rbNumeric.Enabled = numeric.Enabled; rbNumeric.Checked = !equipIsRatioLimit; - + log.Debug("rbNumeric: " + (rbNumeric.Enabled ? "enabled" : "disabled") + " " + (rbNumeric.Checked ? "checked" : "unchecked")); SetUnitEquipmentItemAmount(); } else { + log.Debug("Null equipment - no widget update"); Enabled = false; } } @@ -100,6 +113,7 @@ private void SetUpDownControlMinMax(NumericUpDown upDownControl, decimal min, decimal max) { + log.Debug("Set "+upDownControl.Name+" min and max to: "+min+", "+max); upDownControl.Minimum = min; upDownControl.Maximum = max; } @@ -121,6 +135,7 @@ private void percentage_ValueChanged(object sender, EventArgs e) { + log.Debug("Percentage value changed"); SetNumericValueFromPercentage(); rbEquipAll.Checked = (percentage.Value == 100 && !rbNumeric.Checked); OnValueChanged(); @@ -136,11 +151,13 @@ private decimal CalculateNumericValueFromPercentage(decimal percent) { decimal calcedAmount = (decimal) IBBoard.CustomMath.IBBMath.Round((double)(unit.Size * (percent / 100)), equip.RoundNumberUp); + log.Debug("Numeric value calculated from percentage: "+percent+"% -> "+calcedAmount); return Math.Min(Math.Max(calcedAmount, numeric.Minimum), numeric.Maximum); } private void numeric_ValueChanged(object sender, EventArgs e) { + log.Debug("Numeric value changed"); SetPercentageValueFromNumeric(); OnValueChanged(); } @@ -156,6 +173,7 @@ private decimal CalcualtePercentageValueFromNumber(int number) { decimal calcedAmount = (decimal) RoundPercentage(IBBoard.CustomMath.IBBMath.Percentage(number, unit.Size)); + log.Debug("Numeric value calculated from percentage: " + number + " -> " + calcedAmount+"%"); return Math.Min(Math.Max(calcedAmount, percentage.Minimum), percentage.Maximum); } @@ -229,23 +247,26 @@ } } - private void SetEquipmentAmountsFromPercentage(double equipAmountNum) + private void SetEquipmentAmountsFromPercentage(double equipAmount) { - decimal decEquipAmount = (decimal) equipAmountNum; + log.Debug("Set equipment amount from percentage: " + equipAmount); + decimal decEquipAmount = (decimal) equipAmount; if (decEquipAmount > percentage.Maximum) { - string percentageTooLarge = Translation.GetTranslation("equipPercentageTooLarge", "The current percentage ({0}%) was larger than the maximum for the equipment item ({1}%). The maximum value will be used instead.", equipAmountNum, percentage.Maximum); + string percentageTooLarge = Translation.GetTranslation("equipPercentageTooLarge", "The current percentage ({0}%) was larger than the maximum for the equipment item ({1}%). The maximum value will be used instead.", equipAmount, percentage.Maximum); string percentageTooLargeTitle = Translation.GetTranslation("equipPercentageTooLargeTitle", "Equipment percentage too large"); MessageBox.Show(ParentForm, percentageTooLarge, percentageTooLargeTitle); decEquipAmount = percentage.Maximum; + log.Debug("Limited equipment amount to " + decEquipAmount); } else if (decEquipAmount < percentage.Minimum) { - string percentageTooSmall = Translation.GetTranslation("equipPercentageTooSmall", "The current percentage ({0}%) was smaller than the minimum for the equipment item ({1}%). The minimum value will be used instead.", equipAmountNum, percentage.Minimum); + string percentageTooSmall = Translation.GetTranslation("equipPercentageTooSmall", "The current percentage ({0}%) was smaller than the minimum for the equipment item ({1}%). The minimum value will be used instead.", equipAmount, percentage.Minimum); string percentageTooSmallTitle = Translation.GetTranslation("equipPercentageTooSmallTitle", "Equipment percentage too small"); MessageBox.Show(ParentForm, percentageTooSmall, percentageTooSmallTitle); decEquipAmount = percentage.Minimum; + log.Debug("Limited equipment amount to " + decEquipAmount); } numeric.Value = CalculateNumericValueFromPercentage(decEquipAmount); @@ -254,12 +275,15 @@ private void SetEquipmentAmountsFromNumber(int equipAmount) { + log.Debug("Set equipment percentage from amount: " + equipAmount); + if (equipAmount > numeric.Maximum) { string amountTooLarge = Translation.GetTranslation("equipNumberTooLarge", "The current amount ({0}) was larger than the maximum for the equipment item ({1}). The maximum value will be used instead.", equipAmount, numeric.Maximum); string amountTooLargeTitle = Translation.GetTranslation("equipNumberTooLargeTitle", "Equipment amount too large"); MessageBox.Show(ParentForm, amountTooLarge, amountTooLargeTitle); equipAmount = (int)numeric.Maximum; + log.Debug("Limited equipment amount to " + equipAmount); } else if (equipAmount < numeric.Minimum) { @@ -267,6 +291,7 @@ string amountTooSmallTitle = Translation.GetTranslation("equipNumberTooSmallTitle", "Equipment amount too small"); MessageBox.Show(ParentForm, amountTooSmall, amountTooSmallTitle); equipAmount = (int) numeric.Minimum; + log.Debug("Limited equipment amount to " + equipAmount); } percentage.Value = CalcualtePercentageValueFromNumber(equipAmount);