diff FrmNewUnitEquipment.cs @ 40:740350673006

Re #117: Add percentage and number boxes to equipment item dialogs * Add a new EquipmentAmountControl to bundle the controls with some initial implementation * Add new control to "new equipment" dialog and remove old controls Also: * Update some namespaces
author IBBoard <dev@ibboard.co.uk>
date Sun, 06 Sep 2009 18:01:54 +0000
parents 6ab7ddc038f9
children 4fc87d6e6119
line wrap: on
line diff
--- a/FrmNewUnitEquipment.cs	Tue Sep 01 19:47:33 2009 +0000
+++ b/FrmNewUnitEquipment.cs	Sun Sep 06 18:01:54 2009 +0000
@@ -13,8 +13,9 @@
 using IBBoard.WarFoundry.API;
 using IBBoard.WarFoundry.API.Commands;
 using IBBoard.WarFoundry.API.Objects;
+using IBBoard.WarFoundry.GUI.WinForms.Util;
 
-namespace IBBoard.WarFoundry
+namespace IBBoard.WarFoundry.GUI.WinForms
 {
 	/// <summary>
 	/// Summary description for FrmNewUnitEquipment.
@@ -22,17 +23,13 @@
 	public class FrmNewUnitEquipment : System.Windows.Forms.Form
 	{
 		private Unit unit;
-		private bool required;
 		private CommandStack commandStack;
-
-		private System.Windows.Forms.NumericUpDown numEquipAmount;
-		private System.Windows.Forms.Label lblPercent;
 		private System.Windows.Forms.Label lblAmount;
 		private System.Windows.Forms.Button bttnCancel;
 		private System.Windows.Forms.Button bttnOkay;
-		private System.Windows.Forms.CheckBox cbEquipAll;
 		private System.Windows.Forms.Label lblItem;
 		private System.Windows.Forms.ListBox listItems;
+		private IBBoard.WarFoundry.GUI.WinForms.UI.EquipmentAmountControl equipmentAmount;
 		/// <summary>
 		/// Required designer variable.
 		/// </summary>
@@ -70,35 +67,14 @@
 		/// </summary>
 		private void InitializeComponent()
 		{
-			this.numEquipAmount = new System.Windows.Forms.NumericUpDown();
-			this.lblPercent = new System.Windows.Forms.Label();
 			this.lblAmount = new System.Windows.Forms.Label();
 			this.bttnCancel = new System.Windows.Forms.Button();
 			this.bttnOkay = new System.Windows.Forms.Button();
-			this.cbEquipAll = new System.Windows.Forms.CheckBox();
 			this.lblItem = new System.Windows.Forms.Label();
 			this.listItems = new System.Windows.Forms.ListBox();
-			((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).BeginInit();
+			this.equipmentAmount = new IBBoard.WarFoundry.GUI.WinForms.UI.EquipmentAmountControl();
 			this.SuspendLayout();
 			// 
-			// numEquipAmount
-			// 
-			this.numEquipAmount.Enabled = false;
-			this.numEquipAmount.Location = new System.Drawing.Point(88, 80);
-			this.numEquipAmount.Name = "numEquipAmount";
-			this.numEquipAmount.Size = new System.Drawing.Size(144, 20);
-			this.numEquipAmount.TabIndex = 0;
-			this.numEquipAmount.ValueChanged += new System.EventHandler(this.numEquipAmount_ValueChanged);
-			// 
-			// lblPercent
-			// 
-			this.lblPercent.Location = new System.Drawing.Point(208, 80);
-			this.lblPercent.Name = "lblPercent";
-			this.lblPercent.Size = new System.Drawing.Size(16, 16);
-			this.lblPercent.TabIndex = 1;
-			this.lblPercent.Text = "%";
-			this.lblPercent.Visible = false;
-			// 
 			// lblAmount
 			// 
 			this.lblAmount.Location = new System.Drawing.Point(8, 80);
@@ -112,8 +88,9 @@
 			// 
 			this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
 			this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
-			this.bttnCancel.Location = new System.Drawing.Point(160, 136);
+			this.bttnCancel.Location = new System.Drawing.Point(158, 162);
 			this.bttnCancel.Name = "bttnCancel";
+			this.bttnCancel.Size = new System.Drawing.Size(75, 23);
 			this.bttnCancel.TabIndex = 3;
 			this.bttnCancel.Text = "cancel";
 			this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click);
@@ -122,22 +99,13 @@
 			// 
 			this.bttnOkay.Enabled = false;
 			this.bttnOkay.FlatStyle = System.Windows.Forms.FlatStyle.System;
-			this.bttnOkay.Location = new System.Drawing.Point(8, 136);
+			this.bttnOkay.Location = new System.Drawing.Point(12, 162);
 			this.bttnOkay.Name = "bttnOkay";
+			this.bttnOkay.Size = new System.Drawing.Size(75, 23);
 			this.bttnOkay.TabIndex = 4;
 			this.bttnOkay.Text = "okay";
 			this.bttnOkay.Click += new System.EventHandler(this.bttnOkay_Click);
 			// 
-			// cbEquipAll
-			// 
-			this.cbEquipAll.Enabled = false;
-			this.cbEquipAll.FlatStyle = System.Windows.Forms.FlatStyle.System;
-			this.cbEquipAll.Location = new System.Drawing.Point(88, 104);
-			this.cbEquipAll.Name = "cbEquipAll";
-			this.cbEquipAll.TabIndex = 5;
-			this.cbEquipAll.Text = "equip all";
-			this.cbEquipAll.CheckedChanged += new System.EventHandler(this.cbEquipAll_CheckedChanged);
-			// 
 			// lblItem
 			// 
 			this.lblItem.Location = new System.Drawing.Point(0, 8);
@@ -151,31 +119,35 @@
 			// 
 			this.listItems.Location = new System.Drawing.Point(88, 8);
 			this.listItems.Name = "listItems";
-			this.listItems.Size = new System.Drawing.Size(144, 69);
+			this.listItems.Size = new System.Drawing.Size(145, 69);
 			this.listItems.TabIndex = 7;
 			this.listItems.SelectedIndexChanged += new System.EventHandler(this.listItems_SelectedIndexChanged);
 			// 
+			// equipmentAmount
+			// 
+			this.equipmentAmount.Location = new System.Drawing.Point(88, 80);
+			this.equipmentAmount.Name = "equipmentAmount";
+			this.equipmentAmount.Size = new System.Drawing.Size(155, 77);
+			this.equipmentAmount.TabIndex = 8;
+			// 
 			// FrmNewUnitEquipment
 			// 
 			this.AcceptButton = this.bttnOkay;
 			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
 			this.CancelButton = this.bttnCancel;
-			this.ClientSize = new System.Drawing.Size(240, 164);
+			this.ClientSize = new System.Drawing.Size(245, 190);
 			this.ControlBox = false;
+			this.Controls.Add(this.equipmentAmount);
 			this.Controls.Add(this.listItems);
 			this.Controls.Add(this.lblItem);
-			this.Controls.Add(this.cbEquipAll);
 			this.Controls.Add(this.bttnOkay);
 			this.Controls.Add(this.bttnCancel);
 			this.Controls.Add(this.lblAmount);
-			this.Controls.Add(this.numEquipAmount);
-			this.Controls.Add(this.lblPercent);
 			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
 			this.Name = "FrmNewUnitEquipment";
 			this.ShowInTaskbar = false;
 			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
 			this.Text = "FrmEditUnitEquipment";
-			((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).EndInit();
 			this.ResumeLayout(false);
 
 		}
@@ -183,28 +155,22 @@
 
 		private void bttnOkay_Click(object sender, System.EventArgs e)
 		{
-			setValue();
+			SetValue();
 			this.Close();
 		}
 
-		private void setValue()
+		private void SetValue()
 		{
 			UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem;
 
-			if (cbEquipAll.Checked)
+			if (equipmentAmount.IsRatioEquipmentAmount)
 			{
-				commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, WarFoundryCore.INFINITY));
+				commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, equipmentAmount.EquipmentAmount));
 			}
 			else
 			{
-				if (equipItem.IsRatioLimit)
-				{
-					commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, (double)numEquipAmount.Value / 100.0));
-				}
-				else
-				{
-					commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int)numEquipAmount.Value));
-				}
+				//Just cast here - we should be returned a whole number anyway
+				commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int) equipmentAmount.EquipmentAmount));
 			}
 		}
 
