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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.hgignore	Sat Aug 20 16:12:15 2011 +0100
     1.3 @@ -0,0 +1,3 @@
     1.4 +obj/*
     1.5 +bin/*
     1.6 +IBBoard.WarFoundry.GUI.WinForms.suo
     1.7 \ No newline at end of file
     2.1 --- a/FrmMain.cs	Tue Aug 16 21:01:45 2011 +0100
     2.2 +++ b/FrmMain.cs	Sat Aug 20 16:12:15 2011 +0100
     2.3 @@ -1202,12 +1202,19 @@
     2.4  
     2.5  			if (dr == DialogResult.OK)
     2.6  			{
     2.7 -				CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnit.SelectedUnit, CurrentArmy.GetCategory(cat));
     2.8 -				commandStack.Execute(cmd);
     2.9 -				OpenUnitDialog(cmd.Unit);
    2.10 +                UnitType unitType = newUnit.SelectedUnit;
    2.11 +                CreateUnitInCategory(unitType, cat);
    2.12  			}
    2.13  		}
    2.14  
    2.15 +        internal void CreateUnitInCategory(UnitType unitType, Category cat)
    2.16 +        {
    2.17 +            ArmyCategory armyCat = CurrentArmy.GetCategory(cat);
    2.18 +            CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(unitType, armyCat);
    2.19 +            commandStack.Execute(cmd);
    2.20 +            OpenUnitDialog(cmd.Unit);
    2.21 +        }
    2.22 +
    2.23  		internal void OpenUnitDialog(Unit unit)
    2.24  		{
    2.25  			string unitID = unit.ID;
     3.1 --- a/FrmNewUnitFromTree.Designer.cs	Tue Aug 16 21:01:45 2011 +0100
     3.2 +++ b/FrmNewUnitFromTree.Designer.cs	Sat Aug 20 16:12:15 2011 +0100
     3.3 @@ -38,17 +38,20 @@
     3.4                          | System.Windows.Forms.AnchorStyles.Right)));
     3.5              this.unitTypeTree.Location = new System.Drawing.Point(0, 0);
     3.6              this.unitTypeTree.Name = "unitTypeTree";
     3.7 -            this.unitTypeTree.Size = new System.Drawing.Size(292, 267);
     3.8 +            this.unitTypeTree.Size = new System.Drawing.Size(199, 287);
     3.9              this.unitTypeTree.TabIndex = 0;
    3.10 +            this.unitTypeTree.DoubleClick += new System.EventHandler(this.unitTypeTree_DoubleClick);
    3.11              // 
    3.12              // FrmNewUnitFromTree
    3.13              // 
    3.14              this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    3.15              this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    3.16 -            this.ClientSize = new System.Drawing.Size(292, 266);
    3.17 +            this.ClientSize = new System.Drawing.Size(199, 286);
    3.18 +            this.ControlBox = false;
    3.19              this.Controls.Add(this.unitTypeTree);
    3.20 +            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
    3.21              this.Name = "FrmNewUnitFromTree";
    3.22 -            this.Text = "FrmNewUnitFromTree";
    3.23 +            this.Text = "Available Unit Types";
    3.24              this.ResumeLayout(false);
    3.25  
    3.26          }
     4.1 --- a/FrmNewUnitFromTree.cs	Tue Aug 16 21:01:45 2011 +0100
     4.2 +++ b/FrmNewUnitFromTree.cs	Sat Aug 20 16:12:15 2011 +0100
     4.3 @@ -19,7 +19,7 @@
     4.4              WarFoundryCore.ArmyChanged += new ArmyChangedDelegate(ArmyChanged);
     4.5          }
     4.6  
     4.7 -        private void ArmyChanged(Army newArmy, Army oldArmy)
     4.8 +        private void ArmyChanged(Army oldArmy, Army newArmy)
     4.9          {
    4.10              unitTypeTree.Nodes.Clear();
    4.11  
    4.12 @@ -49,6 +49,27 @@
    4.13                  unitTypeTree.Nodes.Add(catTemp);
    4.14                  catTemp.ExpandAll();
    4.15              }
    4.16 +
    4.17 +            unitTypeTree.Show();
    4.18 +        }
    4.19 +
    4.20 +        private void unitTypeTree_DoubleClick(object sender, EventArgs e)
    4.21 +        {
    4.22 +            TreeNode selected = unitTypeTree.SelectedNode;
    4.23 +            object tagData = selected.Tag;
    4.24 +
    4.25 +            if (tagData is UnitType)
    4.26 +            {
    4.27 +                UnitType unit = (UnitType)tagData;
    4.28 +                Category cat = (Category)selected.Parent.Tag;
    4.29 +                MdiParent.CreateUnitInCategory(unit, cat);
    4.30 +            }
    4.31 +        }
    4.32 +
    4.33 +        public new FrmMain MdiParent
    4.34 +        {
    4.35 +            get { return (FrmMain)base.MdiParent; }
    4.36 +            set { base.MdiParent = value; }
    4.37          }
    4.38      }
    4.39  }