# HG changeset patch # User IBBoard # Date 1283631065 0 # Node ID 100626381159cdb5d591233dbf5ec2e23e294491 # Parent 77448375d2f994e3e7799887718a11e9017987a0 Re #60: Add UI to add/remove/edit weapons in GTK * Rip apart UI controls and put all the common code in a base class * Add additional interfaces for common UI behaviour between equipment widgets Not tested, but should provide a base for Replace widget diff -r 77448375d2f9 -r 100626381159 IBBoard.WarFoundry.GUI.GTK.csproj --- a/IBBoard.WarFoundry.GUI.GTK.csproj Sat Sep 04 10:25:39 2010 +0000 +++ b/IBBoard.WarFoundry.GUI.GTK.csproj Sat Sep 04 20:11:05 2010 +0000 @@ -59,6 +59,9 @@ + + + diff -r 77448375d2f9 -r 100626381159 UIControl/AbstractBaseEquipmentUIControl.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UIControl/AbstractBaseEquipmentUIControl.cs Sat Sep 04 20:11:05 2010 +0000 @@ -0,0 +1,210 @@ +// This file (AbstractBaseEquipmentUIControl.cs) is a part of the IBBoard.WarFoundry.GUI.GTK project and is copyright 2010 IBBoard +// +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. +using System; +using IBBoard.Commands; +using IBBoard.WarFoundry.API.Objects; +using IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces; +using IBBoard.Lang; +using IBBoard.WarFoundry.API.Util; +namespace IBBoard.WarFoundry.GUI.GTK.UIControl +{ + public abstract class AbstractBaseEquipmentUIControl where UI_TYPE : IBaseEquipmentUI + { + protected CommandStack commandStack; + protected Unit unit; + protected UI_TYPE ui; + protected UnitEquipmentItem equipItem; + protected double minPercentage, maxPercentage; + protected int minNumber, maxNumber; + protected bool isRatioAmount; + protected double equipmentAmount; + + public AbstractBaseEquipmentUIControl(Unit unit, CommandStack commandStack) + { + this.unit = unit; + this.commandStack = commandStack; + SetupUI(); + } + + private void SetupUI() + { + ui = CreateEquipmentUI(); + ui.SetUnitEquipmentLimitsEnabled(false); + ui.SetOkayEnabledState(false); + ui.UnitEquipmentAmountChanged += SetUnitEquipmentValues; + ui.UnitEquipmentAmountTypeChanged += SetUnitEquipmentValues; + CompleteUISetup(); + } + + /// + /// Creates the UI component that will be displayed to the user and returns it + /// + /// + /// the UI component to display to the user + /// + protected abstract UI_TYPE CreateEquipmentUI(); + + /// + /// Completes any additional user interface setup. + /// + protected virtual void CompleteUISetup() + { + //Do nothing + } + + protected void HandleUnitEquipmentAmountChanged() + { + SetUnitEquipmentValues(); + } + + /// + /// Sets the unit equipment values on the UI + /// + protected void SetUnitEquipmentValues() + { + ui.SetOkayEnabledState(HasNonZeroEquipmentAmount()); + isRatioAmount = ui.IsRatioEquipmentAmount; + + if (isRatioAmount) + { + equipmentAmount = ui.EquipmentPercentageAmount; + SetEquipmentAmountsFromPercentage(equipmentAmount); + } + + else + { + int equipmentIntAmount = ui.EquipmentNumericAmount; + equipmentAmount = equipmentIntAmount; + SetEquipmentAmountsFromNumber(equipmentIntAmount); + } + } + + private void SetEquipmentAmountsFromPercentage(double equipAmount) + { + if (equipAmount > maxPercentage) + { + 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, maxPercentage); + string percentageTooLargeTitle = Translation.GetTranslation("equipPercentageTooLargeTitle", "equipment percentage too large"); + // MessageBox.Show(ParentForm, percentageTooLarge, percentageTooLargeTitle); + equipAmount = maxPercentage; + } + + else if (equipAmount < minPercentage) + { + 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, minPercentage); + string percentageTooSmallTitle = Translation.GetTranslation("equipPercentageTooSmallTitle", "equipment percentage too small"); + // MessageBox.Show(ParentForm, percentageTooSmall, percentageTooSmallTitle); + equipAmount = minPercentage; + } + + ui.EquipmentNumericAmount = CalculateNumericValueFromPercentage(equipAmount); + ui.EquipmentPercentageAmount = equipAmount; + } + + private int CalculateNumericValueFromPercentage(double percent) + { + int calcedAmount = (int)CustomMath.IBBMath.Round((unit.Size * (percent / 100.0)), equipItem.RoundNumberUp); + return Math.Min(Math.Max(calcedAmount, minNumber), maxNumber); + } + + private void SetEquipmentAmountsFromNumber(int equipAmount) + { + if (equipAmount > maxNumber) + { + 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, maxNumber); + string amountTooLargeTitle = Translation.GetTranslation("equipNumberTooLargeTitle", "equipment amount too large"); + //MessageBox.Show(ParentForm, amountTooLarge, amountTooLargeTitle); + equipAmount = maxNumber; + } + + else if (equipAmount < minNumber) + { + string amountTooSmall = Translation.GetTranslation("equipNumberTooSmall", "the current amount ({0}) was smaller than the minimum for the equipment item ({1}) - the minimum value will be used instead", equipAmount, minNumber); + string amountTooSmallTitle = Translation.GetTranslation("equipNumberTooSmallTitle", "equipment amount too small"); + //MessageBox.Show(ParentForm, amountTooSmall, amountTooSmallTitle); + equipAmount = minNumber; + } + + ui.EquipmentPercentageAmount = CalcualtePercentageValueFromNumber(equipAmount); + ui.EquipmentNumericAmount = equipAmount; + } + + private double CalcualtePercentageValueFromNumber(int number) + { + double calcedAmount = RoundPercentage(CustomMath.IBBMath.Percentage(number, unit.Size)); + return Math.Min(Math.Max(calcedAmount, minPercentage), maxPercentage); + } + + protected void SetEquipmentAmountControlEnabledStates() + { + ui.SetNumericAmountEnabledState(!isRatioAmount); + ui.SetPercentageAmountEnabledState(true); + } + + protected double GetMaxPercentageLimit(UnitEquipmentItem equip) + { + double maxPercent = RoundPercentage(UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); + return Math.Max(0, maxPercent); + } + + protected double GetMinPercentageLimit(UnitEquipmentItem equip) + { + double minPercent = RoundPercentage(UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); + return Math.Max(0, minPercent); + } + + protected int GetMaxNumericLimit(UnitEquipmentItem equip) + { + int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip); + return Math.Max(0, maxNumber); + } + + protected int GetMinNumericLimit(UnitEquipmentItem equip) + { + int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip); + return Math.Max(0, minNumber); + } + + protected bool HasNonZeroEquipmentAmount() + { + bool nonZero; + + if (isRatioAmount) + { + nonZero = (ui.EquipmentPercentageAmount > 0); + } + + + else + { + nonZero = (ui.EquipmentNumericAmount > 0); + } + + return nonZero; + } + + private double RoundPercentage(double percent) + { + return Math.Round(percent, 1); + } + + public void Show() + { + bool okayed = ui.ShowControl(); + + if (okayed) + { + DoProcessing(); + } + + ui.Dispose(); + } + + /// + /// Does the processing required for the control when the "OK" button was clicked + /// + protected abstract void DoProcessing(); + } +} + diff -r 77448375d2f9 -r 100626381159 UIControl/AddEquipmentUIControl.cs --- a/UIControl/AddEquipmentUIControl.cs Sat Sep 04 10:25:39 2010 +0000 +++ b/UIControl/AddEquipmentUIControl.cs Sat Sep 04 20:11:05 2010 +0000 @@ -11,113 +11,24 @@ using IBBoard.Lang; namespace IBBoard.WarFoundry.GUI.GTK.UIControl { - public class AddEquipmentUIControl - { - private CommandStack commandStack; - private IAddEquipmentUI ui; - private Unit unit; - private UnitEquipmentItem equipItem; - private double minPercentage, maxPercentage; - private int minNumber, maxNumber; - private bool isRatioAmount; - private double equipmentAmount; - - - public AddEquipmentUIControl(Unit unit, CommandStack commandStack) - { - this.unit = unit; - this.commandStack = commandStack; - SetupUI(); - } - - private void SetupUI() + public class AddEquipmentUIControl : AbstractBaseEquipmentUIControl + { + public AddEquipmentUIControl(Unit unit, CommandStack commandStack) : base(unit, commandStack) { - CreateEquipmentUI(); - ui.SetUnitEquipmentLimitsEnabled(false); - UnitEquipmentItem[] items = Arrays.Subtract(UnitEquipmentUtil.GetAllowedEquipmentItems(unit), unit.GetEquipment()); - ui.SetUnitEquipmentItems(items); - ui.SetOkayEnabledState(false); - ui.UnitEquipmentItemChoiceChanged += HandleUiUnitEquipmentItemChoiceChanged; - ui.UnitEquipmentAmountChanged += HandleUnitEquipmentAmountChanged; - ui.UnitEquipmentAmountTypeChanged += HandleUnitEquipmentAmountChanged; - } - - private void HandleUnitEquipmentAmountChanged() - { - ui.SetOkayEnabledState(equipItem != null && HasNonZeroEquipmentAmount()); - isRatioAmount = ui.IsRatioEquipmentAmount; - - if (isRatioAmount) - { - equipmentAmount = ui.EquipmentPercentageAmount; - SetEquipmentAmountsFromPercentage(equipmentAmount); - } - else - { - int equipmentIntAmount = ui.EquipmentNumericAmount; - equipmentAmount = equipmentIntAmount; - SetEquipmentAmountsFromNumber(equipmentIntAmount); - } + //Do nothing extra } - private void SetEquipmentAmountsFromPercentage(double equipAmount) - { - if (equipAmount > maxPercentage) - { - 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, maxPercentage); - string percentageTooLargeTitle = Translation.GetTranslation("equipPercentageTooLargeTitle", "equipment percentage too large"); - // MessageBox.Show(ParentForm, percentageTooLarge, percentageTooLargeTitle); - equipAmount = maxPercentage; - } - else if (equipAmount < minPercentage) - { - 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, minPercentage); - string percentageTooSmallTitle = Translation.GetTranslation("equipPercentageTooSmallTitle", "equipment percentage too small"); - // MessageBox.Show(ParentForm, percentageTooSmall, percentageTooSmallTitle); - equipAmount = minPercentage; - } - - ui.EquipmentNumericAmount = CalculateNumericValueFromPercentage(equipAmount); - ui.EquipmentPercentageAmount = equipAmount; + //TODO Make abstract + protected override IAddEquipmentUI CreateEquipmentUI() + { + return new FrmAddEquipment(); } - private int CalculateNumericValueFromPercentage(double percent) - { - int calcedAmount = (int)CustomMath.IBBMath.Round((unit.Size * (percent / 100.0)), equipItem.RoundNumberUp); - return Math.Min(Math.Max(calcedAmount, minNumber), maxNumber); - } - - private void SetEquipmentAmountsFromNumber(int equipAmount) + protected override void CompleteUISetup() { - if (equipAmount > maxNumber) - { - 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, maxNumber); - string amountTooLargeTitle = Translation.GetTranslation("equipNumberTooLargeTitle", "equipment amount too large"); - //MessageBox.Show(ParentForm, amountTooLarge, amountTooLargeTitle); - equipAmount = maxNumber; - } - else if (equipAmount < minNumber) - { - string amountTooSmall = Translation.GetTranslation("equipNumberTooSmall", "the current amount ({0}) was smaller than the minimum for the equipment item ({1}) - the minimum value will be used instead", equipAmount, minNumber); - string amountTooSmallTitle = Translation.GetTranslation("equipNumberTooSmallTitle", "equipment amount too small"); - //MessageBox.Show(ParentForm, amountTooSmall, amountTooSmallTitle); - equipAmount = minNumber; - } - - ui.EquipmentPercentageAmount = CalcualtePercentageValueFromNumber(equipAmount); - ui.EquipmentNumericAmount = equipAmount; - } - - private double CalcualtePercentageValueFromNumber(int number) - { - double calcedAmount = RoundPercentage(CustomMath.IBBMath.Percentage(number, unit.Size)); - return Math.Min(Math.Max(calcedAmount, minPercentage), maxPercentage); - } - - //TODO Make abstract - protected void CreateEquipmentUI() - { - ui = new FrmAddEquipment(); + UnitEquipmentItem[] items = Arrays.Subtract(UnitEquipmentUtil.GetAllowedEquipmentItems(unit), unit.GetEquipment()); + ui.SetUnitEquipmentItems(items); + ui.UnitEquipmentItemChoiceChanged += HandleUiUnitEquipmentItemChoiceChanged; } private void HandleUiUnitEquipmentItemChoiceChanged(UnitEquipmentItem equip) @@ -135,7 +46,7 @@ ui.SetUnitEquipmentLimits(equipIsRatioLimit, minPercentage, maxPercentage, minNumber, maxNumber); ui.SetUnitEquipmentLimitsEnabled(true); ui.SetOkayEnabledState(HasNonZeroEquipmentAmount()); - SetEquipmentAmountControlEnabledStates(equipIsRatioLimit); + SetEquipmentAmountControlEnabledStates(); } else { @@ -145,76 +56,18 @@ ui.SetUnitEquipmentLimitsEnabled(false); ui.SetOkayEnabledState(false); } - } - - private void SetEquipmentAmountControlEnabledStates(bool ratioLimited) - { - ui.SetNumericAmountEnabledState(!ratioLimited); - ui.SetPercentageAmountEnabledState(true); - } - - private double GetMaxPercentageLimit(UnitEquipmentItem equip) - { - double maxPercent = RoundPercentage(UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); - return Math.Max(0, maxPercent); - } - - private double GetMinPercentageLimit(UnitEquipmentItem equip) - { - double minPercent = RoundPercentage(UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); - return Math.Max(0, minPercent); - } - - private int GetMaxNumericLimit(UnitEquipmentItem equip) - { - int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip); - return Math.Max(0, maxNumber); - } - private int GetMinNumericLimit(UnitEquipmentItem equip) - { - int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip); - return Math.Max(0, minNumber); } - private bool HasNonZeroEquipmentAmount() + protected override void DoProcessing() { - bool nonZero; - if (isRatioAmount) { - nonZero = (ui.EquipmentPercentageAmount > 0); + commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, equipmentAmount)); } - else { - nonZero = (ui.EquipmentNumericAmount > 0); + commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int)equipmentAmount)); } - - return nonZero; - } - - private double RoundPercentage(double percent) - { - return Math.Round(percent, 1); - } - - public void Show() - { - bool okayed = ui.ShowControl(); - - if (okayed) - { - if (isRatioAmount) - { - commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, equipmentAmount)); - } - else - { - commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int)equipmentAmount)); - } - } - - ui.Dispose(); } } } diff -r 77448375d2f9 -r 100626381159 UIControl/EditEquipmentUIControl.cs --- a/UIControl/EditEquipmentUIControl.cs Sat Sep 04 10:25:39 2010 +0000 +++ b/UIControl/EditEquipmentUIControl.cs Sat Sep 04 20:11:05 2010 +0000 @@ -12,200 +12,34 @@ using IBBoard.WarFoundry.GUI.GTK; namespace IBBoard.WarFoundry.GUI.GTK.UIControl { - public class EditEquipmentUIControl - { - private CommandStack commandStack; - private IEditEquipmentUI ui; - private Unit unit; - private UnitEquipmentItem equipItem; - private double minPercentage, maxPercentage; - private int minNumber, maxNumber; - private bool isRatioAmount; - private double equipmentAmount; - - - public EditEquipmentUIControl(Unit unit, UnitEquipmentItem item, CommandStack commandStack) + public class EditEquipmentUIControl : AbstractBaseEquipmentUIControl + { + public EditEquipmentUIControl(Unit unit, UnitEquipmentItem item, CommandStack commandStack) : base(unit, commandStack) { - this.unit = unit; - this.commandStack = commandStack; this.equipItem = item; - SetupUI(); + } + + //TODO Make abstract + protected override IEditEquipmentUI CreateEquipmentUI() + { + return new FrmEditEquipment(); } - private void SetupUI() + protected override void CompleteUISetup() { - CreateEquipmentUI(); - ui.SetOkayEnabledState(false); - isRatioAmount = UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equipItem); - maxPercentage = GetMaxPercentageLimit(equipItem); - minPercentage = GetMinPercentageLimit(equipItem); - maxNumber = GetMaxNumericLimit(equipItem); - minNumber = GetMinNumericLimit(equipItem); - - ui.SetUnitEquipmentLimits(isRatioAmount, minPercentage, maxPercentage, minNumber, maxNumber); - ui.SetUnitEquipmentLimitsEnabled(true); - ui.SetOkayEnabledState(false); - SetEquipmentAmountControlEnabledStates(); - - if (UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equipItem)) - { - SetEquipmentAmountsFromPercentage(UnitEquipmentUtil.GetEquipmentAmount(unit, equipItem)); - } - else - { - SetEquipmentAmountsFromNumber((int)UnitEquipmentUtil.GetEquipmentAmount(unit, equipItem)); - } - - ui.UnitEquipmentAmountChanged += HandleUnitEquipmentAmountChanged; - ui.UnitEquipmentAmountTypeChanged += HandleUnitEquipmentAmountChanged; + SetUnitEquipmentValues(); } - private void HandleUnitEquipmentAmountChanged() + protected override void DoProcessing() { - ui.SetOkayEnabledState(HasNonZeroEquipmentAmount()); - isRatioAmount = ui.IsRatioEquipmentAmount; - if (isRatioAmount) { - equipmentAmount = ui.EquipmentPercentageAmount; - SetEquipmentAmountsFromPercentage(equipmentAmount); + commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, equipmentAmount)); } else { - int equipmentIntAmount = ui.EquipmentNumericAmount; - equipmentAmount = equipmentIntAmount; - SetEquipmentAmountsFromNumber(equipmentIntAmount); - } - } - - private void SetEquipmentAmountsFromPercentage(double equipAmount) - { - if (equipAmount > maxPercentage) - { - 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, maxPercentage); - string percentageTooLargeTitle = Translation.GetTranslation("equipPercentageTooLargeTitle", "equipment percentage too large"); - // MessageBox.Show(ParentForm, percentageTooLarge, percentageTooLargeTitle); - equipAmount = maxPercentage; - } - else if (equipAmount < minPercentage) - { - 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, minPercentage); - string percentageTooSmallTitle = Translation.GetTranslation("equipPercentageTooSmallTitle", "equipment percentage too small"); - // MessageBox.Show(ParentForm, percentageTooSmall, percentageTooSmallTitle); - equipAmount = minPercentage; - } - - ui.EquipmentNumericAmount = CalculateNumericValueFromPercentage(equipAmount); - ui.EquipmentPercentageAmount = equipAmount; - } - - private int CalculateNumericValueFromPercentage(double percent) - { - int calcedAmount = (int)CustomMath.IBBMath.Round((unit.Size * (percent / 100.0)), equipItem.RoundNumberUp); - return Math.Min(Math.Max(calcedAmount, minNumber), maxNumber); - } - - private void SetEquipmentAmountsFromNumber(int equipAmount) - { - if (equipAmount > maxNumber) - { - 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, maxNumber); - string amountTooLargeTitle = Translation.GetTranslation("equipNumberTooLargeTitle", "equipment amount too large"); - //MessageBox.Show(ParentForm, amountTooLarge, amountTooLargeTitle); - equipAmount = maxNumber; - } - else if (equipAmount < minNumber) - { - string amountTooSmall = Translation.GetTranslation("equipNumberTooSmall", "the current amount ({0}) was smaller than the minimum for the equipment item ({1}) - the minimum value will be used instead", equipAmount, minNumber); - string amountTooSmallTitle = Translation.GetTranslation("equipNumberTooSmallTitle", "equipment amount too small"); - //MessageBox.Show(ParentForm, amountTooSmall, amountTooSmallTitle); - equipAmount = minNumber; + commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int)equipmentAmount)); } - - ui.EquipmentPercentageAmount = CalcualtePercentageValueFromNumber(equipAmount); - ui.EquipmentNumericAmount = equipAmount; - } - - private double CalcualtePercentageValueFromNumber(int number) - { - double calcedAmount = RoundPercentage(CustomMath.IBBMath.Percentage(number, unit.Size)); - return Math.Min(Math.Max(calcedAmount, minPercentage), maxPercentage); - } - - //TODO Make abstract - protected void CreateEquipmentUI() - { - ui = new FrmEditEquipment(); - } - - private void SetEquipmentAmountControlEnabledStates() - { - ui.SetNumericAmountEnabledState(!isRatioAmount); - ui.SetPercentageAmountEnabledState(true); - } - - private double GetMaxPercentageLimit(UnitEquipmentItem equip) - { - double maxPercent = RoundPercentage(UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); - return Math.Max(0, maxPercent); - } - - private double GetMinPercentageLimit(UnitEquipmentItem equip) - { - double minPercent = RoundPercentage(UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); - return Math.Max(0, minPercent); - } - - private int GetMaxNumericLimit(UnitEquipmentItem equip) - { - int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip); - return Math.Max(0, maxNumber); - } - private int GetMinNumericLimit(UnitEquipmentItem equip) - { - int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip); - return Math.Max(0, minNumber); - } - - private bool HasNonZeroEquipmentAmount() - { - bool nonZero; - - if (isRatioAmount) - { - nonZero = (ui.EquipmentPercentageAmount > 0); - } - - else - { - nonZero = (ui.EquipmentNumericAmount > 0); - } - - return nonZero; - } - - private double RoundPercentage(double percent) - { - return Math.Round(percent, 1); - } - - public void Show() - { - bool okayed = ui.ShowControl(); - - if (okayed) - { - if (isRatioAmount) - { - commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, equipmentAmount)); - } - else - { - commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int)equipmentAmount)); - } - } - - ui.Dispose(); } } } diff -r 77448375d2f9 -r 100626381159 UIControl/Interfaces/IAddEquipmentUI.cs --- a/UIControl/Interfaces/IAddEquipmentUI.cs Sat Sep 04 10:25:39 2010 +0000 +++ b/UIControl/Interfaces/IAddEquipmentUI.cs Sat Sep 04 20:11:05 2010 +0000 @@ -8,124 +8,9 @@ /// /// The interface that UI components should implement to represent "Add Equipment" dialogs or system equivalents (e.g. console areas or HTML fragments) /// - public interface IAddEquipmentUI : IDisposable + public interface IAddEquipmentUI : ISelectableItemEquipmentUI { - /// - /// Should be fired when unit equipment item choice changes. - /// - event SingleArgMethodInvoker UnitEquipmentItemChoiceChanged; - - /// - /// Occurs when the unit equipment amount type changes (e.g. percentage to numeric) - /// - event MethodInvoker UnitEquipmentAmountTypeChanged; - - /// - /// Occurs when the unit equipment amount changes - /// - event MethodInvoker UnitEquipmentAmountChanged; - - /// - /// Sets the equipment items that should be displayed on the form - /// - /// - /// The equipment items that should be displayed on the form - /// - void SetUnitEquipmentItems(UnitEquipmentItem[] items); - - /// - /// Sets the limits for the currently selected equipment item - /// - /// - /// True if the current limit is a ratio limit, else false for absolute limits - /// - /// - /// The minimum limit as a percentage - /// - /// - /// The maximum limit as a percentage - /// - /// - /// The minimum number as an absolute figure - /// - /// - /// The maximum number as an absolute figure - /// - void SetUnitEquipmentLimits(bool isRatioLimit, double minPercent, double maxPercent, int minNumber, int maxNumber); - - /// - /// Sets whether the unit equipment limit UI components should be enabled and able to accept input. This will - /// generally pass the values on to the and - /// methods and is included for convenience - /// - /// - /// True if the UI components should accept input, else false - /// - void SetUnitEquipmentLimitsEnabled(bool isEnabled); - - /// - /// Shows the control and awaits a user action (close or okay) - /// - /// - /// true if the control was closed with "Okay", else false - /// - bool ShowControl(); - - /// - /// Gets the selected equipment item. - /// - /// - /// The selected equipment item. - /// - UnitEquipmentItem SelectedUnitEquipmentItem { get; } - - /// - /// Gets a value indicating whether the equipment amount is a ratio or an absolute number. - /// - /// - /// true if the selected amount is a ratio type (percentage or "all"); otherwise, false. - /// - bool IsRatioEquipmentAmount { get; } - - /// - /// Gets and sets the numeric amount for the current equipment amount. This number is meaningless if is true - /// - /// - /// The absolue number of items taken. - /// - int EquipmentNumericAmount { get; set; } - - /// - /// Gets and sets the percentage amount for the current equipment amount. This number is meaningless if is false - /// - /// - /// The number of items taken as a percentage of the unit size. - /// - double EquipmentPercentageAmount { get; set; } - - /// - /// Sets the state of the Okay button. - /// - /// - /// true to enable the button, else false - /// - void SetOkayEnabledState(bool enabled); - - /// - /// Sets the state of the numeric equipment amount control. - /// - /// - /// true to enable the control, else false - /// - void SetNumericAmountEnabledState(bool enabled); - - /// - /// Sets the state of the percentage equipment amount control. - /// - /// - /// true to enable the control, else false - /// - void SetPercentageAmountEnabledState(bool enabled); + //Marker interface } } diff -r 77448375d2f9 -r 100626381159 UIControl/Interfaces/IBaseEquipmentUI.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UIControl/Interfaces/IBaseEquipmentUI.cs Sat Sep 04 20:11:05 2010 +0000 @@ -0,0 +1,120 @@ +// This file (IBaseEquipmentUI.cs) is a part of the IBBoard.WarFoundry.GUI.GTK project and is copyright 2010 IBBoard +// +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. +using System; +namespace IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces +{ + /// + /// The base interface that all "UI control" controlled interfaces implement. It provides common definitions for all classes + /// + public interface IBaseEquipmentUI : IDisposable + { + /// + /// Occurs when the unit equipment amount type changes (e.g. percentage to numeric) + /// + event MethodInvoker UnitEquipmentAmountTypeChanged; + + /// + /// Occurs when the unit equipment amount changes + /// + event MethodInvoker UnitEquipmentAmountChanged; + + /// + /// Sets the limits for the currently selected equipment item + /// + /// + /// True if the current limit is a ratio limit, else false for absolute limits + /// + /// + /// The minimum limit as a percentage + /// + /// + /// The maximum limit as a percentage + /// + /// + /// The minimum number as an absolute figure + /// + /// + /// The maximum number as an absolute figure + /// + void SetUnitEquipmentLimits(bool isRatioLimit, double minPercent, double maxPercent, int minNumber, int maxNumber); + + /// + /// Sets whether the unit equipment limit UI components should be enabled and able to accept input. This will + /// generally pass the values on to the and + /// methods and is included for convenience + /// + /// + /// True if the UI components should accept input, else false + /// + void SetUnitEquipmentLimitsEnabled(bool isEnabled); + + /// + /// Shows the control and awaits a user action (close or okay) + /// + /// + /// true if the control was closed with "Okay", else false + /// + bool ShowControl(); + + /// + /// Gets a value indicating whether the equipment amount is a ratio or an absolute number. + /// + /// + /// true if the selected amount is a ratio type (percentage or "all"); otherwise, false. + /// + bool IsRatioEquipmentAmount + { + get; + } + + /// + /// Gets and sets the numeric amount for the current equipment amount. This number is meaningless if is true + /// + /// + /// The absolue number of items taken. + /// + int EquipmentNumericAmount + { + get; + set; + } + + /// + /// Gets and sets the percentage amount for the current equipment amount. This number is meaningless if is false + /// + /// + /// The number of items taken as a percentage of the unit size. + /// + double EquipmentPercentageAmount + { + get; + set; + } + + /// + /// Sets the state of the Okay button. + /// + /// + /// true to enable the button, else false + /// + void SetOkayEnabledState(bool enabled); + + /// + /// Sets the state of the numeric equipment amount control. + /// + /// + /// true to enable the control, else false + /// + void SetNumericAmountEnabledState(bool enabled); + + /// + /// Sets the state of the percentage equipment amount control. + /// + /// + /// true to enable the control, else false + /// + void SetPercentageAmountEnabledState(bool enabled); + } +} + diff -r 77448375d2f9 -r 100626381159 UIControl/Interfaces/IEditEquipmentUI.cs --- a/UIControl/Interfaces/IEditEquipmentUI.cs Sat Sep 04 10:25:39 2010 +0000 +++ b/UIControl/Interfaces/IEditEquipmentUI.cs Sat Sep 04 20:11:05 2010 +0000 @@ -8,103 +8,9 @@ /// /// The interface that UI components should implement to represent "Edit Equipment" dialogs or system equivalents (e.g. console areas or HTML fragments) /// - public interface IEditEquipmentUI : IDisposable - { - /// - /// Occurs when the unit equipment amount type changes (e.g. percentage to numeric) - /// - event MethodInvoker UnitEquipmentAmountTypeChanged; - - /// - /// Occurs when the unit equipment amount changes - /// - event MethodInvoker UnitEquipmentAmountChanged; - - /// - /// Sets the limits for the currently selected equipment item - /// - /// - /// True if the current limit is a ratio limit, else false for absolute limits - /// - /// - /// The minimum limit as a percentage - /// - /// - /// The maximum limit as a percentage - /// - /// - /// The minimum number as an absolute figure - /// - /// - /// The maximum number as an absolute figure - /// - void SetUnitEquipmentLimits(bool isRatioLimit, double minPercent, double maxPercent, int minNumber, int maxNumber); - - /// - /// Sets whether the unit equipment limit UI components should be enabled and able to accept input. This will - /// generally pass the values on to the and - /// methods and is included for convenience - /// - /// - /// True if the UI components should accept input, else false - /// - void SetUnitEquipmentLimitsEnabled(bool isEnabled); - - /// - /// Shows the control and awaits a user action (close or okay) - /// - /// - /// true if the control was closed with "Okay", else false - /// - bool ShowControl(); - - /// - /// Gets a value indicating whether the equipment amount is a ratio or an absolute number. - /// - /// - /// true if the selected amount is a ratio type (percentage or "all"); otherwise, false. - /// - bool IsRatioEquipmentAmount { get; } - - /// - /// Gets and sets the numeric amount for the current equipment amount. This number is meaningless if is true - /// - /// - /// The absolue number of items taken. - /// - int EquipmentNumericAmount { get; set; } - - /// - /// Gets and sets the percentage amount for the current equipment amount. This number is meaningless if is false - /// - /// - /// The number of items taken as a percentage of the unit size. - /// - double EquipmentPercentageAmount { get; set; } - - /// - /// Sets the state of the Okay button. - /// - /// - /// true to enable the button, else false - /// - void SetOkayEnabledState(bool enabled); - - /// - /// Sets the state of the numeric equipment amount control. - /// - /// - /// true to enable the control, else false - /// - void SetNumericAmountEnabledState(bool enabled); - - /// - /// Sets the state of the percentage equipment amount control. - /// - /// - /// true to enable the control, else false - /// - void SetPercentageAmountEnabledState(bool enabled); + public interface IEditEquipmentUI : IBaseEquipmentUI + { + //Marker interface } } diff -r 77448375d2f9 -r 100626381159 UIControl/Interfaces/ISelectableItemEquipmentUI.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UIControl/Interfaces/ISelectableItemEquipmentUI.cs Sat Sep 04 20:11:05 2010 +0000 @@ -0,0 +1,38 @@ +// This file (ISelectableItemEquipmentUI.cs) is a part of the IBBoard.WarFoundry.GUI.GTK project and is copyright 2010 IBBoard +// +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. +using System; +using IBBoard.WarFoundry.API.Objects; +namespace IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces +{ + /// + /// + /// + public interface ISelectableItemEquipmentUI : IBaseEquipmentUI + { + /// + /// Should be fired when unit equipment item choice changes. + /// + event SingleArgMethodInvoker UnitEquipmentItemChoiceChanged; + + /// + /// Sets the equipment items that should be displayed on the form + /// + /// + /// The equipment items that should be displayed on the form + /// + void SetUnitEquipmentItems(UnitEquipmentItem[] items); + + /// + /// Gets the selected equipment item. + /// + /// + /// The selected equipment item. + /// + UnitEquipmentItem SelectedUnitEquipmentItem + { + get; + } + } +} + diff -r 77448375d2f9 -r 100626381159 gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmAddEquipment.cs --- a/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmAddEquipment.cs Sat Sep 04 10:25:39 2010 +0000 +++ b/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmAddEquipment.cs Sat Sep 04 20:11:05 2010 +0000 @@ -135,6 +135,7 @@ this.rbEquipAll = new global::Gtk.RadioButton(""); this.rbEquipAll.CanFocus = true; this.rbEquipAll.Name = "rbEquipAll"; + this.rbEquipAll.Active = true; this.rbEquipAll.DrawIndicator = true; this.rbEquipAll.UseUnderline = true; this.rbEquipAll.Group = new global::GLib.SList(global::System.IntPtr.Zero);