changeset 248:19a88383dfa7

Re #354: Single-button Add Unit * Pull out re-usable method for adding unit * Make double-click add unit
author IBBoard <dev@ibboard.co.uk>
date Sat, 20 Aug 2011 16:12:15 +0100
parents 53d79e1be712
children a11faa64c333
files .hgignore FrmMain.cs FrmNewUnitFromTree.Designer.cs FrmNewUnitFromTree.cs
diffstat 4 files changed, 41 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Sat Aug 20 16:12:15 2011 +0100
@@ -0,0 +1,3 @@
+obj/*
+bin/*
+IBBoard.WarFoundry.GUI.WinForms.suo
\ No newline at end of file
--- a/FrmMain.cs	Tue Aug 16 21:01:45 2011 +0100
+++ b/FrmMain.cs	Sat Aug 20 16:12:15 2011 +0100
@@ -1202,12 +1202,19 @@
 
 			if (dr == DialogResult.OK)
 			{
-				CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnit.SelectedUnit, CurrentArmy.GetCategory(cat));
-				commandStack.Execute(cmd);
-				OpenUnitDialog(cmd.Unit);
+                UnitType unitType = newUnit.SelectedUnit;
+                CreateUnitInCategory(unitType, cat);
 			}
 		}
 
+        internal void CreateUnitInCategory(UnitType unitType, Category cat)
+        {
+            ArmyCategory armyCat = CurrentArmy.GetCategory(cat);
+            CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(unitType, armyCat);
+            commandStack.Execute(cmd);
+            OpenUnitDialog(cmd.Unit);
+        }
+
 		internal void OpenUnitDialog(Unit unit)
 		{
 			string unitID = unit.ID;
--- a/FrmNewUnitFromTree.Designer.cs	Tue Aug 16 21:01:45 2011 +0100
+++ b/FrmNewUnitFromTree.Designer.cs	Sat Aug 20 16:12:15 2011 +0100
@@ -38,17 +38,20 @@
                         | System.Windows.Forms.AnchorStyles.Right)));
             this.unitTypeTree.Location = new System.Drawing.Point(0, 0);
             this.unitTypeTree.Name = "unitTypeTree";
-            this.unitTypeTree.Size = new System.Drawing.Size(292, 267);
+            this.unitTypeTree.Size = new System.Drawing.Size(199, 287);
             this.unitTypeTree.TabIndex = 0;
+            this.unitTypeTree.DoubleClick += new System.EventHandler(this.unitTypeTree_DoubleClick);
             // 
             // FrmNewUnitFromTree
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(292, 266);
+            this.ClientSize = new System.Drawing.Size(199, 286);
+            this.ControlBox = false;
             this.Controls.Add(this.unitTypeTree);
+            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
             this.Name = "FrmNewUnitFromTree";
-            this.Text = "FrmNewUnitFromTree";
+            this.Text = "Available Unit Types";
             this.ResumeLayout(false);
 
         }
--- a/FrmNewUnitFromTree.cs	Tue Aug 16 21:01:45 2011 +0100
+++ b/FrmNewUnitFromTree.cs	Sat Aug 20 16:12:15 2011 +0100
@@ -19,7 +19,7 @@
             WarFoundryCore.ArmyChanged += new ArmyChangedDelegate(ArmyChanged);
         }
 
-        private void ArmyChanged(Army newArmy, Army oldArmy)
+        private void ArmyChanged(Army oldArmy, Army newArmy)
         {
             unitTypeTree.Nodes.Clear();
 
@@ -49,6 +49,27 @@
                 unitTypeTree.Nodes.Add(catTemp);
                 catTemp.ExpandAll();
             }
+
+            unitTypeTree.Show();
+        }
+
+        private void unitTypeTree_DoubleClick(object sender, EventArgs e)
+        {
+            TreeNode selected = unitTypeTree.SelectedNode;
+            object tagData = selected.Tag;
+
+            if (tagData is UnitType)
+            {
+                UnitType unit = (UnitType)tagData;
+                Category cat = (Category)selected.Parent.Tag;
+                MdiParent.CreateUnitInCategory(unit, cat);
+            }
+        }
+
+        public new FrmMain MdiParent
+        {
+            get { return (FrmMain)base.MdiParent; }
+            set { base.MdiParent = value; }
         }
     }
 }