Mercurial > repos > IBBoard.WarFoundry.GUI.GTK
changeset 66:100626381159
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
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 04 Sep 2010 20:11:05 +0000 |
parents | 77448375d2f9 |
children | a7306b5a229e |
files | IBBoard.WarFoundry.GUI.GTK.csproj UIControl/AbstractBaseEquipmentUIControl.cs UIControl/AddEquipmentUIControl.cs UIControl/EditEquipmentUIControl.cs UIControl/Interfaces/IAddEquipmentUI.cs UIControl/Interfaces/IBaseEquipmentUI.cs UIControl/Interfaces/IEditEquipmentUI.cs UIControl/Interfaces/ISelectableItemEquipmentUI.cs gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmAddEquipment.cs |
diffstat | 9 files changed, 407 insertions(+), 557 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ <Compile Include="UIControl\Interfaces\IEditEquipmentUI.cs" /> <Compile Include="gtk-gui\IBBoard.WarFoundry.GUI.GTK.FrmEditEquipment.cs" /> <Compile Include="FrmEditEquipment.cs" /> + <Compile Include="UIControl\AbstractBaseEquipmentUIControl.cs" /> + <Compile Include="UIControl\Interfaces\IBaseEquipmentUI.cs" /> + <Compile Include="UIControl\Interfaces\ISelectableItemEquipmentUI.cs" /> </ItemGroup> <ItemGroup> <Content Include="App.png" />
--- /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<UI_TYPE> 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(); + } + + /// <summary> + /// Creates the UI component that will be displayed to the user and returns it + /// </summary> + /// <returns> + /// the UI component to display to the user + /// </returns> + protected abstract UI_TYPE CreateEquipmentUI(); + + /// <summary> + /// Completes any additional user interface setup. + /// </summary> + protected virtual void CompleteUISetup() + { + //Do nothing + } + + protected void HandleUnitEquipmentAmountChanged() + { + SetUnitEquipmentValues(); + } + + /// <summary> + /// Sets the unit equipment values on the UI + /// </summary> + 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(); + } + + /// <summary> + /// Does the processing required for the control when the "OK" button was clicked + /// </summary> + protected abstract void DoProcessing(); + } +} +
--- 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<IAddEquipmentUI> + { + 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(); } } }
--- 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<IEditEquipmentUI> + { + 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(); } } }
--- 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 @@ /// <summary> /// The interface that UI components should implement to represent "Add Equipment" dialogs or system equivalents (e.g. console areas or HTML fragments) /// </summary> - public interface IAddEquipmentUI : IDisposable + public interface IAddEquipmentUI : ISelectableItemEquipmentUI { - /// <summary> - /// Should be fired when unit equipment item choice changes. - /// </summary> - event SingleArgMethodInvoker<UnitEquipmentItem> UnitEquipmentItemChoiceChanged; - - /// <summary> - /// Occurs when the unit equipment amount type changes (e.g. percentage to numeric) - /// </summary> - event MethodInvoker UnitEquipmentAmountTypeChanged; - - /// <summary> - /// Occurs when the unit equipment amount changes - /// </summary> - event MethodInvoker UnitEquipmentAmountChanged; - - /// <summary> - /// Sets the equipment items that should be displayed on the form - /// </summary> - /// <param name='items'> - /// The equipment items that should be displayed on the form - /// </param> - void SetUnitEquipmentItems(UnitEquipmentItem[] items); - - /// <summary> - /// Sets the limits for the currently selected equipment item - /// </summary> - /// <param name='isRatioLimit'> - /// <code>True</code> if the current limit is a ratio limit, else <code>false</code> for absolute limits - /// </param> - /// <param name='minPercent'> - /// The minimum limit as a percentage - /// </param> - /// <param name='maxPercent'> - /// The maximum limit as a percentage - /// </param> - /// <param name='minNumber'> - /// The minimum number as an absolute figure - /// </param> - /// <param name='maxNumber'> - /// The maximum number as an absolute figure - /// </param> - void SetUnitEquipmentLimits(bool isRatioLimit, double minPercent, double maxPercent, int minNumber, int maxNumber); - - /// <summary> - /// 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 <see cref="SetNumericAmountEnabledState(bool)"/> and - /// <see cref="SetPercentageAmountEnabledState(bool)"/> methods and is included for convenience - /// </summary> - /// <param name='isEnabled'> - /// <code>True</code> if the UI components should accept input, else <code>false</code> - /// </param> - void SetUnitEquipmentLimitsEnabled(bool isEnabled); - - /// <summary> - /// Shows the control and awaits a user action (close or okay) - /// </summary> - /// <returns> - /// <code>true</code> if the control was closed with "Okay", else <code>false</code> - /// </returns> - bool ShowControl(); - - /// <summary> - /// Gets the selected equipment item. - /// </summary> - /// <value> - /// The selected equipment item. - /// </value> - UnitEquipmentItem SelectedUnitEquipmentItem { get; } - - /// <summary> - /// Gets a value indicating whether the equipment amount is a ratio or an absolute number. - /// </summary> - /// <value> - /// <c>true</c> if the selected amount is a ratio type (percentage or "all"); otherwise, <c>false</c>. - /// </value> - bool IsRatioEquipmentAmount { get; } - - /// <summary> - /// Gets and sets the numeric amount for the current equipment amount. This number is meaningless if <see cref="IsRatioEquipmentAmount"/> is <code>true</code> - /// </summary> - /// <value> - /// The absolue number of items taken. - /// </value> - int EquipmentNumericAmount { get; set; } - - /// <summary> - /// Gets and sets the percentage amount for the current equipment amount. This number is meaningless if <see cref="IsRatioEquipmentAmount"/> is <code>false</code> - /// </summary> - /// <value> - /// The number of items taken as a percentage of the unit size. - /// </value> - double EquipmentPercentageAmount { get; set; } - - /// <summary> - /// Sets the state of the Okay button. - /// </summary> - /// <param name='enabled'> - /// <code>true</code> to enable the button, else <code>false</code> - /// </param> - void SetOkayEnabledState(bool enabled); - - /// <summary> - /// Sets the state of the numeric equipment amount control. - /// </summary> - /// <param name='enabled'> - /// <code>true</code> to enable the control, else <code>false</code> - /// </param> - void SetNumericAmountEnabledState(bool enabled); - - /// <summary> - /// Sets the state of the percentage equipment amount control. - /// </summary> - /// <param name='enabled'> - /// <code>true</code> to enable the control, else <code>false</code> - /// </param> - void SetPercentageAmountEnabledState(bool enabled); + //Marker interface } }
--- /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 +{ + /// <summary> + /// The base interface that all "UI control" controlled interfaces implement. It provides common definitions for all classes + /// </summary> + public interface IBaseEquipmentUI : IDisposable + { + /// <summary> + /// Occurs when the unit equipment amount type changes (e.g. percentage to numeric) + /// </summary> + event MethodInvoker UnitEquipmentAmountTypeChanged; + + /// <summary> + /// Occurs when the unit equipment amount changes + /// </summary> + event MethodInvoker UnitEquipmentAmountChanged; + + /// <summary> + /// Sets the limits for the currently selected equipment item + /// </summary> + /// <param name='isRatioLimit'> + /// <code>True</code> if the current limit is a ratio limit, else <code>false</code> for absolute limits + /// </param> + /// <param name='minPercent'> + /// The minimum limit as a percentage + /// </param> + /// <param name='maxPercent'> + /// The maximum limit as a percentage + /// </param> + /// <param name='minNumber'> + /// The minimum number as an absolute figure + /// </param> + /// <param name='maxNumber'> + /// The maximum number as an absolute figure + /// </param> + void SetUnitEquipmentLimits(bool isRatioLimit, double minPercent, double maxPercent, int minNumber, int maxNumber); + + /// <summary> + /// 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 <see cref="SetNumericAmountEnabledState(bool)"/> and + /// <see cref="SetPercentageAmountEnabledState(bool)"/> methods and is included for convenience + /// </summary> + /// <param name='isEnabled'> + /// <code>True</code> if the UI components should accept input, else <code>false</code> + /// </param> + void SetUnitEquipmentLimitsEnabled(bool isEnabled); + + /// <summary> + /// Shows the control and awaits a user action (close or okay) + /// </summary> + /// <returns> + /// <code>true</code> if the control was closed with "Okay", else <code>false</code> + /// </returns> + bool ShowControl(); + + /// <summary> + /// Gets a value indicating whether the equipment amount is a ratio or an absolute number. + /// </summary> + /// <value> + /// <c>true</c> if the selected amount is a ratio type (percentage or "all"); otherwise, <c>false</c>. + /// </value> + bool IsRatioEquipmentAmount + { + get; + } + + /// <summary> + /// Gets and sets the numeric amount for the current equipment amount. This number is meaningless if <see cref="IsRatioEquipmentAmount"/> is <code>true</code> + /// </summary> + /// <value> + /// The absolue number of items taken. + /// </value> + int EquipmentNumericAmount + { + get; + set; + } + + /// <summary> + /// Gets and sets the percentage amount for the current equipment amount. This number is meaningless if <see cref="IsRatioEquipmentAmount"/> is <code>false</code> + /// </summary> + /// <value> + /// The number of items taken as a percentage of the unit size. + /// </value> + double EquipmentPercentageAmount + { + get; + set; + } + + /// <summary> + /// Sets the state of the Okay button. + /// </summary> + /// <param name='enabled'> + /// <code>true</code> to enable the button, else <code>false</code> + /// </param> + void SetOkayEnabledState(bool enabled); + + /// <summary> + /// Sets the state of the numeric equipment amount control. + /// </summary> + /// <param name='enabled'> + /// <code>true</code> to enable the control, else <code>false</code> + /// </param> + void SetNumericAmountEnabledState(bool enabled); + + /// <summary> + /// Sets the state of the percentage equipment amount control. + /// </summary> + /// <param name='enabled'> + /// <code>true</code> to enable the control, else <code>false</code> + /// </param> + void SetPercentageAmountEnabledState(bool enabled); + } +} +
--- 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 @@ /// <summary> /// The interface that UI components should implement to represent "Edit Equipment" dialogs or system equivalents (e.g. console areas or HTML fragments) /// </summary> - public interface IEditEquipmentUI : IDisposable - { - /// <summary> - /// Occurs when the unit equipment amount type changes (e.g. percentage to numeric) - /// </summary> - event MethodInvoker UnitEquipmentAmountTypeChanged; - - /// <summary> - /// Occurs when the unit equipment amount changes - /// </summary> - event MethodInvoker UnitEquipmentAmountChanged; - - /// <summary> - /// Sets the limits for the currently selected equipment item - /// </summary> - /// <param name='isRatioLimit'> - /// <code>True</code> if the current limit is a ratio limit, else <code>false</code> for absolute limits - /// </param> - /// <param name='minPercent'> - /// The minimum limit as a percentage - /// </param> - /// <param name='maxPercent'> - /// The maximum limit as a percentage - /// </param> - /// <param name='minNumber'> - /// The minimum number as an absolute figure - /// </param> - /// <param name='maxNumber'> - /// The maximum number as an absolute figure - /// </param> - void SetUnitEquipmentLimits(bool isRatioLimit, double minPercent, double maxPercent, int minNumber, int maxNumber); - - /// <summary> - /// 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 <see cref="SetNumericAmountEnabledState(bool)"/> and - /// <see cref="SetPercentageAmountEnabledState(bool)"/> methods and is included for convenience - /// </summary> - /// <param name='isEnabled'> - /// <code>True</code> if the UI components should accept input, else <code>false</code> - /// </param> - void SetUnitEquipmentLimitsEnabled(bool isEnabled); - - /// <summary> - /// Shows the control and awaits a user action (close or okay) - /// </summary> - /// <returns> - /// <code>true</code> if the control was closed with "Okay", else <code>false</code> - /// </returns> - bool ShowControl(); - - /// <summary> - /// Gets a value indicating whether the equipment amount is a ratio or an absolute number. - /// </summary> - /// <value> - /// <c>true</c> if the selected amount is a ratio type (percentage or "all"); otherwise, <c>false</c>. - /// </value> - bool IsRatioEquipmentAmount { get; } - - /// <summary> - /// Gets and sets the numeric amount for the current equipment amount. This number is meaningless if <see cref="IsRatioEquipmentAmount"/> is <code>true</code> - /// </summary> - /// <value> - /// The absolue number of items taken. - /// </value> - int EquipmentNumericAmount { get; set; } - - /// <summary> - /// Gets and sets the percentage amount for the current equipment amount. This number is meaningless if <see cref="IsRatioEquipmentAmount"/> is <code>false</code> - /// </summary> - /// <value> - /// The number of items taken as a percentage of the unit size. - /// </value> - double EquipmentPercentageAmount { get; set; } - - /// <summary> - /// Sets the state of the Okay button. - /// </summary> - /// <param name='enabled'> - /// <code>true</code> to enable the button, else <code>false</code> - /// </param> - void SetOkayEnabledState(bool enabled); - - /// <summary> - /// Sets the state of the numeric equipment amount control. - /// </summary> - /// <param name='enabled'> - /// <code>true</code> to enable the control, else <code>false</code> - /// </param> - void SetNumericAmountEnabledState(bool enabled); - - /// <summary> - /// Sets the state of the percentage equipment amount control. - /// </summary> - /// <param name='enabled'> - /// <code>true</code> to enable the control, else <code>false</code> - /// </param> - void SetPercentageAmountEnabledState(bool enabled); + public interface IEditEquipmentUI : IBaseEquipmentUI + { + //Marker interface } }
--- /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 +{ + /// <summary> + /// + /// </summary> + public interface ISelectableItemEquipmentUI : IBaseEquipmentUI + { + /// <summary> + /// Should be fired when unit equipment item choice changes. + /// </summary> + event SingleArgMethodInvoker<UnitEquipmentItem> UnitEquipmentItemChoiceChanged; + + /// <summary> + /// Sets the equipment items that should be displayed on the form + /// </summary> + /// <param name='items'> + /// The equipment items that should be displayed on the form + /// </param> + void SetUnitEquipmentItems(UnitEquipmentItem[] items); + + /// <summary> + /// Gets the selected equipment item. + /// </summary> + /// <value> + /// The selected equipment item. + /// </value> + UnitEquipmentItem SelectedUnitEquipmentItem + { + get; + } + } +} +
--- 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);