changeset 239:2c3474d652e1

Re #360: Add WinForms UI for adding contained units * Update UI (unit tree and unit creation dialog) so that we can add contained units
author IBBoard <dev@ibboard.co.uk>
date Sat, 14 Apr 2012 20:48:13 +0100
parents 55c94d438a4b
children d0454aae0241
files FrmArmyTree.Designer.cs FrmArmyTree.cs FrmNewUnit.cs
diffstat 3 files changed, 78 insertions(+), 27 deletions(-) [+]
line diff
     1.1 --- a/FrmArmyTree.Designer.cs	Sat Mar 17 21:03:33 2012 +0000
     1.2 +++ b/FrmArmyTree.Designer.cs	Sat Apr 14 20:48:13 2012 +0100
     1.3 @@ -35,8 +35,8 @@
     1.4  			this.miEditArmy = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
     1.5  			this.miEditUnit = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
     1.6  			this.miDeleteUnit = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
     1.7 +			this.miAddUnit = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
     1.8  			this.toolStrip1 = new System.Windows.Forms.ToolStrip();
     1.9 -			this.miAddUnit = new IBBoard.Windows.Forms.IBBToolStripMenuItem();
    1.10  			this.bttnAdd = new IBBoard.Windows.Forms.IBBToolStripButton();
    1.11  			this.bttnEdit = new IBBoard.Windows.Forms.IBBToolStripButton();
    1.12  			this.bttnDelete = new IBBoard.Windows.Forms.IBBToolStripButton();
    1.13 @@ -83,19 +83,19 @@
    1.14  			// contextMenuStrip
    1.15  			// 
    1.16  			this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
    1.17 +            this.miAddUnit,
    1.18              this.miEditArmy,
    1.19              this.miEditUnit,
    1.20 -            this.miDeleteUnit,
    1.21 -            this.miAddUnit});
    1.22 +            this.miDeleteUnit});
    1.23  			this.contextMenuStrip.Name = "contextMenuStrip1";
    1.24 -			this.contextMenuStrip.Size = new System.Drawing.Size(137, 92);
    1.25 +			this.contextMenuStrip.Size = new System.Drawing.Size(153, 114);
    1.26  			this.contextMenuStrip.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenuStrip_Opening);
    1.27  			// 
    1.28  			// miEditArmy
    1.29  			// 
    1.30  			this.miEditArmy.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.gtk_edit;
    1.31  			this.miEditArmy.Name = "miEditArmy";
    1.32 -			this.miEditArmy.Size = new System.Drawing.Size(136, 22);
    1.33 +			this.miEditArmy.Size = new System.Drawing.Size(152, 22);
    1.34  			this.miEditArmy.Text = "edit army";
    1.35  			this.miEditArmy.Click += new System.EventHandler(this.miEditArmy_Click);
    1.36  			// 
    1.37 @@ -103,7 +103,7 @@
    1.38  			// 
    1.39  			this.miEditUnit.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.gtk_edit;
    1.40  			this.miEditUnit.Name = "miEditUnit";
    1.41 -			this.miEditUnit.Size = new System.Drawing.Size(136, 22);
    1.42 +			this.miEditUnit.Size = new System.Drawing.Size(152, 22);
    1.43  			this.miEditUnit.Text = "edit unit";
    1.44  			this.miEditUnit.Click += new System.EventHandler(this.miEdit_Click);
    1.45  			// 
    1.46 @@ -111,10 +111,18 @@
    1.47  			// 
    1.48  			this.miDeleteUnit.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.edit_delete;
    1.49  			this.miDeleteUnit.Name = "miDeleteUnit";
    1.50 -			this.miDeleteUnit.Size = new System.Drawing.Size(136, 22);
    1.51 +			this.miDeleteUnit.Size = new System.Drawing.Size(152, 22);
    1.52  			this.miDeleteUnit.Text = "delete unit";
    1.53  			this.miDeleteUnit.Click += new System.EventHandler(this.miDelete_Click);
    1.54  			// 
    1.55 +			// miAddUnit
    1.56 +			// 
    1.57 +			this.miAddUnit.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.list_add;
    1.58 +			this.miAddUnit.Name = "miAddUnit";
    1.59 +			this.miAddUnit.Size = new System.Drawing.Size(152, 22);
    1.60 +			this.miAddUnit.Text = "add unit";
    1.61 +			this.miAddUnit.Click += new System.EventHandler(this.miAddUnit_Click);
    1.62 +			// 
    1.63  			// toolStrip1
    1.64  			// 
    1.65  			this.toolStrip1.Dock = System.Windows.Forms.DockStyle.None;
    1.66 @@ -124,17 +132,9 @@
    1.67              this.bttnDelete});
    1.68  			this.toolStrip1.Location = new System.Drawing.Point(3, 0);
    1.69  			this.toolStrip1.Name = "toolStrip1";
    1.70 -			this.toolStrip1.Size = new System.Drawing.Size(112, 25);
    1.71 +			this.toolStrip1.Size = new System.Drawing.Size(81, 25);
    1.72  			this.toolStrip1.TabIndex = 0;
    1.73  			// 
    1.74 -			// miAddUnit
    1.75 -			// 
    1.76 -			this.miAddUnit.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.list_add;
    1.77 -			this.miAddUnit.Name = "miAddUnit";
    1.78 -			this.miAddUnit.Size = new System.Drawing.Size(136, 22);
    1.79 -			this.miAddUnit.Text = "add unit";
    1.80 -			this.miAddUnit.Click += new System.EventHandler(this.miAddUnit_Click);
    1.81 -			// 
    1.82  			// bttnAdd
    1.83  			// 
    1.84  			this.bttnAdd.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
     2.1 --- a/FrmArmyTree.cs	Sat Mar 17 21:03:33 2012 +0000
     2.2 +++ b/FrmArmyTree.cs	Sat Apr 14 20:48:13 2012 +0100
     2.3 @@ -298,9 +298,24 @@
     2.4  		private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
     2.5  		{
     2.6  			TreeNode node = treeView.SelectedNode;
     2.7 -			bttnAdd.Enabled = (node != null && node.Tag is ArmyCategory);
     2.8 -			bttnDelete.Enabled = (node != null && node.Tag is Unit);
     2.9 -			bttnEdit.Enabled = (node != null && (node.Tag is Unit || node.Tag is Army));
    2.10 +			Object tag = (node != null) ? node.Tag : null;
    2.11 +			bool tagIsUnit = (tag is Unit);
    2.12 +			bool tagIsUnitWithContained;
    2.13 +
    2.14 +			if (tagIsUnit)
    2.15 +			{
    2.16 +				tagIsUnitWithContained = ((Unit)tag).UnitType.ContainedUnitTypes.Length > 0;
    2.17 +			}
    2.18 +			else
    2.19 +			{
    2.20 +				tagIsUnitWithContained = false;
    2.21 +			}
    2.22 +
    2.23 +			bool tagIsArmy = (tag is Army);
    2.24 +			bool tagIsCategory = (tag is ArmyCategory);
    2.25 +			bttnAdd.Enabled = tagIsCategory || tagIsUnitWithContained;
    2.26 +			bttnDelete.Enabled = tagIsUnit;
    2.27 +			bttnEdit.Enabled = tagIsArmy || tagIsUnit;
    2.28  		}
    2.29  
    2.30  		private void miEditArmy_Click(object sender, EventArgs e)
    2.31 @@ -330,6 +345,17 @@
    2.32  			TreeNode node = treeView.SelectedNode;
    2.33  			Object tag = (node != null) ? node.Tag : null;
    2.34  			bool tagIsUnit = (tag is Unit);
    2.35 +			bool tagIsUnitWithContained;
    2.36 +
    2.37 +			if (tagIsUnit)
    2.38 +			{
    2.39 +				tagIsUnitWithContained = ((Unit)tag).UnitType.ContainedUnitTypes.Length > 0;
    2.40 +			}
    2.41 +			else
    2.42 +			{
    2.43 +				tagIsUnitWithContained = false;
    2.44 +			}
    2.45 +
    2.46  			bool tagIsArmy = (tag is Army);
    2.47  			bool tagIsCategory = (tag is ArmyCategory);
    2.48  
    2.49 @@ -342,7 +368,7 @@
    2.50  				miDeleteUnit.Visible = tagIsUnit;
    2.51  				miEditUnit.Visible = tagIsUnit;
    2.52  				miEditArmy.Visible = tagIsArmy;
    2.53 -				miAddUnit.Visible = tagIsCategory;
    2.54 +				miAddUnit.Visible = tagIsCategory || tagIsUnitWithContained;
    2.55  			}
    2.56  		}
    2.57  
    2.58 @@ -353,8 +379,28 @@
    2.59  
    2.60  		private void AddUnit()
    2.61  		{
    2.62 -			ArmyCategory tagData = treeView.SelectedNode.Tag as ArmyCategory;
    2.63 -			AddUnitFromCategory(tagData);
    2.64 +			object tag = treeView.SelectedNode.Tag;
    2.65 +
    2.66 +			if (tag is Unit)
    2.67 +			{
    2.68 +				Unit unit = (Unit)tag;
    2.69 +				UnitType[] unitTypes = unit.UnitType.ContainedUnitTypes;
    2.70 +				FrmNewUnit newUnitFrm = new FrmNewUnit(WarFoundryCore.CurrentArmy, unitTypes);
    2.71 +				DialogResult dr = newUnitFrm.ShowDialog(this);
    2.72 +
    2.73 +				if (dr == DialogResult.OK)
    2.74 +				{
    2.75 +					UnitType newUnit = newUnitFrm.SelectedUnit;
    2.76 +					CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnitFrm.SelectedUnit, WarFoundryCore.CurrentArmy.GetCategory(newUnit.MainCategory));
    2.77 +					commandStack.Execute(cmd);
    2.78 +					MdiParent.OpenUnitDialog(cmd.Unit);
    2.79 +				}
    2.80 +			}
    2.81 +			else
    2.82 +			{
    2.83 +				ArmyCategory tagData = tag as ArmyCategory;
    2.84 +				AddUnitFromCategory(tagData);
    2.85 +			}
    2.86  		}
    2.87  
    2.88  		private void AddUnitFromCategory(ArmyCategory tagData)
     3.1 --- a/FrmNewUnit.cs	Sat Mar 17 21:03:33 2012 +0000
     3.2 +++ b/FrmNewUnit.cs	Sat Apr 14 20:48:13 2012 +0100
     3.3 @@ -31,15 +31,20 @@
     3.4  		private System.Windows.Forms.Label lblNewUnitWarning;
     3.5  		private System.Windows.Forms.Label lblWarningIcon;
     3.6  
     3.7 -		public FrmNewUnit(Race race, Category cat, Army army)
     3.8 +		public FrmNewUnit(Race race, Category cat, Army army) : this(army, race.GetUnitTypes(cat))
     3.9  		{
    3.10 +			ControlTranslator.TranslateControl(this, cat.Name);
    3.11 +		}
    3.12 +
    3.13 +		public FrmNewUnit(Army army, UnitType[] unitTypes)
    3.14 +		{
    3.15 +			units = unitTypes;
    3.16 +			this.army = army;
    3.17  			InitializeComponent();
    3.18  
    3.19 -			ControlTranslator.TranslateControl(this, cat.Name);
    3.20 -			units = race.GetUnitTypes(cat);
    3.21 -			this.army = army;
    3.22 +			ControlTranslator.TranslateControl(this);
    3.23  			
    3.24 -			for (int i = 0; i<units.Length; i++)
    3.25 +			for (int i = 0; i < units.Length; i++)
    3.26  			{
    3.27  				lstUnits.Items.Add(units[i].Name);
    3.28  			}