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, 410 insertions(+), 560 deletions(-) [+]
line diff
     1.1 --- a/IBBoard.WarFoundry.GUI.GTK.csproj	Sat Sep 04 10:25:39 2010 +0000
     1.2 +++ b/IBBoard.WarFoundry.GUI.GTK.csproj	Sat Sep 04 20:11:05 2010 +0000
     1.3 @@ -59,6 +59,9 @@
     1.4      <Compile Include="UIControl\Interfaces\IEditEquipmentUI.cs" />
     1.5      <Compile Include="gtk-gui\IBBoard.WarFoundry.GUI.GTK.FrmEditEquipment.cs" />
     1.6      <Compile Include="FrmEditEquipment.cs" />
     1.7 +    <Compile Include="UIControl\AbstractBaseEquipmentUIControl.cs" />
     1.8 +    <Compile Include="UIControl\Interfaces\IBaseEquipmentUI.cs" />
     1.9 +    <Compile Include="UIControl\Interfaces\ISelectableItemEquipmentUI.cs" />
    1.10    </ItemGroup>
    1.11    <ItemGroup>
    1.12      <Content Include="App.png" />
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/UIControl/AbstractBaseEquipmentUIControl.cs	Sat Sep 04 20:11:05 2010 +0000
     2.3 @@ -0,0 +1,210 @@
     2.4 +//  This file (AbstractBaseEquipmentUIControl.cs) is a part of the IBBoard.WarFoundry.GUI.GTK project and is copyright 2010 IBBoard
     2.5 +// 
     2.6 +//  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.
     2.7 +using System;
     2.8 +using IBBoard.Commands;
     2.9 +using IBBoard.WarFoundry.API.Objects;
    2.10 +using IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces;
    2.11 +using IBBoard.Lang;
    2.12 +using IBBoard.WarFoundry.API.Util;
    2.13 +namespace IBBoard.WarFoundry.GUI.GTK.UIControl
    2.14 +{
    2.15 +	public abstract class AbstractBaseEquipmentUIControl<UI_TYPE> where UI_TYPE : IBaseEquipmentUI
    2.16 +	{
    2.17 +		protected CommandStack commandStack;
    2.18 +		protected Unit unit;
    2.19 +		protected UI_TYPE ui;
    2.20 +		protected UnitEquipmentItem equipItem;
    2.21 +		protected double minPercentage, maxPercentage;
    2.22 +		protected int minNumber, maxNumber;
    2.23 +		protected bool isRatioAmount;
    2.24 +		protected double equipmentAmount;
    2.25 +		
    2.26 +		public AbstractBaseEquipmentUIControl(Unit unit, CommandStack commandStack)
    2.27 +		{
    2.28 +			this.unit = unit;
    2.29 +			this.commandStack = commandStack;
    2.30 +			SetupUI();
    2.31 +		}
    2.32 +
    2.33 +		private void SetupUI()
    2.34 +		{
    2.35 +			ui = CreateEquipmentUI();
    2.36 +			ui.SetUnitEquipmentLimitsEnabled(false);
    2.37 +			ui.SetOkayEnabledState(false);
    2.38 +			ui.UnitEquipmentAmountChanged += SetUnitEquipmentValues;
    2.39 +			ui.UnitEquipmentAmountTypeChanged += SetUnitEquipmentValues;
    2.40 +			CompleteUISetup();
    2.41 +		}
    2.42 +		
    2.43 +		/// <summary>
    2.44 +		/// Creates the UI component that will be displayed to the user and returns it
    2.45 +		/// </summary>
    2.46 +		/// <returns>
    2.47 +		/// the UI component to display to the user
    2.48 +		/// </returns>
    2.49 +		protected abstract UI_TYPE CreateEquipmentUI();
    2.50 +		
    2.51 +		/// <summary>
    2.52 +		/// Completes any additional user interface setup.
    2.53 +		/// </summary>
    2.54 +		protected virtual void CompleteUISetup()
    2.55 +		{
    2.56 +			//Do nothing
    2.57 +		}
    2.58 +			
    2.59 +		protected void HandleUnitEquipmentAmountChanged()
    2.60 +		{
    2.61 +			SetUnitEquipmentValues();
    2.62 +		}
    2.63 +		
    2.64 +		/// <summary>
    2.65 +		/// Sets the unit equipment values on the UI
    2.66 +		/// </summary>
    2.67 +		protected void SetUnitEquipmentValues()
    2.68 +		{
    2.69 +			ui.SetOkayEnabledState(HasNonZeroEquipmentAmount());
    2.70 +			isRatioAmount = ui.IsRatioEquipmentAmount;
    2.71 +			
    2.72 +			if (isRatioAmount)
    2.73 +			{
    2.74 +				equipmentAmount = ui.EquipmentPercentageAmount;
    2.75 +				SetEquipmentAmountsFromPercentage(equipmentAmount);
    2.76 +			}
    2.77 +
    2.78 +			else
    2.79 +			{
    2.80 +				int equipmentIntAmount = ui.EquipmentNumericAmount;
    2.81 +				equipmentAmount = equipmentIntAmount;
    2.82 +				SetEquipmentAmountsFromNumber(equipmentIntAmount);
    2.83 +			}
    2.84 +		}
    2.85 +
    2.86 +		private void SetEquipmentAmountsFromPercentage(double equipAmount)
    2.87 +		{
    2.88 +			if (equipAmount > maxPercentage)
    2.89 +			{
    2.90 +				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);
    2.91 +				string percentageTooLargeTitle = Translation.GetTranslation("equipPercentageTooLargeTitle", "equipment percentage too large");
    2.92 +				//				MessageBox.Show(ParentForm, percentageTooLarge, percentageTooLargeTitle);
    2.93 +				equipAmount = maxPercentage;
    2.94 +			}
    2.95 +
    2.96 +			else if (equipAmount < minPercentage)
    2.97 +			{
    2.98 +				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);
    2.99 +				string percentageTooSmallTitle = Translation.GetTranslation("equipPercentageTooSmallTitle", "equipment percentage too small");
   2.100 +				//				MessageBox.Show(ParentForm, percentageTooSmall, percentageTooSmallTitle);
   2.101 +				equipAmount = minPercentage;
   2.102 +			}
   2.103 +			
   2.104 +			ui.EquipmentNumericAmount = CalculateNumericValueFromPercentage(equipAmount);
   2.105 +			ui.EquipmentPercentageAmount = equipAmount;
   2.106 +		}
   2.107 +
   2.108 +		private int CalculateNumericValueFromPercentage(double percent)
   2.109 +		{
   2.110 +			int calcedAmount = (int)CustomMath.IBBMath.Round((unit.Size * (percent / 100.0)), equipItem.RoundNumberUp);
   2.111 +			return Math.Min(Math.Max(calcedAmount, minNumber), maxNumber);
   2.112 +		}
   2.113 +
   2.114 +		private void SetEquipmentAmountsFromNumber(int equipAmount)
   2.115 +		{
   2.116 +			if (equipAmount > maxNumber)
   2.117 +			{
   2.118 +				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);
   2.119 +				string amountTooLargeTitle = Translation.GetTranslation("equipNumberTooLargeTitle", "equipment amount too large");
   2.120 +				//MessageBox.Show(ParentForm, amountTooLarge, amountTooLargeTitle);
   2.121 +				equipAmount = maxNumber;
   2.122 +			}
   2.123 +
   2.124 +			else if (equipAmount < minNumber)
   2.125 +			{
   2.126 +				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);
   2.127 +				string amountTooSmallTitle = Translation.GetTranslation("equipNumberTooSmallTitle", "equipment amount too small");
   2.128 +				//MessageBox.Show(ParentForm, amountTooSmall, amountTooSmallTitle);
   2.129 +				equipAmount = minNumber;
   2.130 +			}
   2.131 +			
   2.132 +			ui.EquipmentPercentageAmount = CalcualtePercentageValueFromNumber(equipAmount);
   2.133 +			ui.EquipmentNumericAmount = equipAmount;
   2.134 +		}
   2.135 +
   2.136 +		private double CalcualtePercentageValueFromNumber(int number)
   2.137 +		{
   2.138 +			double calcedAmount = RoundPercentage(CustomMath.IBBMath.Percentage(number, unit.Size));
   2.139 +			return Math.Min(Math.Max(calcedAmount, minPercentage), maxPercentage);
   2.140 +		}
   2.141 +
   2.142 +		protected void SetEquipmentAmountControlEnabledStates()
   2.143 +		{
   2.144 +			ui.SetNumericAmountEnabledState(!isRatioAmount);
   2.145 +			ui.SetPercentageAmountEnabledState(true);
   2.146 +		}
   2.147 +
   2.148 +		protected double GetMaxPercentageLimit(UnitEquipmentItem equip)
   2.149 +		{
   2.150 +			double maxPercent = RoundPercentage(UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
   2.151 +			return Math.Max(0, maxPercent);
   2.152 +		}
   2.153 +
   2.154 +		protected double GetMinPercentageLimit(UnitEquipmentItem equip)
   2.155 +		{
   2.156 +			double minPercent = RoundPercentage(UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
   2.157 +			return Math.Max(0, minPercent);
   2.158 +		}
   2.159 +
   2.160 +		protected int GetMaxNumericLimit(UnitEquipmentItem equip)
   2.161 +		{
   2.162 +			int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip);
   2.163 +			return Math.Max(0, maxNumber);
   2.164 +		}
   2.165 +		
   2.166 +		protected int GetMinNumericLimit(UnitEquipmentItem equip)
   2.167 +		{
   2.168 +			int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip);
   2.169 +			return Math.Max(0, minNumber);
   2.170 +		}
   2.171 +
   2.172 +		protected bool HasNonZeroEquipmentAmount()
   2.173 +		{
   2.174 +			bool nonZero;
   2.175 +			
   2.176 +			if (isRatioAmount)
   2.177 +			{
   2.178 +				nonZero = (ui.EquipmentPercentageAmount > 0);
   2.179 +			}
   2.180 +
   2.181 +			
   2.182 +			else
   2.183 +			{
   2.184 +				nonZero = (ui.EquipmentNumericAmount > 0);
   2.185 +			}
   2.186 +			
   2.187 +			return nonZero;
   2.188 +		}
   2.189 +
   2.190 +		private double RoundPercentage(double percent)
   2.191 +		{
   2.192 +			return Math.Round(percent, 1);
   2.193 +		}
   2.194 +		
   2.195 +		public void Show()
   2.196 +		{			
   2.197 +			bool okayed = ui.ShowControl();
   2.198 +			
   2.199 +			if (okayed)
   2.200 +			{
   2.201 +				DoProcessing();
   2.202 +			}
   2.203 +			
   2.204 +			ui.Dispose();
   2.205 +		}	
   2.206 +		
   2.207 +		/// <summary>
   2.208 +		/// Does the processing required for the control when the "OK" button was clicked
   2.209 +		/// </summary>
   2.210 +		protected abstract void DoProcessing();
   2.211 +	}
   2.212 +}
   2.213 +
     3.1 --- a/UIControl/AddEquipmentUIControl.cs	Sat Sep 04 10:25:39 2010 +0000
     3.2 +++ b/UIControl/AddEquipmentUIControl.cs	Sat Sep 04 20:11:05 2010 +0000
     3.3 @@ -11,113 +11,24 @@
     3.4  using IBBoard.Lang;
     3.5  namespace IBBoard.WarFoundry.GUI.GTK.UIControl
     3.6  {
     3.7 -	public class AddEquipmentUIControl
     3.8 -	{
     3.9 -		private CommandStack commandStack;
    3.10 -		private IAddEquipmentUI ui;
    3.11 -		private Unit unit;
    3.12 -		private UnitEquipmentItem equipItem;
    3.13 -		private double minPercentage, maxPercentage;
    3.14 -		private int minNumber, maxNumber;
    3.15 -		private bool isRatioAmount;
    3.16 -		private double equipmentAmount;
    3.17 -		
    3.18 -		
    3.19 -		public AddEquipmentUIControl(Unit unit, CommandStack commandStack)
    3.20 +	public class AddEquipmentUIControl : AbstractBaseEquipmentUIControl<IAddEquipmentUI>
    3.21 +	{		
    3.22 +		public AddEquipmentUIControl(Unit unit, CommandStack commandStack) : base(unit, commandStack)
    3.23  		{
    3.24 -			this.unit = unit;
    3.25 -			this.commandStack = commandStack;
    3.26 -			SetupUI();
    3.27 +			//Do nothing extra
    3.28  		}
    3.29  		
    3.30 -		private void SetupUI()
    3.31 +		//TODO Make abstract
    3.32 +		protected override IAddEquipmentUI CreateEquipmentUI()
    3.33  		{
    3.34 -			CreateEquipmentUI();
    3.35 -			ui.SetUnitEquipmentLimitsEnabled(false);
    3.36 +			return new FrmAddEquipment();
    3.37 +		}
    3.38 +		
    3.39 +		protected override void CompleteUISetup()
    3.40 +		{			
    3.41  			UnitEquipmentItem[] items = Arrays.Subtract(UnitEquipmentUtil.GetAllowedEquipmentItems(unit), unit.GetEquipment());
    3.42  			ui.SetUnitEquipmentItems(items);
    3.43 -			ui.SetOkayEnabledState(false);
    3.44  			ui.UnitEquipmentItemChoiceChanged += HandleUiUnitEquipmentItemChoiceChanged;
    3.45 -			ui.UnitEquipmentAmountChanged += HandleUnitEquipmentAmountChanged;
    3.46 -			ui.UnitEquipmentAmountTypeChanged += HandleUnitEquipmentAmountChanged;
    3.47 -		}
    3.48 -
    3.49 -		private void HandleUnitEquipmentAmountChanged()
    3.50 -		{
    3.51 -			ui.SetOkayEnabledState(equipItem != null && HasNonZeroEquipmentAmount());
    3.52 -			isRatioAmount = ui.IsRatioEquipmentAmount;
    3.53 -			
    3.54 -			if (isRatioAmount)
    3.55 -			{
    3.56 -				equipmentAmount = ui.EquipmentPercentageAmount;
    3.57 -				SetEquipmentAmountsFromPercentage(equipmentAmount);
    3.58 -			}
    3.59 -			else
    3.60 -			{
    3.61 -				int equipmentIntAmount = ui.EquipmentNumericAmount;
    3.62 -				equipmentAmount = equipmentIntAmount;
    3.63 -				SetEquipmentAmountsFromNumber(equipmentIntAmount);
    3.64 -			}
    3.65 -		}
    3.66 -		
    3.67 -		private void SetEquipmentAmountsFromPercentage(double equipAmount)
    3.68 -		{			
    3.69 -			if (equipAmount > maxPercentage)
    3.70 -			{
    3.71 -				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);
    3.72 -				string percentageTooLargeTitle = Translation.GetTranslation("equipPercentageTooLargeTitle", "equipment percentage too large");
    3.73 -				//				MessageBox.Show(ParentForm, percentageTooLarge, percentageTooLargeTitle);
    3.74 -				equipAmount = maxPercentage;
    3.75 -			}
    3.76 -			else if (equipAmount < minPercentage)
    3.77 -			{
    3.78 -				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);
    3.79 -				string percentageTooSmallTitle = Translation.GetTranslation("equipPercentageTooSmallTitle", "equipment percentage too small");
    3.80 -		//				MessageBox.Show(ParentForm, percentageTooSmall, percentageTooSmallTitle);
    3.81 -				equipAmount = minPercentage;
    3.82 -			}
    3.83 -			
    3.84 -			ui.EquipmentNumericAmount = CalculateNumericValueFromPercentage(equipAmount);
    3.85 -			ui.EquipmentPercentageAmount = equipAmount;
    3.86 -		}
    3.87 -		
    3.88 -		private int CalculateNumericValueFromPercentage(double percent)
    3.89 -		{
    3.90 -			int calcedAmount = (int)CustomMath.IBBMath.Round((unit.Size * (percent / 100.0)), equipItem.RoundNumberUp);
    3.91 -			return Math.Min(Math.Max(calcedAmount, minNumber), maxNumber);
    3.92 -		}
    3.93 -
    3.94 -		private void SetEquipmentAmountsFromNumber(int equipAmount)
    3.95 -		{			
    3.96 -			if (equipAmount > maxNumber)
    3.97 -			{
    3.98 -				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);
    3.99 -				string amountTooLargeTitle = Translation.GetTranslation("equipNumberTooLargeTitle", "equipment amount too large");
   3.100 -				//MessageBox.Show(ParentForm, amountTooLarge, amountTooLargeTitle);
   3.101 -				equipAmount = maxNumber;
   3.102 -			}
   3.103 -			else if (equipAmount < minNumber)
   3.104 -			{
   3.105 -				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);
   3.106 -				string amountTooSmallTitle = Translation.GetTranslation("equipNumberTooSmallTitle", "equipment amount too small");
   3.107 -				//MessageBox.Show(ParentForm, amountTooSmall, amountTooSmallTitle);
   3.108 -				equipAmount = minNumber;
   3.109 -			}
   3.110 -			
   3.111 -			ui.EquipmentPercentageAmount = CalcualtePercentageValueFromNumber(equipAmount);
   3.112 -			ui.EquipmentNumericAmount = equipAmount;
   3.113 -		}
   3.114 -		
   3.115 -		private double CalcualtePercentageValueFromNumber(int number)
   3.116 -		{
   3.117 -			double calcedAmount = RoundPercentage(CustomMath.IBBMath.Percentage(number, unit.Size));
   3.118 -			return Math.Min(Math.Max(calcedAmount, minPercentage), maxPercentage);
   3.119 -		}
   3.120 -
   3.121 -		//TODO Make abstract
   3.122 -		protected void CreateEquipmentUI()
   3.123 -		{
   3.124 -			ui = new FrmAddEquipment();
   3.125  		}
   3.126  
   3.127  		private void HandleUiUnitEquipmentItemChoiceChanged(UnitEquipmentItem equip)
   3.128 @@ -135,7 +46,7 @@
   3.129  				ui.SetUnitEquipmentLimits(equipIsRatioLimit, minPercentage, maxPercentage, minNumber, maxNumber);
   3.130  				ui.SetUnitEquipmentLimitsEnabled(true);
   3.131  				ui.SetOkayEnabledState(HasNonZeroEquipmentAmount());
   3.132 -				SetEquipmentAmountControlEnabledStates(equipIsRatioLimit);
   3.133 +				SetEquipmentAmountControlEnabledStates();
   3.134  			}
   3.135  			else
   3.136  			{
   3.137 @@ -145,76 +56,18 @@
   3.138  				ui.SetUnitEquipmentLimitsEnabled(false);
   3.139  				ui.SetOkayEnabledState(false);
   3.140  			}
   3.141 -		}		
   3.142 -
   3.143 -		private void SetEquipmentAmountControlEnabledStates(bool ratioLimited)
   3.144 -		{
   3.145 -			ui.SetNumericAmountEnabledState(!ratioLimited);
   3.146 -			ui.SetPercentageAmountEnabledState(true);
   3.147  		}
   3.148  
   3.149 -		private double GetMaxPercentageLimit(UnitEquipmentItem equip)
   3.150 +		protected override void DoProcessing()
   3.151  		{
   3.152 -			double maxPercent = RoundPercentage(UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
   3.153 -			return Math.Max(0, maxPercent);
   3.154 -		}
   3.155 -		
   3.156 -		private double GetMinPercentageLimit(UnitEquipmentItem equip)
   3.157 -		{
   3.158 -			double minPercent = RoundPercentage(UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
   3.159 -			return Math.Max(0, minPercent);
   3.160 -		}
   3.161 -		
   3.162 -		private int GetMaxNumericLimit(UnitEquipmentItem equip)
   3.163 -		{
   3.164 -			int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip);
   3.165 -			return Math.Max(0, maxNumber);
   3.166 -		}
   3.167 -		private int GetMinNumericLimit(UnitEquipmentItem equip)
   3.168 -		{
   3.169 -			int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip);
   3.170 -			return Math.Max(0, minNumber);
   3.171 -		}
   3.172 -
   3.173 -		private bool HasNonZeroEquipmentAmount()
   3.174 -		{
   3.175 -			bool nonZero;
   3.176 -			
   3.177  			if (isRatioAmount)
   3.178  			{
   3.179 -				nonZero = (ui.EquipmentPercentageAmount > 0);
   3.180 +				commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, equipmentAmount));
   3.181  			}
   3.182 -
   3.183  			else
   3.184  			{
   3.185 -				nonZero = (ui.EquipmentNumericAmount > 0);
   3.186 +				commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int)equipmentAmount));
   3.187  			}
   3.188 -			
   3.189 -			return nonZero;
   3.190 -		}
   3.191 -
   3.192 -		private double RoundPercentage(double percent)
   3.193 -		{
   3.194 -			return Math.Round(percent, 1);
   3.195 -		}
   3.196 -
   3.197 -		public void Show()
   3.198 -		{
   3.199 -			bool okayed = ui.ShowControl();
   3.200 -			
   3.201 -			if (okayed)
   3.202 -			{			
   3.203 -				if (isRatioAmount)
   3.204 -				{
   3.205 -					commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, equipmentAmount));
   3.206 -				}
   3.207 -				else
   3.208 -				{
   3.209 -					commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int)equipmentAmount));
   3.210 -				}
   3.211 -			}
   3.212 -			
   3.213 -			ui.Dispose();
   3.214  		}
   3.215  	}
   3.216  }
     4.1 --- a/UIControl/EditEquipmentUIControl.cs	Sat Sep 04 10:25:39 2010 +0000
     4.2 +++ b/UIControl/EditEquipmentUIControl.cs	Sat Sep 04 20:11:05 2010 +0000
     4.3 @@ -12,200 +12,34 @@
     4.4  using IBBoard.WarFoundry.GUI.GTK;
     4.5  namespace IBBoard.WarFoundry.GUI.GTK.UIControl
     4.6  {
     4.7 -	public class EditEquipmentUIControl
     4.8 -	{
     4.9 -		private CommandStack commandStack;
    4.10 -		private IEditEquipmentUI ui;
    4.11 -		private Unit unit;
    4.12 -		private UnitEquipmentItem equipItem;
    4.13 -		private double minPercentage, maxPercentage;
    4.14 -		private int minNumber, maxNumber;
    4.15 -		private bool isRatioAmount;
    4.16 -		private double equipmentAmount;
    4.17 -		
    4.18 -		
    4.19 -		public EditEquipmentUIControl(Unit unit, UnitEquipmentItem item, CommandStack commandStack)
    4.20 +	public class EditEquipmentUIControl : AbstractBaseEquipmentUIControl<IEditEquipmentUI>
    4.21 +	{		
    4.22 +		public EditEquipmentUIControl(Unit unit, UnitEquipmentItem item, CommandStack commandStack) : base(unit, commandStack)
    4.23  		{
    4.24 -			this.unit = unit;
    4.25 -			this.commandStack = commandStack;
    4.26  			this.equipItem = item;
    4.27 -			SetupUI();
    4.28 +		}
    4.29 +
    4.30 +		//TODO Make abstract
    4.31 +		protected override IEditEquipmentUI CreateEquipmentUI()
    4.32 +		{
    4.33 +			return new FrmEditEquipment();
    4.34  		}
    4.35  		
    4.36 -		private void SetupUI()
    4.37 +		protected override void CompleteUISetup()
    4.38  		{
    4.39 -			CreateEquipmentUI();
    4.40 -			ui.SetOkayEnabledState(false);
    4.41 -			isRatioAmount = UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equipItem);
    4.42 -			maxPercentage = GetMaxPercentageLimit(equipItem);
    4.43 -			minPercentage = GetMinPercentageLimit(equipItem);
    4.44 -			maxNumber = GetMaxNumericLimit(equipItem);
    4.45 -			minNumber = GetMinNumericLimit(equipItem);
    4.46 -			
    4.47 -			ui.SetUnitEquipmentLimits(isRatioAmount, minPercentage, maxPercentage, minNumber, maxNumber);
    4.48 -			ui.SetUnitEquipmentLimitsEnabled(true);
    4.49 -			ui.SetOkayEnabledState(false);
    4.50 -			SetEquipmentAmountControlEnabledStates();
    4.51 -			
    4.52 -			if (UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equipItem))
    4.53 +			SetUnitEquipmentValues();
    4.54 +		}
    4.55 +
    4.56 +		protected override void DoProcessing()
    4.57 +		{
    4.58 +			if (isRatioAmount)
    4.59  			{
    4.60 -				SetEquipmentAmountsFromPercentage(UnitEquipmentUtil.GetEquipmentAmount(unit, equipItem));
    4.61 +				commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, equipmentAmount));
    4.62  			}
    4.63  			else
    4.64  			{
    4.65 -				SetEquipmentAmountsFromNumber((int)UnitEquipmentUtil.GetEquipmentAmount(unit, equipItem));
    4.66 +				commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int)equipmentAmount));
    4.67  			}
    4.68 -			
    4.69 -			ui.UnitEquipmentAmountChanged += HandleUnitEquipmentAmountChanged;
    4.70 -			ui.UnitEquipmentAmountTypeChanged += HandleUnitEquipmentAmountChanged;
    4.71 -		}
    4.72 -
    4.73 -		private void HandleUnitEquipmentAmountChanged()
    4.74 -		{
    4.75 -			ui.SetOkayEnabledState(HasNonZeroEquipmentAmount());
    4.76 -			isRatioAmount = ui.IsRatioEquipmentAmount;
    4.77 -			
    4.78 -			if (isRatioAmount)
    4.79 -			{
    4.80 -				equipmentAmount = ui.EquipmentPercentageAmount;
    4.81 -				SetEquipmentAmountsFromPercentage(equipmentAmount);
    4.82 -			}
    4.83 -			else
    4.84 -			{
    4.85 -				int equipmentIntAmount = ui.EquipmentNumericAmount;
    4.86 -				equipmentAmount = equipmentIntAmount;
    4.87 -				SetEquipmentAmountsFromNumber(equipmentIntAmount);
    4.88 -			}
    4.89 -		}
    4.90 -		
    4.91 -		private void SetEquipmentAmountsFromPercentage(double equipAmount)
    4.92 -		{			
    4.93 -			if (equipAmount > maxPercentage)
    4.94 -			{
    4.95 -				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);
    4.96 -				string percentageTooLargeTitle = Translation.GetTranslation("equipPercentageTooLargeTitle", "equipment percentage too large");
    4.97 -				//				MessageBox.Show(ParentForm, percentageTooLarge, percentageTooLargeTitle);
    4.98 -				equipAmount = maxPercentage;
    4.99 -			}
   4.100 -			else if (equipAmount < minPercentage)
   4.101 -			{
   4.102 -				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);
   4.103 -				string percentageTooSmallTitle = Translation.GetTranslation("equipPercentageTooSmallTitle", "equipment percentage too small");
   4.104 -		//				MessageBox.Show(ParentForm, percentageTooSmall, percentageTooSmallTitle);
   4.105 -				equipAmount = minPercentage;
   4.106 -			}
   4.107 -			
   4.108 -			ui.EquipmentNumericAmount = CalculateNumericValueFromPercentage(equipAmount);
   4.109 -			ui.EquipmentPercentageAmount = equipAmount;
   4.110 -		}
   4.111 -		
   4.112 -		private int CalculateNumericValueFromPercentage(double percent)
   4.113 -		{
   4.114 -			int calcedAmount = (int)CustomMath.IBBMath.Round((unit.Size * (percent / 100.0)), equipItem.RoundNumberUp);
   4.115 -			return Math.Min(Math.Max(calcedAmount, minNumber), maxNumber);
   4.116 -		}
   4.117 -
   4.118 -		private void SetEquipmentAmountsFromNumber(int equipAmount)
   4.119 -		{			
   4.120 -			if (equipAmount > maxNumber)
   4.121 -			{
   4.122 -				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);
   4.123 -				string amountTooLargeTitle = Translation.GetTranslation("equipNumberTooLargeTitle", "equipment amount too large");
   4.124 -				//MessageBox.Show(ParentForm, amountTooLarge, amountTooLargeTitle);
   4.125 -				equipAmount = maxNumber;
   4.126 -			}
   4.127 -			else if (equipAmount < minNumber)
   4.128 -			{
   4.129 -				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);
   4.130 -				string amountTooSmallTitle = Translation.GetTranslation("equipNumberTooSmallTitle", "equipment amount too small");
   4.131 -				//MessageBox.Show(ParentForm, amountTooSmall, amountTooSmallTitle);
   4.132 -				equipAmount = minNumber;
   4.133 -			}
   4.134 -			
   4.135 -			ui.EquipmentPercentageAmount = CalcualtePercentageValueFromNumber(equipAmount);
   4.136 -			ui.EquipmentNumericAmount = equipAmount;
   4.137 -		}
   4.138 -		
   4.139 -		private double CalcualtePercentageValueFromNumber(int number)
   4.140 -		{
   4.141 -			double calcedAmount = RoundPercentage(CustomMath.IBBMath.Percentage(number, unit.Size));
   4.142 -			return Math.Min(Math.Max(calcedAmount, minPercentage), maxPercentage);
   4.143 -		}
   4.144 -
   4.145 -		//TODO Make abstract
   4.146 -		protected void CreateEquipmentUI()
   4.147 -		{
   4.148 -			ui = new FrmEditEquipment();
   4.149 -		}
   4.150 -
   4.151 -		private void SetEquipmentAmountControlEnabledStates()
   4.152 -		{
   4.153 -			ui.SetNumericAmountEnabledState(!isRatioAmount);
   4.154 -			ui.SetPercentageAmountEnabledState(true);
   4.155 -		}
   4.156 -
   4.157 -		private double GetMaxPercentageLimit(UnitEquipmentItem equip)
   4.158 -		{
   4.159 -			double maxPercent = RoundPercentage(UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
   4.160 -			return Math.Max(0, maxPercent);
   4.161 -		}
   4.162 -		
   4.163 -		private double GetMinPercentageLimit(UnitEquipmentItem equip)
   4.164 -		{
   4.165 -			double minPercent = RoundPercentage(UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
   4.166 -			return Math.Max(0, minPercent);
   4.167 -		}
   4.168 -		
   4.169 -		private int GetMaxNumericLimit(UnitEquipmentItem equip)
   4.170 -		{
   4.171 -			int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip);
   4.172 -			return Math.Max(0, maxNumber);
   4.173 -		}
   4.174 -		private int GetMinNumericLimit(UnitEquipmentItem equip)
   4.175 -		{
   4.176 -			int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip);
   4.177 -			return Math.Max(0, minNumber);
   4.178 -		}
   4.179 -
   4.180 -		private bool HasNonZeroEquipmentAmount()
   4.181 -		{
   4.182 -			bool nonZero;
   4.183 -			
   4.184 -			if (isRatioAmount)
   4.185 -			{
   4.186 -				nonZero = (ui.EquipmentPercentageAmount > 0);
   4.187 -			}
   4.188 -
   4.189 -			else
   4.190 -			{
   4.191 -				nonZero = (ui.EquipmentNumericAmount > 0);
   4.192 -			}
   4.193 -			
   4.194 -			return nonZero;
   4.195 -		}
   4.196 -
   4.197 -		private double RoundPercentage(double percent)
   4.198 -		{
   4.199 -			return Math.Round(percent, 1);
   4.200 -		}
   4.201 -
   4.202 -		public void Show()
   4.203 -		{
   4.204 -			bool okayed = ui.ShowControl();
   4.205 -			
   4.206 -			if (okayed)
   4.207 -			{			
   4.208 -				if (isRatioAmount)
   4.209 -				{
   4.210 -					commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, equipmentAmount));
   4.211 -				}
   4.212 -				else
   4.213 -				{
   4.214 -					commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int)equipmentAmount));
   4.215 -				}
   4.216 -			}
   4.217 -			
   4.218 -			ui.Dispose();
   4.219  		}
   4.220  	}
   4.221  }
     5.1 --- a/UIControl/Interfaces/IAddEquipmentUI.cs	Sat Sep 04 10:25:39 2010 +0000
     5.2 +++ b/UIControl/Interfaces/IAddEquipmentUI.cs	Sat Sep 04 20:11:05 2010 +0000
     5.3 @@ -8,124 +8,9 @@
     5.4  	/// <summary>
     5.5  	/// The interface that UI components should implement to represent "Add Equipment" dialogs or system equivalents (e.g. console areas or HTML fragments)
     5.6  	/// </summary>
     5.7 -	public interface IAddEquipmentUI : IDisposable
     5.8 +	public interface IAddEquipmentUI : ISelectableItemEquipmentUI
     5.9  	{
    5.10 -		/// <summary>
    5.11 -		/// Should be fired when unit equipment item choice changes.
    5.12 -		/// </summary>
    5.13 -		event SingleArgMethodInvoker<UnitEquipmentItem> UnitEquipmentItemChoiceChanged;
    5.14 -		
    5.15 -		/// <summary>
    5.16 -		/// Occurs when the unit equipment amount type changes (e.g. percentage to numeric)
    5.17 -		/// </summary>
    5.18 -		event MethodInvoker UnitEquipmentAmountTypeChanged;
    5.19 -		
    5.20 -		/// <summary>
    5.21 -		/// Occurs when the unit equipment amount changes
    5.22 -		/// </summary>
    5.23 -		event MethodInvoker UnitEquipmentAmountChanged;
    5.24 -		
    5.25 -		/// <summary>
    5.26 -		/// Sets the equipment items that should be displayed on the form
    5.27 -		/// </summary>
    5.28 -		/// <param name='items'>
    5.29 -		/// The equipment items that should be displayed on the form
    5.30 -		/// </param>
    5.31 -		void SetUnitEquipmentItems(UnitEquipmentItem[] items);
    5.32 -		
    5.33 -		/// <summary>
    5.34 -		/// Sets the limits for the currently selected equipment item
    5.35 -		/// </summary>
    5.36 -		/// <param name='isRatioLimit'>
    5.37 -		/// <code>True</code> if the current limit is a ratio limit, else <code>false</code> for absolute limits
    5.38 -		/// </param>
    5.39 -		/// <param name='minPercent'>
    5.40 -		/// The minimum limit as a percentage
    5.41 -		/// </param>
    5.42 -		/// <param name='maxPercent'>
    5.43 -		/// The maximum limit as a percentage
    5.44 -		/// </param>
    5.45 -		/// <param name='minNumber'>
    5.46 -		/// The minimum number as an absolute figure
    5.47 -		/// </param>
    5.48 -		/// <param name='maxNumber'>
    5.49 -		/// The maximum number as an absolute figure
    5.50 -		/// </param>
    5.51 -		void SetUnitEquipmentLimits(bool isRatioLimit, double minPercent, double maxPercent, int minNumber, int maxNumber);
    5.52 -		
    5.53 -		/// <summary>
    5.54 -		/// Sets whether the unit equipment limit UI components should be enabled and able to accept input. This will 
    5.55 -		/// generally pass the values on to the <see cref="SetNumericAmountEnabledState(bool)"/> and
    5.56 -		/// <see cref="SetPercentageAmountEnabledState(bool)"/> methods and is included for convenience
    5.57 -		/// </summary>
    5.58 -		/// <param name='isEnabled'>
    5.59 -		/// <code>True</code> if the UI components should accept input, else <code>false</code>
    5.60 -		/// </param>
    5.61 -		void SetUnitEquipmentLimitsEnabled(bool isEnabled);
    5.62 -		
    5.63 -		/// <summary>
    5.64 -		/// Shows the control and awaits a user action (close or okay)
    5.65 -		/// </summary>
    5.66 -		/// <returns>
    5.67 -		/// <code>true</code> if the control was closed with "Okay", else <code>false</code>
    5.68 -		/// </returns>
    5.69 -		bool ShowControl();
    5.70 -		
    5.71 -		/// <summary>
    5.72 -		/// Gets the selected equipment item.
    5.73 -		/// </summary>
    5.74 -		/// <value>
    5.75 -		/// The selected equipment item.
    5.76 -		/// </value>
    5.77 -		UnitEquipmentItem SelectedUnitEquipmentItem { get; }
    5.78 -		
    5.79 -		/// <summary>
    5.80 -		/// Gets a value indicating whether the equipment amount is a ratio or an absolute number.
    5.81 -		/// </summary>
    5.82 -		/// <value>
    5.83 -		/// <c>true</c> if the selected amount is a ratio type (percentage or "all"); otherwise, <c>false</c>.
    5.84 -		/// </value>
    5.85 -		bool IsRatioEquipmentAmount { get; }
    5.86 -		
    5.87 -		/// <summary>
    5.88 -		/// Gets and sets the numeric amount for the current equipment amount. This number is meaningless if <see cref="IsRatioEquipmentAmount"/> is <code>true</code>
    5.89 -		/// </summary>
    5.90 -		/// <value>
    5.91 -		/// The absolue number of items taken.
    5.92 -		/// </value>
    5.93 -		int EquipmentNumericAmount { get; set; }
    5.94 -
    5.95 -		/// <summary>
    5.96 -		/// Gets and sets the percentage amount for the current equipment amount. This number is meaningless if <see cref="IsRatioEquipmentAmount"/> is <code>false</code>
    5.97 -		/// </summary>
    5.98 -		/// <value>
    5.99 -		/// The number of items taken as a percentage of the unit size.
   5.100 -		/// </value>
   5.101 -		double EquipmentPercentageAmount { get; set; }
   5.102 -	
   5.103 -		/// <summary>
   5.104 -		/// Sets the state of the Okay button.
   5.105 -		/// </summary>
   5.106 -		/// <param name='enabled'>
   5.107 -		/// <code>true</code> to enable the button, else <code>false</code>
   5.108 -		/// </param>
   5.109 -		void SetOkayEnabledState(bool enabled);
   5.110 -		
   5.111 -		/// <summary>
   5.112 -		/// Sets the state of the numeric equipment amount control.
   5.113 -		/// </summary>
   5.114 -		/// <param name='enabled'>
   5.115 -		/// <code>true</code> to enable the control, else <code>false</code>
   5.116 -		/// </param>
   5.117 -		void SetNumericAmountEnabledState(bool enabled);
   5.118 -		
   5.119 -		/// <summary>
   5.120 -		/// Sets the state of the percentage equipment amount control.
   5.121 -		/// </summary>
   5.122 -		/// <param name='enabled'>
   5.123 -		/// <code>true</code> to enable the control, else <code>false</code>
   5.124 -		/// </param>
   5.125 -		void SetPercentageAmountEnabledState(bool enabled);
   5.126 +		//Marker interface
   5.127  	}
   5.128  }
   5.129  
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/UIControl/Interfaces/IBaseEquipmentUI.cs	Sat Sep 04 20:11:05 2010 +0000
     6.3 @@ -0,0 +1,120 @@
     6.4 +//  This file (IBaseEquipmentUI.cs) is a part of the IBBoard.WarFoundry.GUI.GTK project and is copyright 2010 IBBoard
     6.5 +// 
     6.6 +//  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.
     6.7 +using System;
     6.8 +namespace IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces
     6.9 +{
    6.10 +	/// <summary>
    6.11 +	/// The base interface that all "UI control" controlled interfaces implement. It provides common definitions for all classes
    6.12 +	/// </summary>
    6.13 +	public interface IBaseEquipmentUI : IDisposable
    6.14 +	{
    6.15 +		/// <summary>
    6.16 +		/// Occurs when the unit equipment amount type changes (e.g. percentage to numeric)
    6.17 +		/// </summary>
    6.18 +		event MethodInvoker UnitEquipmentAmountTypeChanged;
    6.19 +
    6.20 +		/// <summary>
    6.21 +		/// Occurs when the unit equipment amount changes
    6.22 +		/// </summary>
    6.23 +		event MethodInvoker UnitEquipmentAmountChanged;
    6.24 +
    6.25 +		/// <summary>
    6.26 +		/// Sets the limits for the currently selected equipment item
    6.27 +		/// </summary>
    6.28 +		/// <param name='isRatioLimit'>
    6.29 +		/// <code>True</code> if the current limit is a ratio limit, else <code>false</code> for absolute limits
    6.30 +		/// </param>
    6.31 +		/// <param name='minPercent'>
    6.32 +		/// The minimum limit as a percentage
    6.33 +		/// </param>
    6.34 +		/// <param name='maxPercent'>
    6.35 +		/// The maximum limit as a percentage
    6.36 +		/// </param>
    6.37 +		/// <param name='minNumber'>
    6.38 +		/// The minimum number as an absolute figure
    6.39 +		/// </param>
    6.40 +		/// <param name='maxNumber'>
    6.41 +		/// The maximum number as an absolute figure
    6.42 +		/// </param>
    6.43 +		void SetUnitEquipmentLimits(bool isRatioLimit, double minPercent, double maxPercent, int minNumber, int maxNumber);
    6.44 +
    6.45 +		/// <summary>
    6.46 +		/// Sets whether the unit equipment limit UI components should be enabled and able to accept input. This will 
    6.47 +		/// generally pass the values on to the <see cref="SetNumericAmountEnabledState(bool)"/> and
    6.48 +		/// <see cref="SetPercentageAmountEnabledState(bool)"/> methods and is included for convenience
    6.49 +		/// </summary>
    6.50 +		/// <param name='isEnabled'>
    6.51 +		/// <code>True</code> if the UI components should accept input, else <code>false</code>
    6.52 +		/// </param>
    6.53 +		void SetUnitEquipmentLimitsEnabled(bool isEnabled);
    6.54 +
    6.55 +		/// <summary>
    6.56 +		/// Shows the control and awaits a user action (close or okay)
    6.57 +		/// </summary>
    6.58 +		/// <returns>
    6.59 +		/// <code>true</code> if the control was closed with "Okay", else <code>false</code>
    6.60 +		/// </returns>
    6.61 +		bool ShowControl();
    6.62 +
    6.63 +		/// <summary>
    6.64 +		/// Gets a value indicating whether the equipment amount is a ratio or an absolute number.
    6.65 +		/// </summary>
    6.66 +		/// <value>
    6.67 +		/// <c>true</c> if the selected amount is a ratio type (percentage or "all"); otherwise, <c>false</c>.
    6.68 +		/// </value>
    6.69 +		bool IsRatioEquipmentAmount
    6.70 +		{
    6.71 +			get;
    6.72 +		}
    6.73 +
    6.74 +		/// <summary>
    6.75 +		/// Gets and sets the numeric amount for the current equipment amount. This number is meaningless if <see cref="IsRatioEquipmentAmount"/> is <code>true</code>
    6.76 +		/// </summary>
    6.77 +		/// <value>
    6.78 +		/// The absolue number of items taken.
    6.79 +		/// </value>
    6.80 +		int EquipmentNumericAmount
    6.81 +		{
    6.82 +			get;
    6.83 +			set;
    6.84 +		}
    6.85 +
    6.86 +		/// <summary>
    6.87 +		/// Gets and sets the percentage amount for the current equipment amount. This number is meaningless if <see cref="IsRatioEquipmentAmount"/> is <code>false</code>
    6.88 +		/// </summary>
    6.89 +		/// <value>
    6.90 +		/// The number of items taken as a percentage of the unit size.
    6.91 +		/// </value>
    6.92 +		double EquipmentPercentageAmount
    6.93 +		{
    6.94 +			get;
    6.95 +			set;
    6.96 +		}
    6.97 +
    6.98 +		/// <summary>
    6.99 +		/// Sets the state of the Okay button.
   6.100 +		/// </summary>
   6.101 +		/// <param name='enabled'>
   6.102 +		/// <code>true</code> to enable the button, else <code>false</code>
   6.103 +		/// </param>
   6.104 +		void SetOkayEnabledState(bool enabled);
   6.105 +
   6.106 +		/// <summary>
   6.107 +		/// Sets the state of the numeric equipment amount control.
   6.108 +		/// </summary>
   6.109 +		/// <param name='enabled'>
   6.110 +		/// <code>true</code> to enable the control, else <code>false</code>
   6.111 +		/// </param>
   6.112 +		void SetNumericAmountEnabledState(bool enabled);
   6.113 +
   6.114 +		/// <summary>
   6.115 +		/// Sets the state of the percentage equipment amount control.
   6.116 +		/// </summary>
   6.117 +		/// <param name='enabled'>
   6.118 +		/// <code>true</code> to enable the control, else <code>false</code>
   6.119 +		/// </param>
   6.120 +		void SetPercentageAmountEnabledState(bool enabled);
   6.121 +	}
   6.122 +}
   6.123 +
     7.1 --- a/UIControl/Interfaces/IEditEquipmentUI.cs	Sat Sep 04 10:25:39 2010 +0000
     7.2 +++ b/UIControl/Interfaces/IEditEquipmentUI.cs	Sat Sep 04 20:11:05 2010 +0000
     7.3 @@ -8,103 +8,9 @@
     7.4  	/// <summary>
     7.5  	/// The interface that UI components should implement to represent "Edit Equipment" dialogs or system equivalents (e.g. console areas or HTML fragments)
     7.6  	/// </summary>
     7.7 -	public interface IEditEquipmentUI : IDisposable
     7.8 -	{		
     7.9 -		/// <summary>
    7.10 -		/// Occurs when the unit equipment amount type changes (e.g. percentage to numeric)
    7.11 -		/// </summary>
    7.12 -		event MethodInvoker UnitEquipmentAmountTypeChanged;
    7.13 -		
    7.14 -		/// <summary>
    7.15 -		/// Occurs when the unit equipment amount changes
    7.16 -		/// </summary>
    7.17 -		event MethodInvoker UnitEquipmentAmountChanged;
    7.18 -				
    7.19 -		/// <summary>
    7.20 -		/// Sets the limits for the currently selected equipment item
    7.21 -		/// </summary>
    7.22 -		/// <param name='isRatioLimit'>
    7.23 -		/// <code>True</code> if the current limit is a ratio limit, else <code>false</code> for absolute limits
    7.24 -		/// </param>
    7.25 -		/// <param name='minPercent'>
    7.26 -		/// The minimum limit as a percentage
    7.27 -		/// </param>
    7.28 -		/// <param name='maxPercent'>
    7.29 -		/// The maximum limit as a percentage
    7.30 -		/// </param>
    7.31 -		/// <param name='minNumber'>
    7.32 -		/// The minimum number as an absolute figure
    7.33 -		/// </param>
    7.34 -		/// <param name='maxNumber'>
    7.35 -		/// The maximum number as an absolute figure
    7.36 -		/// </param>
    7.37 -		void SetUnitEquipmentLimits(bool isRatioLimit, double minPercent, double maxPercent, int minNumber, int maxNumber);
    7.38 -		
    7.39 -		/// <summary>
    7.40 -		/// Sets whether the unit equipment limit UI components should be enabled and able to accept input. This will 
    7.41 -		/// generally pass the values on to the <see cref="SetNumericAmountEnabledState(bool)"/> and
    7.42 -		/// <see cref="SetPercentageAmountEnabledState(bool)"/> methods and is included for convenience
    7.43 -		/// </summary>
    7.44 -		/// <param name='isEnabled'>
    7.45 -		/// <code>True</code> if the UI components should accept input, else <code>false</code>
    7.46 -		/// </param>
    7.47 -		void SetUnitEquipmentLimitsEnabled(bool isEnabled);
    7.48 -		
    7.49 -		/// <summary>
    7.50 -		/// Shows the control and awaits a user action (close or okay)
    7.51 -		/// </summary>
    7.52 -		/// <returns>
    7.53 -		/// <code>true</code> if the control was closed with "Okay", else <code>false</code>
    7.54 -		/// </returns>
    7.55 -		bool ShowControl();
    7.56 -				
    7.57 -		/// <summary>
    7.58 -		/// Gets a value indicating whether the equipment amount is a ratio or an absolute number.
    7.59 -		/// </summary>
    7.60 -		/// <value>
    7.61 -		/// <c>true</c> if the selected amount is a ratio type (percentage or "all"); otherwise, <c>false</c>.
    7.62 -		/// </value>
    7.63 -		bool IsRatioEquipmentAmount { get; }
    7.64 -		
    7.65 -		/// <summary>
    7.66 -		/// Gets and sets the numeric amount for the current equipment amount. This number is meaningless if <see cref="IsRatioEquipmentAmount"/> is <code>true</code>
    7.67 -		/// </summary>
    7.68 -		/// <value>
    7.69 -		/// The absolue number of items taken.
    7.70 -		/// </value>
    7.71 -		int EquipmentNumericAmount { get; set; }
    7.72 -
    7.73 -		/// <summary>
    7.74 -		/// Gets and sets the percentage amount for the current equipment amount. This number is meaningless if <see cref="IsRatioEquipmentAmount"/> is <code>false</code>
    7.75 -		/// </summary>
    7.76 -		/// <value>
    7.77 -		/// The number of items taken as a percentage of the unit size.
    7.78 -		/// </value>
    7.79 -		double EquipmentPercentageAmount { get; set; }
    7.80 -	
    7.81 -		/// <summary>
    7.82 -		/// Sets the state of the Okay button.
    7.83 -		/// </summary>
    7.84 -		/// <param name='enabled'>
    7.85 -		/// <code>true</code> to enable the button, else <code>false</code>
    7.86 -		/// </param>
    7.87 -		void SetOkayEnabledState(bool enabled);
    7.88 -		
    7.89 -		/// <summary>
    7.90 -		/// Sets the state of the numeric equipment amount control.
    7.91 -		/// </summary>
    7.92 -		/// <param name='enabled'>
    7.93 -		/// <code>true</code> to enable the control, else <code>false</code>
    7.94 -		/// </param>
    7.95 -		void SetNumericAmountEnabledState(bool enabled);
    7.96 -		
    7.97 -		/// <summary>
    7.98 -		/// Sets the state of the percentage equipment amount control.
    7.99 -		/// </summary>
   7.100 -		/// <param name='enabled'>
   7.101 -		/// <code>true</code> to enable the control, else <code>false</code>
   7.102 -		/// </param>
   7.103 -		void SetPercentageAmountEnabledState(bool enabled);
   7.104 +	public interface IEditEquipmentUI : IBaseEquipmentUI
   7.105 +	{
   7.106 +		//Marker interface
   7.107  	}
   7.108  }
   7.109  
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/UIControl/Interfaces/ISelectableItemEquipmentUI.cs	Sat Sep 04 20:11:05 2010 +0000
     8.3 @@ -0,0 +1,38 @@
     8.4 +//  This file (ISelectableItemEquipmentUI.cs) is a part of the IBBoard.WarFoundry.GUI.GTK project and is copyright 2010 IBBoard
     8.5 +// 
     8.6 +//  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.
     8.7 +using System;
     8.8 +using IBBoard.WarFoundry.API.Objects;
     8.9 +namespace IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces
    8.10 +{
    8.11 +	/// <summary>
    8.12 +	/// 
    8.13 +	/// </summary>
    8.14 +	public interface ISelectableItemEquipmentUI : IBaseEquipmentUI
    8.15 +	{
    8.16 +		/// <summary>
    8.17 +		/// Should be fired when unit equipment item choice changes.
    8.18 +		/// </summary>
    8.19 +		event SingleArgMethodInvoker<UnitEquipmentItem> UnitEquipmentItemChoiceChanged;
    8.20 +
    8.21 +		/// <summary>
    8.22 +		/// Sets the equipment items that should be displayed on the form
    8.23 +		/// </summary>
    8.24 +		/// <param name='items'>
    8.25 +		/// The equipment items that should be displayed on the form
    8.26 +		/// </param>
    8.27 +		void SetUnitEquipmentItems(UnitEquipmentItem[] items);
    8.28 +
    8.29 +		/// <summary>
    8.30 +		/// Gets the selected equipment item.
    8.31 +		/// </summary>
    8.32 +		/// <value>
    8.33 +		/// The selected equipment item.
    8.34 +		/// </value>
    8.35 +		UnitEquipmentItem SelectedUnitEquipmentItem
    8.36 +		{
    8.37 +			get;
    8.38 +		}
    8.39 +	}
    8.40 +}
    8.41 +
     9.1 --- a/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmAddEquipment.cs	Sat Sep 04 10:25:39 2010 +0000
     9.2 +++ b/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmAddEquipment.cs	Sat Sep 04 20:11:05 2010 +0000
     9.3 @@ -135,6 +135,7 @@
     9.4  			this.rbEquipAll = new global::Gtk.RadioButton("");
     9.5  			this.rbEquipAll.CanFocus = true;
     9.6  			this.rbEquipAll.Name = "rbEquipAll";
     9.7 +			this.rbEquipAll.Active = true;
     9.8  			this.rbEquipAll.DrawIndicator = true;
     9.9  			this.rbEquipAll.UseUnderline = true;
    9.10  			this.rbEquipAll.Group = new global::GLib.SList(global::System.IntPtr.Zero);