Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
diff FrmReplaceEquipment.cs @ 70:4b82515586ac
Re #60: Add UI to add/remove/edit weapons in GTK
* Fix widget enabling/disabling (sometimes enabling ratio input for numeric limit)
* Correct behaviour of Edit dialog (setting wrong value on edit)
* Add setting of limits based on specific equipment item to base dialog controller
* Make sure that we catch all radio button click events from Edit dialog
* Add ability to ignore and listen to widgets to make sure that changes don't cascade
TODO: See if code can be tidied up and common classes created
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 06 Nov 2010 17:03:13 +0000 |
parents | 7028e24b67ec |
children | 7055b24cfc79 |
line wrap: on
line diff
--- a/FrmReplaceEquipment.cs Sat Nov 06 11:44:26 2010 +0000 +++ b/FrmReplaceEquipment.cs Sat Nov 06 17:03:13 2010 +0000 @@ -22,8 +22,7 @@ public event MethodInvoker UnitEquipmentAmountTypeChanged; public event MethodInvoker UnitEquipmentAmountChanged; - private bool limitsEnabled = false; - private bool ratioLimited = false; + private bool isRatioLimited; public FrmReplaceEquipment() { @@ -37,6 +36,26 @@ lstEquipment.AppendColumn(equipColumn); } + public void ListenToWidgets() + { + rbEquipAll.Clicked += RadioButtonClicked; + rbEquipNumeric.Clicked += RadioButtonClicked; + rbEquipPercent.Clicked += RadioButtonClicked; + numericAmount.ValueChanged += SpinButtonValueChanged; + percentageAmount.ValueChanged += SpinButtonValueChanged; + lstEquipment.Selection.Changed += OnSelectionChanged; + } + + public void IgnoreWidgets() + { + rbEquipAll.Clicked -= RadioButtonClicked; + rbEquipNumeric.Clicked -= RadioButtonClicked; + rbEquipPercent.Clicked -= RadioButtonClicked; + numericAmount.ValueChanged -= SpinButtonValueChanged; + percentageAmount.ValueChanged -= SpinButtonValueChanged; + lstEquipment.Selection.Changed -= OnSelectionChanged; + } + private void OnUnitEquipmentAmountChanged() { if (UnitEquipmentAmountChanged != null) @@ -76,9 +95,9 @@ public void SetUnitEquipmentLimits(bool isRatioLimit, double minPercent, double maxPercent, int minNumber, int maxNumber) { log.DebugFormat("IsRatio? {0}. Limits: {1}->{2}, {3}%->{4}%", isRatioLimit, minNumber, maxNumber, minPercent, maxPercent); - ratioLimited = isRatioLimit; numericAmount.SetRange(minNumber, maxNumber); percentageAmount.SetRange(minPercent, maxPercent); + isRatioLimited = isRatioLimit; if (isRatioLimit) { @@ -140,8 +159,9 @@ public void SetNumericAmountEnabledState(bool enabled) { - rbEquipNumeric.Sensitive = enabled; - numericAmount.Sensitive = enabled; + double minPercent = GetMinPercentage(); + rbEquipNumeric.Sensitive = enabled && !(isRatioLimited && minPercent == 100); + numericAmount.Sensitive = rbEquipNumeric.Sensitive; } public void SetPercentageAmountEnabledState(bool enabled) @@ -149,11 +169,11 @@ if (enabled) { double minPercentage = GetMinPercentage(); - rbEquipPercent.Sensitive = minPercentage != 100; - percentageAmount.Sensitive = minPercentage != 100; - double maxPercentage = GetMaxPercentage(); - rbEquipAll.Sensitive = ratioLimited && maxPercentage == 100; - lblEquipAll.Sensitive = ratioLimited && maxPercentage == 100; + rbEquipPercent.Sensitive = isRatioLimited && minPercentage != 100; + percentageAmount.Sensitive = rbEquipPercent.Sensitive; + double maxPercentage = GetMaxPercentage(); + rbEquipAll.Sensitive = isRatioLimited && maxPercentage == 100; + lblEquipAll.Sensitive = rbEquipAll.Sensitive; } else { @@ -186,7 +206,7 @@ } } - public bool IsRatioEquipmentAmount + public bool IsRatioEquipmentAmount { get { @@ -194,7 +214,7 @@ } } - public int EquipmentNumericAmount + public int EquipmentNumericAmount { get { @@ -207,7 +227,7 @@ } } - public double EquipmentPercentageAmount + public double EquipmentPercentageAmount { get {