# HG changeset patch # User IBBoard # Date 1282766667 0 # Node ID 0c5fbb54bfb0400af8d084cc45c0e53a53be278f # Parent eb7db8495bb55b239318d03f1cdb804d14968973 Re #60: Add UI to add/remove/edit weapons in GTK * Refactor enabling/disabling of radio buttons * Handle null selections * Move Dispose() to be an interface method and move call out to controller diff -r eb7db8495bb5 -r 0c5fbb54bfb0 FrmAddEquipment.cs --- a/FrmAddEquipment.cs Wed Aug 25 19:51:23 2010 +0000 +++ b/FrmAddEquipment.cs Wed Aug 25 20:04:27 2010 +0000 @@ -17,6 +17,9 @@ public event SingleArgMethodInvoker UnitEquipmentItemChoiceChanged; + private bool limitsEnabled = false; + private bool ratioLimited = false; + public FrmAddEquipment() { this.Build(); @@ -52,14 +55,26 @@ 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); - rbEquipNumeric.Sensitive = isRatioLimit; - numericAmount.Sensitive = isRatioLimit; + ratioLimited = isRatioLimit; + SetEnabledState(); numericAmount.SetRange(minNumber, maxNumber); percentageAmount.SetRange(minPercent, maxPercent); } public void SetUnitEquipmentLimitsEnabled(bool isEnabled) { + limitsEnabled = isEnabled; + SetEnabledState(); + } + + private void SetEnabledState() + { + rbEquipNumeric.Sensitive = (limitsEnabled && ratioLimited); + numericAmount.Sensitive = (limitsEnabled && ratioLimited); + rbEquipPercent.Sensitive = limitsEnabled; + percentageAmount.Sensitive = limitsEnabled; + rbEquipAll.Sensitive = limitsEnabled; + lblEquipAll.Sensitive = limitsEnabled; } public bool ShowControl() @@ -67,7 +82,6 @@ int result = Run(); bool okayClicked = (result == (int)ResponseType.Ok); this.Hide(); - this.Dispose(); return okayClicked; } @@ -75,6 +89,12 @@ { log.Debug("Cancel clicked"); Respond(ResponseType.Cancel); + } + + protected virtual void OkayButtonClicked(object sender, System.EventArgs e) + { + log.Debug("Okay clicked"); + Respond(ResponseType.Ok); } } } diff -r eb7db8495bb5 -r 0c5fbb54bfb0 UIControl/AddEquipmentUIControl.cs --- a/UIControl/AddEquipmentUIControl.cs Wed Aug 25 19:51:23 2010 +0000 +++ b/UIControl/AddEquipmentUIControl.cs Wed Aug 25 20:04:27 2010 +0000 @@ -24,6 +24,7 @@ private void SetupUI() { CreateEquipmentUI(); + ui.SetUnitEquipmentLimitsEnabled(false); UnitEquipmentItem[] items = Arrays.Subtract(UnitEquipmentUtil.GetAllowedEquipmentItems(unit), unit.GetEquipment()); ui.SetUnitEquipmentItems(items); ui.UnitEquipmentItemChoiceChanged += HandleUiUnitEquipmentItemChoiceChanged; @@ -37,28 +38,38 @@ private void HandleUiUnitEquipmentItemChoiceChanged(UnitEquipmentItem equip) { - bool equipIsRatioLimit = UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip); - double maxPercent = RoundPercentage(UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); - maxPercent = Math.Max(0, maxPercent); - double minPercent = RoundPercentage(UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); - minPercent = Math.Max(0, minPercent); - int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip); - maxNumber = Math.Max(0, maxNumber); - int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip); - minNumber = Math.Max(0, minNumber); + if (equip != null) + { + bool equipIsRatioLimit = UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip); + double maxPercent = RoundPercentage(UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); + maxPercent = Math.Max(0, maxPercent); + double minPercent = RoundPercentage(UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); + minPercent = Math.Max(0, minPercent); + int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip); + maxNumber = Math.Max(0, maxNumber); + int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip); + minNumber = Math.Max(0, minNumber); - ui.SetUnitEquipmentLimits(equipIsRatioLimit, minPercent, maxPercent, minNumber, maxNumber); - + ui.SetUnitEquipmentLimits(equipIsRatioLimit, minPercent, maxPercent, minNumber, maxNumber); + ui.SetUnitEquipmentLimitsEnabled(true); + } + else + { + ui.SetUnitEquipmentLimits(true, 0, 0, 0, 0); + ui.SetUnitEquipmentLimitsEnabled(false); + } } private double RoundPercentage(double percent) { return Math.Round(percent, 1); } - + public void Show() { ui.ShowControl(); + //Do command stuff here + ui.Dispose(); } } } diff -r eb7db8495bb5 -r 0c5fbb54bfb0 UIControl/Interfaces/IAddEquipmentUI.cs --- a/UIControl/Interfaces/IAddEquipmentUI.cs Wed Aug 25 19:51:23 2010 +0000 +++ b/UIControl/Interfaces/IAddEquipmentUI.cs Wed Aug 25 20:04:27 2010 +0000 @@ -58,6 +58,19 @@ /// true if the control was closed with "Okay", else false /// bool ShowControl(); + + /// + /// Releases all resource used by the object. + /// + /// + /// Call when you are finished using the + /// . The method + /// leaves the in an unusable state. + /// After calling , you must release all references to the + /// so the garbage collector can reclaim + /// the memory that the was occupying. + /// + void Dispose(); } } diff -r eb7db8495bb5 -r 0c5fbb54bfb0 gtk-gui/gui.stetic --- a/gtk-gui/gui.stetic Wed Aug 25 19:51:23 2010 +0000 +++ b/gtk-gui/gui.stetic Wed Aug 25 20:04:27 2010 +0000 @@ -1289,6 +1289,7 @@ StockItem gtk-ok -5 + gtk-ok