changeset 34:3ceb0efd261f

Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts * Use new commands created in previous revision Re #122: Make usage of percentage or ratio common * Make sure all usage of percentages are correct Re #117: Add percentage and number boxes to equipment item dialogs * Fix some enable/disable inconsistencies for percentage amounts * Fix problems where fixed limits weren't honoured by widgets
author IBBoard <dev@ibboard.co.uk>
date Thu, 13 Aug 2009 21:16:21 +0000
parents 67c283ea77a7
children 27b1837c837e
files FrmEditUnitEquipment.cs FrmNewUnitEquipment.cs FrmReplaceUnitEquipment.cs FrmUnit.cs Util/UnitEquipmentChoice.cs
diffstat 5 files changed, 302 insertions(+), 288 deletions(-) [+]
line diff
     1.1 --- a/FrmEditUnitEquipment.cs	Sun Aug 09 12:05:24 2009 +0000
     1.2 +++ b/FrmEditUnitEquipment.cs	Thu Aug 13 21:16:21 2009 +0000
     1.3 @@ -46,9 +46,9 @@
     1.4  
     1.5  			if (equipItem.IsRatioLimit)
     1.6  			{
     1.7 -				numEquipAmount.Minimum = (decimal)Math.Round(equipItem.MinNumber * 100.0, 2);
     1.8 -				numEquipAmount.Maximum = (decimal)Math.Round(equipItem.MaxNumber * 100.0, 2);
     1.9 -				numEquipAmount.Value = (decimal)Math.Round(equipAmount * 100, 2);
    1.10 +				numEquipAmount.Minimum = (decimal)Math.Round(equipItem.MinPercentage, 2);
    1.11 +				numEquipAmount.Maximum = (decimal)Math.Round(equipItem.MaxPercentage, 2);
    1.12 +				numEquipAmount.Value = (decimal)Math.Round(equipAmount, 2);
    1.13  				cbEquipAll.Enabled = false;
    1.14  				lblPercent.Visible = true;
    1.15  				numEquipAmount.Width = 120;
    1.16 @@ -210,18 +210,18 @@
    1.17  			{
    1.18  				if (equipAmount != WarFoundryCore.INFINITY)
    1.19  				{
    1.20 -					commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, WarFoundryCore.INFINITY));
    1.21 +					commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, WarFoundryCore.INFINITY));
    1.22  				}
    1.23  			}
    1.24  			else if (numEquipAmount.Value != (decimal)equipAmount)
    1.25  			{
    1.26  				if (equipItem.IsRatioLimit)
    1.27  				{
    1.28 -					commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, ((double)numEquipAmount.Value / 100.0)));
    1.29 +					commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, (double)numEquipAmount.Value));
    1.30  				}
    1.31  				else
    1.32 -				{
    1.33 -					commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, (double)numEquipAmount.Value));
    1.34 +				{
    1.35 +					commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int)numEquipAmount.Value));
    1.36  				}
    1.37  			}
    1.38  
     2.1 --- a/FrmNewUnitEquipment.cs	Sun Aug 09 12:05:24 2009 +0000
     2.2 +++ b/FrmNewUnitEquipment.cs	Thu Aug 13 21:16:21 2009 +0000
     2.3 @@ -1,272 +1,276 @@
     2.4 -// This file (FrmNewUnitEquipment.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard.
     2.5 -//
     2.6 -// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
     2.7 -
     2.8 -using System;
     2.9 -using System.Drawing;
    2.10 -using System.Collections;
    2.11 -using System.ComponentModel;
    2.12 -using System.Windows.Forms;
    2.13 -using IBBoard;
    2.14 -using IBBoard.Commands;
    2.15 -using IBBoard.WarFoundry.API;
    2.16 -using IBBoard.WarFoundry.API.Commands;
    2.17 -using IBBoard.WarFoundry.API.Objects;
    2.18 -
    2.19 -namespace IBBoard.WarFoundry
    2.20 -{
    2.21 -	/// <summary>
    2.22 -	/// Summary description for FrmNewUnitEquipment.
    2.23 -	/// </summary>
    2.24 -	public class FrmNewUnitEquipment : System.Windows.Forms.Form
    2.25 -	{
    2.26 -		private Unit unit;
    2.27 -		private bool required;
    2.28 -		private CommandStack commandStack;
    2.29 -
    2.30 -		private System.Windows.Forms.NumericUpDown numEquipAmount;
    2.31 -		private System.Windows.Forms.Label lblPercent;
    2.32 -		private System.Windows.Forms.Label lblAmount;
    2.33 -		private System.Windows.Forms.Button bttnCancel;
    2.34 -		private System.Windows.Forms.Button bttnOkay;
    2.35 -		private System.Windows.Forms.CheckBox cbEquipAll;
    2.36 -		private System.Windows.Forms.Label lblItem;
    2.37 -		private System.Windows.Forms.ListBox listItems;
    2.38 -		/// <summary>
    2.39 -		/// Required designer variable.
    2.40 -		/// </summary>
    2.41 -		private System.ComponentModel.Container components = null;
    2.42 -
    2.43 -		public FrmNewUnitEquipment(Unit unit, CommandStack stack)
    2.44 -		{
    2.45 -			commandStack = stack;
    2.46 -			this.unit = unit;
    2.47 -			InitializeComponent();
    2.48 -			this.Text = "New equipment for " + unit.Name;
    2.49 -			object[] items = Arrays.Subtract(unit.GetAllowedOptionalEquipment(), unit.GetEquipment());
    2.50 -			listItems.Items.AddRange(items);
    2.51 -		}
    2.52 -
    2.53 -		/// <summary>
    2.54 -		/// Clean up any resources being used.
    2.55 -		/// </summary>
    2.56 -		protected override void Dispose( bool disposing )
    2.57 -		{
    2.58 -			if( disposing )
    2.59 -			{
    2.60 -				if(components != null)
    2.61 -				{
    2.62 -					components.Dispose();
    2.63 -				}
    2.64 -			}
    2.65 -			base.Dispose( disposing );
    2.66 -		}
    2.67 -
    2.68 -		#region Windows Form Designer generated code
    2.69 -		/// <summary>
    2.70 -		/// Required method for Designer support - do not modify
    2.71 -		/// the contents of this method with the code editor.
    2.72 -		/// </summary>
    2.73 -		private void InitializeComponent()
    2.74 -		{
    2.75 -			this.numEquipAmount = new System.Windows.Forms.NumericUpDown();
    2.76 -			this.lblPercent = new System.Windows.Forms.Label();
    2.77 -			this.lblAmount = new System.Windows.Forms.Label();
    2.78 -			this.bttnCancel = new System.Windows.Forms.Button();
    2.79 -			this.bttnOkay = new System.Windows.Forms.Button();
    2.80 -			this.cbEquipAll = new System.Windows.Forms.CheckBox();
    2.81 -			this.lblItem = new System.Windows.Forms.Label();
    2.82 -			this.listItems = new System.Windows.Forms.ListBox();
    2.83 -			((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).BeginInit();
    2.84 -			this.SuspendLayout();
    2.85 -			// 
    2.86 -			// numEquipAmount
    2.87 -			// 
    2.88 -			this.numEquipAmount.Enabled = false;
    2.89 -			this.numEquipAmount.Location = new System.Drawing.Point(88, 80);
    2.90 -			this.numEquipAmount.Name = "numEquipAmount";
    2.91 -			this.numEquipAmount.Size = new System.Drawing.Size(144, 20);
    2.92 -			this.numEquipAmount.TabIndex = 0;
    2.93 -			this.numEquipAmount.ValueChanged += new System.EventHandler(this.numEquipAmount_ValueChanged);
    2.94 -			// 
    2.95 -			// lblPercent
    2.96 -			// 
    2.97 -			this.lblPercent.Location = new System.Drawing.Point(208, 80);
    2.98 -			this.lblPercent.Name = "lblPercent";
    2.99 -			this.lblPercent.Size = new System.Drawing.Size(16, 16);
   2.100 -			this.lblPercent.TabIndex = 1;
   2.101 -			this.lblPercent.Text = "%";
   2.102 -			this.lblPercent.Visible = false;
   2.103 -			// 
   2.104 -			// lblAmount
   2.105 -			// 
   2.106 -			this.lblAmount.Location = new System.Drawing.Point(8, 80);
   2.107 -			this.lblAmount.Name = "lblAmount";
   2.108 -			this.lblAmount.Size = new System.Drawing.Size(72, 23);
   2.109 -			this.lblAmount.TabIndex = 2;
   2.110 -			this.lblAmount.Text = "amount";
   2.111 -			this.lblAmount.TextAlign = System.Drawing.ContentAlignment.TopRight;
   2.112 -			// 
   2.113 -			// bttnCancel
   2.114 -			// 
   2.115 -			this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
   2.116 -			this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
   2.117 -			this.bttnCancel.Location = new System.Drawing.Point(160, 136);
   2.118 -			this.bttnCancel.Name = "bttnCancel";
   2.119 -			this.bttnCancel.TabIndex = 3;
   2.120 -			this.bttnCancel.Text = "cancel";
   2.121 -			this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click);
   2.122 -			// 
   2.123 -			// bttnOkay
   2.124 -			// 
   2.125 -			this.bttnOkay.Enabled = false;
   2.126 -			this.bttnOkay.FlatStyle = System.Windows.Forms.FlatStyle.System;
   2.127 -			this.bttnOkay.Location = new System.Drawing.Point(8, 136);
   2.128 -			this.bttnOkay.Name = "bttnOkay";
   2.129 -			this.bttnOkay.TabIndex = 4;
   2.130 -			this.bttnOkay.Text = "okay";
   2.131 -			this.bttnOkay.Click += new System.EventHandler(this.bttnOkay_Click);
   2.132 -			// 
   2.133 -			// cbEquipAll
   2.134 -			// 
   2.135 -			this.cbEquipAll.Enabled = false;
   2.136 -			this.cbEquipAll.FlatStyle = System.Windows.Forms.FlatStyle.System;
   2.137 -			this.cbEquipAll.Location = new System.Drawing.Point(88, 104);
   2.138 -			this.cbEquipAll.Name = "cbEquipAll";
   2.139 -			this.cbEquipAll.TabIndex = 5;
   2.140 -			this.cbEquipAll.Text = "equip all";
   2.141 -			this.cbEquipAll.CheckedChanged += new System.EventHandler(this.cbEquipAll_CheckedChanged);
   2.142 -			// 
   2.143 -			// lblItem
   2.144 -			// 
   2.145 -			this.lblItem.Location = new System.Drawing.Point(0, 8);
   2.146 -			this.lblItem.Name = "lblItem";
   2.147 -			this.lblItem.Size = new System.Drawing.Size(80, 23);
   2.148 -			this.lblItem.TabIndex = 6;
   2.149 -			this.lblItem.Text = "item";
   2.150 -			this.lblItem.TextAlign = System.Drawing.ContentAlignment.TopRight;
   2.151 -			// 
   2.152 -			// listItems
   2.153 -			// 
   2.154 -			this.listItems.Location = new System.Drawing.Point(88, 8);
   2.155 -			this.listItems.Name = "listItems";
   2.156 -			this.listItems.Size = new System.Drawing.Size(144, 69);
   2.157 -			this.listItems.TabIndex = 7;
   2.158 -			this.listItems.SelectedIndexChanged += new System.EventHandler(this.listItems_SelectedIndexChanged);
   2.159 -			// 
   2.160 -			// FrmNewUnitEquipment
   2.161 -			// 
   2.162 -			this.AcceptButton = this.bttnOkay;
   2.163 -			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
   2.164 -			this.CancelButton = this.bttnCancel;
   2.165 -			this.ClientSize = new System.Drawing.Size(240, 164);
   2.166 -			this.ControlBox = false;
   2.167 -			this.Controls.Add(this.listItems);
   2.168 -			this.Controls.Add(this.lblItem);
   2.169 -			this.Controls.Add(this.cbEquipAll);
   2.170 -			this.Controls.Add(this.bttnOkay);
   2.171 -			this.Controls.Add(this.bttnCancel);
   2.172 -			this.Controls.Add(this.lblAmount);
   2.173 -			this.Controls.Add(this.numEquipAmount);
   2.174 -			this.Controls.Add(this.lblPercent);
   2.175 -			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
   2.176 -			this.Name = "FrmNewUnitEquipment";
   2.177 -			this.ShowInTaskbar = false;
   2.178 -			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
   2.179 -			this.Text = "FrmEditUnitEquipment";
   2.180 -			((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).EndInit();
   2.181 -			this.ResumeLayout(false);
   2.182 -
   2.183 -		}
   2.184 -		#endregion
   2.185 -
   2.186 -		private void bttnOkay_Click(object sender, System.EventArgs e)
   2.187 -		{
   2.188 -			setValue();
   2.189 -			this.Close();
   2.190 -		}
   2.191 -
   2.192 -		private void setValue()
   2.193 -		{
   2.194 -			UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem;
   2.195 -
   2.196 -			if (cbEquipAll.Checked)
   2.197 -			{
   2.198 -				commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, WarFoundryCore.INFINITY));
   2.199 -			}
   2.200 -			else
   2.201 -			{
   2.202 -				if (equipItem.IsRatioLimit)
   2.203 -				{
   2.204 -					commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, (double)numEquipAmount.Value / 100.0));
   2.205 -				}
   2.206 -				else
   2.207 -				{
   2.208 -					commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, (double)numEquipAmount.Value));
   2.209 -				}
   2.210 -			}
   2.211 -		}
   2.212 -
   2.213 -		private void bttnCancel_Click(object sender, System.EventArgs e)
   2.214 -		{
   2.215 -			this.Close();
   2.216 -		}
   2.217 -
   2.218 -		private void cbEquipAll_CheckedChanged(object sender, System.EventArgs e)
   2.219 -		{
   2.220 -			numEquipAmount.Enabled = ((UnitEquipmentItem)listItems.SelectedItem).MinNumber != WarFoundryCore.INFINITY && !cbEquipAll.Checked;
   2.221 -			setOkayButton();
   2.222 -		}
   2.223 -
   2.224 -		private void listItems_SelectedIndexChanged(object sender, System.EventArgs e)
   2.225 -		{
   2.226 -			refreshNumber();
   2.227 -			setOkayButton();
   2.228 -		}
   2.229 -
   2.230 -		private void refreshNumber()
   2.231 -		{
   2.232 -			if (listItems.SelectedIndex > -1)
   2.233 -			{
   2.234 -				UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem;
   2.235 -				required = equipItem.IsRequired;
   2.236 -
   2.237 -				if (equipItem.IsRatioLimit)
   2.238 -				{
   2.239 -					numEquipAmount.Minimum = (decimal)Math.Round(equipItem.MinNumber * 100.0, 2);
   2.240 -					numEquipAmount.Maximum = (decimal)Math.Round(equipItem.MaxNumber * 100.0, 2);
   2.241 -					numEquipAmount.Value = numEquipAmount.Minimum;
   2.242 -					cbEquipAll.Enabled = false;
   2.243 -					lblPercent.Visible = true;
   2.244 -					numEquipAmount.Width = 120;
   2.245 -				}
   2.246 -				else
   2.247 -				{
   2.248 -					numEquipAmount.Minimum = (decimal)(equipItem.MinNumber != WarFoundryCore.INFINITY ? equipItem.MinNumber : unit.Size);
   2.249 -					numEquipAmount.Maximum = (decimal)(equipItem.MaxNumber != WarFoundryCore.INFINITY ? equipItem.MaxNumber : unit.Size);
   2.250 -					numEquipAmount.Value = numEquipAmount.Minimum;
   2.251 -					cbEquipAll.Enabled = equipItem.MinNumber != WarFoundryCore.INFINITY;
   2.252 -					cbEquipAll.Checked = equipItem.MinNumber == WarFoundryCore.INFINITY;
   2.253 -					numEquipAmount.Width = 144;
   2.254 -				}
   2.255 -			}
   2.256 -			else
   2.257 -			{
   2.258 -				numEquipAmount.Minimum = 0;
   2.259 -				numEquipAmount.Value = 0;
   2.260 -				numEquipAmount.Enabled = false;
   2.261 -				cbEquipAll.Enabled = false;
   2.262 -			}
   2.263 -		}
   2.264 -
   2.265 -		private void setOkayButton()
   2.266 -		{
   2.267 -			bttnOkay.Enabled = listItems.SelectedIndex > -1 && (cbEquipAll.Checked || (numEquipAmount.Enabled && numEquipAmount.Value > 0));
   2.268 -		}
   2.269 -
   2.270 -		private void numEquipAmount_ValueChanged(object sender, System.EventArgs e)
   2.271 -		{			
   2.272 -			setOkayButton();
   2.273 -		}
   2.274 -	}
   2.275 -}
   2.276 +// This file (FrmNewUnitEquipment.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard.
   2.277 +//
   2.278 +// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
   2.279 +
   2.280 +using System;
   2.281 +using System.Drawing;
   2.282 +using System.Collections;
   2.283 +using System.ComponentModel;
   2.284 +using System.Windows.Forms;
   2.285 +using IBBoard;
   2.286 +using IBBoard.Commands;
   2.287 +using IBBoard.Lang;
   2.288 +using IBBoard.WarFoundry.API;
   2.289 +using IBBoard.WarFoundry.API.Commands;
   2.290 +using IBBoard.WarFoundry.API.Objects;
   2.291 +
   2.292 +namespace IBBoard.WarFoundry
   2.293 +{
   2.294 +	/// <summary>
   2.295 +	/// Summary description for FrmNewUnitEquipment.
   2.296 +	/// </summary>
   2.297 +	public class FrmNewUnitEquipment : System.Windows.Forms.Form
   2.298 +	{
   2.299 +		private Unit unit;
   2.300 +		private bool required;
   2.301 +		private CommandStack commandStack;
   2.302 +
   2.303 +		private System.Windows.Forms.NumericUpDown numEquipAmount;
   2.304 +		private System.Windows.Forms.Label lblPercent;
   2.305 +		private System.Windows.Forms.Label lblAmount;
   2.306 +		private System.Windows.Forms.Button bttnCancel;
   2.307 +		private System.Windows.Forms.Button bttnOkay;
   2.308 +		private System.Windows.Forms.CheckBox cbEquipAll;
   2.309 +		private System.Windows.Forms.Label lblItem;
   2.310 +		private System.Windows.Forms.ListBox listItems;
   2.311 +		/// <summary>
   2.312 +		/// Required designer variable.
   2.313 +		/// </summary>
   2.314 +		private System.ComponentModel.Container components = null;
   2.315 +
   2.316 +		public FrmNewUnitEquipment(Unit unit, CommandStack stack)
   2.317 +		{
   2.318 +			commandStack = stack;
   2.319 +			this.unit = unit;
   2.320 +			InitializeComponent();
   2.321 +			this.Text = "New equipment for " + unit.Name;
   2.322 +			object[] items = Arrays.Subtract(unit.GetAllowedOptionalEquipment(), unit.GetEquipment());
   2.323 +			listItems.Items.AddRange(items);
   2.324 +		}
   2.325 +
   2.326 +		/// <summary>
   2.327 +		/// Clean up any resources being used.
   2.328 +		/// </summary>
   2.329 +		protected override void Dispose( bool disposing )
   2.330 +		{
   2.331 +			if( disposing )
   2.332 +			{
   2.333 +				if(components != null)
   2.334 +				{
   2.335 +					components.Dispose();
   2.336 +				}
   2.337 +			}
   2.338 +			base.Dispose( disposing );
   2.339 +		}
   2.340 +
   2.341 +		#region Windows Form Designer generated code
   2.342 +		/// <summary>
   2.343 +		/// Required method for Designer support - do not modify
   2.344 +		/// the contents of this method with the code editor.
   2.345 +		/// </summary>
   2.346 +		private void InitializeComponent()
   2.347 +		{
   2.348 +			this.numEquipAmount = new System.Windows.Forms.NumericUpDown();
   2.349 +			this.lblPercent = new System.Windows.Forms.Label();
   2.350 +			this.lblAmount = new System.Windows.Forms.Label();
   2.351 +			this.bttnCancel = new System.Windows.Forms.Button();
   2.352 +			this.bttnOkay = new System.Windows.Forms.Button();
   2.353 +			this.cbEquipAll = new System.Windows.Forms.CheckBox();
   2.354 +			this.lblItem = new System.Windows.Forms.Label();
   2.355 +			this.listItems = new System.Windows.Forms.ListBox();
   2.356 +			((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).BeginInit();
   2.357 +			this.SuspendLayout();
   2.358 +			// 
   2.359 +			// numEquipAmount
   2.360 +			// 
   2.361 +			this.numEquipAmount.Enabled = false;
   2.362 +			this.numEquipAmount.Location = new System.Drawing.Point(88, 80);
   2.363 +			this.numEquipAmount.Name = "numEquipAmount";
   2.364 +			this.numEquipAmount.Size = new System.Drawing.Size(144, 20);
   2.365 +			this.numEquipAmount.TabIndex = 0;
   2.366 +			this.numEquipAmount.ValueChanged += new System.EventHandler(this.numEquipAmount_ValueChanged);
   2.367 +			// 
   2.368 +			// lblPercent
   2.369 +			// 
   2.370 +			this.lblPercent.Location = new System.Drawing.Point(208, 80);
   2.371 +			this.lblPercent.Name = "lblPercent";
   2.372 +			this.lblPercent.Size = new System.Drawing.Size(16, 16);
   2.373 +			this.lblPercent.TabIndex = 1;
   2.374 +			this.lblPercent.Text = "%";
   2.375 +			this.lblPercent.Visible = false;
   2.376 +			// 
   2.377 +			// lblAmount
   2.378 +			// 
   2.379 +			this.lblAmount.Location = new System.Drawing.Point(8, 80);
   2.380 +			this.lblAmount.Name = "lblAmount";
   2.381 +			this.lblAmount.Size = new System.Drawing.Size(72, 23);
   2.382 +			this.lblAmount.TabIndex = 2;
   2.383 +			this.lblAmount.Text = "amount";
   2.384 +			this.lblAmount.TextAlign = System.Drawing.ContentAlignment.TopRight;
   2.385 +			// 
   2.386 +			// bttnCancel
   2.387 +			// 
   2.388 +			this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
   2.389 +			this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
   2.390 +			this.bttnCancel.Location = new System.Drawing.Point(160, 136);
   2.391 +			this.bttnCancel.Name = "bttnCancel";
   2.392 +			this.bttnCancel.TabIndex = 3;
   2.393 +			this.bttnCancel.Text = "cancel";
   2.394 +			this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click);
   2.395 +			// 
   2.396 +			// bttnOkay
   2.397 +			// 
   2.398 +			this.bttnOkay.Enabled = false;
   2.399 +			this.bttnOkay.FlatStyle = System.Windows.Forms.FlatStyle.System;
   2.400 +			this.bttnOkay.Location = new System.Drawing.Point(8, 136);
   2.401 +			this.bttnOkay.Name = "bttnOkay";
   2.402 +			this.bttnOkay.TabIndex = 4;
   2.403 +			this.bttnOkay.Text = "okay";
   2.404 +			this.bttnOkay.Click += new System.EventHandler(this.bttnOkay_Click);
   2.405 +			// 
   2.406 +			// cbEquipAll
   2.407 +			// 
   2.408 +			this.cbEquipAll.Enabled = false;
   2.409 +			this.cbEquipAll.FlatStyle = System.Windows.Forms.FlatStyle.System;
   2.410 +			this.cbEquipAll.Location = new System.Drawing.Point(88, 104);
   2.411 +			this.cbEquipAll.Name = "cbEquipAll";
   2.412 +			this.cbEquipAll.TabIndex = 5;
   2.413 +			this.cbEquipAll.Text = "equip all";
   2.414 +			this.cbEquipAll.CheckedChanged += new System.EventHandler(this.cbEquipAll_CheckedChanged);
   2.415 +			// 
   2.416 +			// lblItem
   2.417 +			// 
   2.418 +			this.lblItem.Location = new System.Drawing.Point(0, 8);
   2.419 +			this.lblItem.Name = "lblItem";
   2.420 +			this.lblItem.Size = new System.Drawing.Size(80, 23);
   2.421 +			this.lblItem.TabIndex = 6;
   2.422 +			this.lblItem.Text = "item";
   2.423 +			this.lblItem.TextAlign = System.Drawing.ContentAlignment.TopRight;
   2.424 +			// 
   2.425 +			// listItems
   2.426 +			// 
   2.427 +			this.listItems.Location = new System.Drawing.Point(88, 8);
   2.428 +			this.listItems.Name = "listItems";
   2.429 +			this.listItems.Size = new System.Drawing.Size(144, 69);
   2.430 +			this.listItems.TabIndex = 7;
   2.431 +			this.listItems.SelectedIndexChanged += new System.EventHandler(this.listItems_SelectedIndexChanged);
   2.432 +			// 
   2.433 +			// FrmNewUnitEquipment
   2.434 +			// 
   2.435 +			this.AcceptButton = this.bttnOkay;
   2.436 +			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
   2.437 +			this.CancelButton = this.bttnCancel;
   2.438 +			this.ClientSize = new System.Drawing.Size(240, 164);
   2.439 +			this.ControlBox = false;
   2.440 +			this.Controls.Add(this.listItems);
   2.441 +			this.Controls.Add(this.lblItem);
   2.442 +			this.Controls.Add(this.cbEquipAll);
   2.443 +			this.Controls.Add(this.bttnOkay);
   2.444 +			this.Controls.Add(this.bttnCancel);
   2.445 +			this.Controls.Add(this.lblAmount);
   2.446 +			this.Controls.Add(this.numEquipAmount);
   2.447 +			this.Controls.Add(this.lblPercent);
   2.448 +			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
   2.449 +			this.Name = "FrmNewUnitEquipment";
   2.450 +			this.ShowInTaskbar = false;
   2.451 +			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
   2.452 +			this.Text = "FrmEditUnitEquipment";
   2.453 +			((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).EndInit();
   2.454 +			this.ResumeLayout(false);
   2.455 +
   2.456 +		}
   2.457 +		#endregion
   2.458 +
   2.459 +		private void bttnOkay_Click(object sender, System.EventArgs e)
   2.460 +		{
   2.461 +			setValue();
   2.462 +			this.Close();
   2.463 +		}
   2.464 +
   2.465 +		private void setValue()
   2.466 +		{
   2.467 +			UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem;
   2.468 +
   2.469 +			if (cbEquipAll.Checked)
   2.470 +			{
   2.471 +				commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, WarFoundryCore.INFINITY));
   2.472 +			}
   2.473 +			else
   2.474 +			{
   2.475 +				if (equipItem.IsRatioLimit)
   2.476 +				{
   2.477 +					commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, (double)numEquipAmount.Value / 100.0));
   2.478 +				}
   2.479 +				else
   2.480 +				{
   2.481 +					commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int)numEquipAmount.Value));
   2.482 +				}
   2.483 +			}
   2.484 +		}
   2.485 +
   2.486 +		private void bttnCancel_Click(object sender, System.EventArgs e)
   2.487 +		{
   2.488 +			this.Close();
   2.489 +		}
   2.490 +
   2.491 +		private void cbEquipAll_CheckedChanged(object sender, System.EventArgs e)
   2.492 +		{
   2.493 +			numEquipAmount.Enabled = ((UnitEquipmentItem)listItems.SelectedItem).MinNumber != WarFoundryCore.INFINITY && !cbEquipAll.Checked;
   2.494 +			setOkayButton();
   2.495 +		}
   2.496 +
   2.497 +		private void listItems_SelectedIndexChanged(object sender, System.EventArgs e)
   2.498 +		{
   2.499 +			refreshNumber();
   2.500 +			setOkayButton();
   2.501 +		}
   2.502 +
   2.503 +		private void refreshNumber()
   2.504 +		{
   2.505 +			if (listItems.SelectedIndex > -1)
   2.506 +			{
   2.507 +				UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem;
   2.508 +				required = equipItem.IsRequired;
   2.509 +
   2.510 +				if (equipItem.IsRatioLimit)
   2.511 +				{
   2.512 +					numEquipAmount.Minimum = (decimal) equipItem.MinPercentage;
   2.513 +					numEquipAmount.Maximum = (decimal) equipItem.MaxPercentage;
   2.514 +					numEquipAmount.Enabled = true;
   2.515 +					numEquipAmount.Value = numEquipAmount.Minimum;
   2.516 +					cbEquipAll.Enabled = false;
   2.517 +					lblPercent.Visible = true;
   2.518 +					numEquipAmount.Width = 120;
   2.519 +				}
   2.520 +				else
   2.521 +				{
   2.522 +					numEquipAmount.Minimum = (decimal)(equipItem.MinNumber != WarFoundryCore.INFINITY ? Math.Min(equipItem.MinNumber, unit.Size) : unit.Size);
   2.523 +					numEquipAmount.Maximum = (decimal)(equipItem.MaxNumber != WarFoundryCore.INFINITY ? Math.Min(equipItem.MaxNumber, unit.Size) : unit.Size);
   2.524 +					numEquipAmount.Value = numEquipAmount.Minimum;
   2.525 +					numEquipAmount.Enabled = equipItem.MinNumber != WarFoundryCore.INFINITY;
   2.526 +					cbEquipAll.Enabled = equipItem.MinNumber != WarFoundryCore.INFINITY && equipItem.MaxNumber == WarFoundryCore.INFINITY;
   2.527 +					cbEquipAll.Checked = equipItem.MinNumber == WarFoundryCore.INFINITY;
   2.528 +					lblPercent.Visible = false;
   2.529 +					numEquipAmount.Width = 144;
   2.530 +				}
   2.531 +			}
   2.532 +			else
   2.533 +			{
   2.534 +				numEquipAmount.Minimum = 0;
   2.535 +				numEquipAmount.Value = 0;
   2.536 +				numEquipAmount.Enabled = false;
   2.537 +				cbEquipAll.Enabled = false;
   2.538 +			}
   2.539 +		}
   2.540 +
   2.541 +		private void setOkayButton()
   2.542 +		{
   2.543 +			bttnOkay.Enabled = listItems.SelectedIndex > -1 && (cbEquipAll.Checked || (numEquipAmount.Enabled && numEquipAmount.Value > 0));
   2.544 +		}
   2.545 +
   2.546 +		private void numEquipAmount_ValueChanged(object sender, System.EventArgs e)
   2.547 +		{			
   2.548 +			setOkayButton();
   2.549 +		}
   2.550 +	}
   2.551 +}
     3.1 --- a/FrmReplaceUnitEquipment.cs	Sun Aug 09 12:05:24 2009 +0000
     3.2 +++ b/FrmReplaceUnitEquipment.cs	Thu Aug 13 21:16:21 2009 +0000
     3.3 @@ -194,17 +194,17 @@
     3.4  
     3.5  			if (cbEquipAll.Checked)
     3.6  			{
     3.7 -                commandStack.Execute(new ReplaceUnitEquipmentCommand(unit, oldItem, equipItem, WarFoundryCore.INFINITY));
     3.8 +                commandStack.Execute(new ReplaceUnitEquipmentWithNumericAmountItemCommand(unit, oldItem, equipItem, WarFoundryCore.INFINITY));
     3.9  			}
    3.10  			else
    3.11  			{
    3.12                  if (equipItem.IsRatioLimit)
    3.13  				{
    3.14 -                    commandStack.Execute(new ReplaceUnitEquipmentCommand(unit, oldItem, equipItem, (double)numEquipAmount.Value / 100.0));
    3.15 +                    commandStack.Execute(new ReplaceUnitEquipmentWithRatioAmountItemCommand(unit, oldItem, equipItem, (double)numEquipAmount.Value));
    3.16  				}
    3.17  				else
    3.18 -				{
    3.19 -                    commandStack.Execute(new ReplaceUnitEquipmentCommand(unit, oldItem, equipItem, (double)numEquipAmount.Value));
    3.20 +				{
    3.21 +					commandStack.Execute(new ReplaceUnitEquipmentWithNumericAmountItemCommand(unit, oldItem, equipItem, (int)numEquipAmount.Value));
    3.22  				}
    3.23  			}
    3.24  		}
     4.1 --- a/FrmUnit.cs	Sun Aug 09 12:05:24 2009 +0000
     4.2 +++ b/FrmUnit.cs	Thu Aug 13 21:16:21 2009 +0000
     4.3 @@ -19,8 +19,6 @@
     4.4  
     4.5  namespace IBBoard.WarFoundry.WinForms
     4.6  {
     4.7 -	///TODO: Separate weapons out into optional and required, where required only has button for replacing
     4.8 -
     4.9  	/// <summary>
    4.10  	/// Summary description for FrmUnit.
    4.11  	/// </summary>
    4.12 @@ -504,7 +502,7 @@
    4.13  
    4.14  		private void removeWeapon()
    4.15  		{
    4.16 -			commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, ((UnitEquipmentChoice) optList.SelectedItem).Item, 0));
    4.17 +			commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, ((UnitEquipmentChoice) optList.SelectedItem).Item, 0));
    4.18  		}
    4.19  
    4.20  		private void bttnRemoveWeapon_Click(object sender, System.EventArgs e)
     5.1 --- a/Util/UnitEquipmentChoice.cs	Sun Aug 09 12:05:24 2009 +0000
     5.2 +++ b/Util/UnitEquipmentChoice.cs	Thu Aug 13 21:16:21 2009 +0000
     5.3 @@ -29,8 +29,20 @@
     5.4  
     5.5          public override string ToString()
     5.6          {
     5.7 -            return String.Format("{0} (For {1} at {2}pts each)", item.Name, UnitEquipmentItem.FormatEquipmentAmount(item, unit.GetEquipmentAmount(item)), item.Cost);
     5.8 -        }
     5.9 +            return String.Format("{0} (For {1} at {2}pts each)", item.Name, GetAmountString(), item.Cost);
    5.10 +        }
    5.11 +
    5.12 +		private string GetAmountString()
    5.13 +		{
    5.14 +			if (unit.GetEquipmentAmountIsRatio(item))
    5.15 +			{
    5.16 +				return UnitEquipmentRatioSelection.GetEquipmentAmountString(unit.GetEquipmentAmount(item));
    5.17 +			}
    5.18 +			else
    5.19 +			{
    5.20 +				return UnitEquipmentNumericSelection.GetEquipmentAmountString(unit.GetEquipmentAmount(item));
    5.21 +			}
    5.22 +		}
    5.23  
    5.24          public UnitEquipmentItem Item
    5.25          {