changeset 56:0c5fbb54bfb0

Re #60: Add UI to add/remove/edit weapons in GTK * Refactor enabling/disabling of radio buttons * Handle null selections * Move Dispose() to be an interface method and move call out to controller
author IBBoard <dev@ibboard.co.uk>
date Wed, 25 Aug 2010 20:04:27 +0000
parents eb7db8495bb5
children 293d204e40db
files FrmAddEquipment.cs UIControl/AddEquipmentUIControl.cs UIControl/Interfaces/IAddEquipmentUI.cs gtk-gui/gui.stetic
diffstat 4 files changed, 60 insertions(+), 15 deletions(-) [+]
line diff
     1.1 --- a/FrmAddEquipment.cs	Wed Aug 25 19:51:23 2010 +0000
     1.2 +++ b/FrmAddEquipment.cs	Wed Aug 25 20:04:27 2010 +0000
     1.3 @@ -17,6 +17,9 @@
     1.4  		
     1.5  		public event SingleArgMethodInvoker<UnitEquipmentItem> UnitEquipmentItemChoiceChanged;
     1.6  		
     1.7 +		private bool limitsEnabled = false;
     1.8 +		private bool ratioLimited = false;
     1.9 +		
    1.10  		public FrmAddEquipment()
    1.11  		{
    1.12  			this.Build();
    1.13 @@ -52,14 +55,26 @@
    1.14  		public void SetUnitEquipmentLimits(bool isRatioLimit, double minPercent, double maxPercent, int minNumber, int maxNumber)
    1.15  		{
    1.16  			log.DebugFormat("IsRatio? {0}. Limits: {1}->{2}, {3}%->{4}%", isRatioLimit, minNumber, maxNumber, minPercent, maxPercent);
    1.17 -			rbEquipNumeric.Sensitive = isRatioLimit;
    1.18 -			numericAmount.Sensitive = isRatioLimit;
    1.19 +			ratioLimited = isRatioLimit;
    1.20 +			SetEnabledState();
    1.21  			numericAmount.SetRange(minNumber, maxNumber);
    1.22  			percentageAmount.SetRange(minPercent, maxPercent);
    1.23  		}
    1.24  
    1.25  		public void SetUnitEquipmentLimitsEnabled(bool isEnabled)
    1.26  		{
    1.27 +			limitsEnabled = isEnabled;
    1.28 +			SetEnabledState();
    1.29 +		}
    1.30 +		
    1.31 +		private void SetEnabledState()
    1.32 +		{
    1.33 +			rbEquipNumeric.Sensitive = (limitsEnabled && ratioLimited);
    1.34 +			numericAmount.Sensitive = (limitsEnabled && ratioLimited);
    1.35 +			rbEquipPercent.Sensitive = limitsEnabled;
    1.36 +			percentageAmount.Sensitive = limitsEnabled;
    1.37 +			rbEquipAll.Sensitive = limitsEnabled;
    1.38 +			lblEquipAll.Sensitive = limitsEnabled;
    1.39  		}
    1.40  
    1.41  		public bool ShowControl()
    1.42 @@ -67,7 +82,6 @@
    1.43  			int result = Run();
    1.44  			bool okayClicked = (result == (int)ResponseType.Ok);
    1.45  			this.Hide();
    1.46 -			this.Dispose();
    1.47  			return okayClicked;
    1.48  		}
    1.49  		
    1.50 @@ -75,6 +89,12 @@
    1.51  		{
    1.52  			log.Debug("Cancel clicked");
    1.53  			Respond(ResponseType.Cancel);
    1.54 +		}	
    1.55 +		
    1.56 +		protected virtual void OkayButtonClicked(object sender, System.EventArgs e)
    1.57 +		{
    1.58 +			log.Debug("Okay clicked");
    1.59 +			Respond(ResponseType.Ok);
    1.60  		}		
    1.61  	}
    1.62  }
     2.1 --- a/UIControl/AddEquipmentUIControl.cs	Wed Aug 25 19:51:23 2010 +0000
     2.2 +++ b/UIControl/AddEquipmentUIControl.cs	Wed Aug 25 20:04:27 2010 +0000
     2.3 @@ -24,6 +24,7 @@
     2.4  		private void SetupUI()
     2.5  		{
     2.6  			CreateEquipmentUI();
     2.7 +			ui.SetUnitEquipmentLimitsEnabled(false);
     2.8  			UnitEquipmentItem[] items = Arrays.Subtract(UnitEquipmentUtil.GetAllowedEquipmentItems(unit), unit.GetEquipment());
     2.9  			ui.SetUnitEquipmentItems(items);
    2.10  			ui.UnitEquipmentItemChoiceChanged += HandleUiUnitEquipmentItemChoiceChanged;
    2.11 @@ -37,28 +38,38 @@
    2.12  
    2.13  		private void HandleUiUnitEquipmentItemChoiceChanged(UnitEquipmentItem equip)
    2.14  		{
    2.15 -			bool equipIsRatioLimit = UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip);
    2.16 -			double maxPercent = RoundPercentage(UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
    2.17 -			maxPercent = Math.Max(0, maxPercent);
    2.18 -			double minPercent = RoundPercentage(UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
    2.19 -			minPercent = Math.Max(0, minPercent);
    2.20 -			int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip);
    2.21 -			maxNumber = Math.Max(0, maxNumber);
    2.22 -			int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip);
    2.23 -			minNumber = Math.Max(0, minNumber);
    2.24 +			if (equip != null)
    2.25 +			{
    2.26 +				bool equipIsRatioLimit = UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip);
    2.27 +				double maxPercent = RoundPercentage(UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
    2.28 +				maxPercent = Math.Max(0, maxPercent);
    2.29 +				double minPercent = RoundPercentage(UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
    2.30 +				minPercent = Math.Max(0, minPercent);
    2.31 +				int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip);
    2.32 +				maxNumber = Math.Max(0, maxNumber);
    2.33 +				int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip);
    2.34 +				minNumber = Math.Max(0, minNumber);
    2.35  			
    2.36 -			ui.SetUnitEquipmentLimits(equipIsRatioLimit, minPercent, maxPercent, minNumber, maxNumber);
    2.37 -			
    2.38 +				ui.SetUnitEquipmentLimits(equipIsRatioLimit, minPercent, maxPercent, minNumber, maxNumber);
    2.39 +				ui.SetUnitEquipmentLimitsEnabled(true);
    2.40 +			}
    2.41 +			else
    2.42 +			{
    2.43 +				ui.SetUnitEquipmentLimits(true, 0, 0, 0, 0);
    2.44 +				ui.SetUnitEquipmentLimitsEnabled(false);
    2.45 +			}
    2.46  		}
    2.47  		
    2.48  		private double RoundPercentage(double percent)
    2.49  		{
    2.50  			return Math.Round(percent, 1);
    2.51  		}
    2.52 -		
    2.53 +
    2.54  		public void Show()
    2.55  		{
    2.56  			ui.ShowControl();
    2.57 +			//Do command stuff here
    2.58 +			ui.Dispose();
    2.59  		}
    2.60  	}
    2.61  }
     3.1 --- a/UIControl/Interfaces/IAddEquipmentUI.cs	Wed Aug 25 19:51:23 2010 +0000
     3.2 +++ b/UIControl/Interfaces/IAddEquipmentUI.cs	Wed Aug 25 20:04:27 2010 +0000
     3.3 @@ -58,6 +58,19 @@
     3.4  		/// <code>true</code> if the control was closed with "Okay", else <code>false</code>
     3.5  		/// </returns>
     3.6  		bool ShowControl();
     3.7 +	
     3.8 +		/// <summary>
     3.9 +		/// Releases all resource used by the <see cref="IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces.IAddEquipmentUI"/> object.
    3.10 +		/// </summary>
    3.11 +		/// <remarks>
    3.12 +		/// Call <see cref="Dispose"/> when you are finished using the
    3.13 +		/// <see cref="IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces.IAddEquipmentUI"/>. The <see cref="Dispose"/> method
    3.14 +		/// leaves the <see cref="IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces.IAddEquipmentUI"/> in an unusable state.
    3.15 +		/// After calling <see cref="Dispose"/>, you must release all references to the
    3.16 +		/// <see cref="IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces.IAddEquipmentUI"/> so the garbage collector can reclaim
    3.17 +		/// the memory that the <see cref="IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces.IAddEquipmentUI"/> was occupying.
    3.18 +		/// </remarks>
    3.19 +		void Dispose();
    3.20  	}
    3.21  }
    3.22  
     4.1 --- a/gtk-gui/gui.stetic	Wed Aug 25 19:51:23 2010 +0000
     4.2 +++ b/gtk-gui/gui.stetic	Wed Aug 25 20:04:27 2010 +0000
     4.3 @@ -1289,6 +1289,7 @@
     4.4              <property name="Type">StockItem</property>
     4.5              <property name="StockId">gtk-ok</property>
     4.6              <property name="ResponseId">-5</property>
     4.7 +            <signal name="Clicked" handler="OkayButtonClicked" />
     4.8              <property name="label">gtk-ok</property>
     4.9            </widget>
    4.10            <packing>