@@ -215,7 +181,7 @@
 
 		private void cbEquipAll_CheckedChanged(object sender, System.EventArgs e)
 		{
-			numEquipAmount.Enabled = ((UnitEquipmentItem)listItems.SelectedItem).MinNumber != WarFoundryCore.INFINITY && !cbEquipAll.Checked;
+			//numEquipAmount.Enabled = ((UnitEquipmentItem) listItems.SelectedItem).MinNumber != WarFoundryCore.INFINITY && !rbEquipAll.Checked;
 			setOkayButton();
 		}
 
@@ -227,6 +193,7 @@
 
 		private void refreshNumber()
 		{
+			/*
 			if (listItems.SelectedIndex > -1)
 			{
 				UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem;
@@ -238,7 +205,7 @@
 					numEquipAmount.Maximum = (decimal) equipItem.MaxPercentage;
 					numEquipAmount.Enabled = true;
 					numEquipAmount.Value = numEquipAmount.Minimum;
-					cbEquipAll.Enabled = false;
+					rbEquipAll.Enabled = false;
 					lblPercent.Visible = true;
 					numEquipAmount.Width = 120;
 				}
@@ -248,8 +215,8 @@
 					numEquipAmount.Maximum = (decimal)(equipItem.MaxNumber != WarFoundryCore.INFINITY ? Math.Min(equipItem.MaxNumber, unit.Size) : unit.Size);
 					numEquipAmount.Value = numEquipAmount.Minimum;
 					numEquipAmount.Enabled = equipItem.MinNumber != WarFoundryCore.INFINITY;
-					cbEquipAll.Enabled = equipItem.MinNumber != WarFoundryCore.INFINITY && equipItem.MaxNumber == WarFoundryCore.INFINITY;
-					cbEquipAll.Checked = equipItem.MinNumber == WarFoundryCore.INFINITY;
+					rbEquipAll.Enabled = equipItem.MinNumber != WarFoundryCore.INFINITY && equipItem.MaxNumber == WarFoundryCore.INFINITY;
+					rbEquipAll.Checked = equipItem.MinNumber == WarFoundryCore.INFINITY;
 					lblPercent.Visible = false;
 					numEquipAmount.Width = 144;
 				}
@@ -259,13 +226,13 @@
 				numEquipAmount.Minimum = 0;
 				numEquipAmount.Value = 0;
 				numEquipAmount.Enabled = false;
-				cbEquipAll.Enabled = false;
-			}
+				rbEquipAll.Enabled = false;
+			}*/
 		}
 
 		private void setOkayButton()
 		{
-			bttnOkay.Enabled = listItems.SelectedIndex > -1 && (cbEquipAll.Checked || (numEquipAmount.Enabled && numEquipAmount.Value > 0));
+			bttnOkay.Enabled = listItems.SelectedIndex > -1;// && (rbEquipAll.Checked || (numEquipAmount.Enabled && numEquipAmount.Value > 0));
 		}
 
 		private void numEquipAmount_ValueChanged(object sender, System.EventArgs e)