# HG changeset patch # User IBBoard # Date 1334432893 -3600 # Node ID 2c3474d652e109de5552e880b9fc14b5db09a00e # Parent 55c94d438a4b6db3eb59d2bb7ae5bfc54c67fa7b Re #360: Add WinForms UI for adding contained units * Update UI (unit tree and unit creation dialog) so that we can add contained units diff -r 55c94d438a4b -r 2c3474d652e1 FrmArmyTree.Designer.cs --- a/FrmArmyTree.Designer.cs Sat Mar 17 21:03:33 2012 +0000 +++ b/FrmArmyTree.Designer.cs Sat Apr 14 20:48:13 2012 +0100 @@ -35,8 +35,8 @@ this.miEditArmy = new IBBoard.Windows.Forms.IBBToolStripMenuItem(); this.miEditUnit = new IBBoard.Windows.Forms.IBBToolStripMenuItem(); this.miDeleteUnit = new IBBoard.Windows.Forms.IBBToolStripMenuItem(); + this.miAddUnit = new IBBoard.Windows.Forms.IBBToolStripMenuItem(); this.toolStrip1 = new System.Windows.Forms.ToolStrip(); - this.miAddUnit = new IBBoard.Windows.Forms.IBBToolStripMenuItem(); this.bttnAdd = new IBBoard.Windows.Forms.IBBToolStripButton(); this.bttnEdit = new IBBoard.Windows.Forms.IBBToolStripButton(); this.bttnDelete = new IBBoard.Windows.Forms.IBBToolStripButton(); @@ -83,19 +83,19 @@ // contextMenuStrip // this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.miAddUnit, this.miEditArmy, this.miEditUnit, - this.miDeleteUnit, - this.miAddUnit}); + this.miDeleteUnit}); this.contextMenuStrip.Name = "contextMenuStrip1"; - this.contextMenuStrip.Size = new System.Drawing.Size(137, 92); + this.contextMenuStrip.Size = new System.Drawing.Size(153, 114); this.contextMenuStrip.Opening += new System.ComponentModel.CancelEventHandler(this.contextMenuStrip_Opening); // // miEditArmy // this.miEditArmy.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.gtk_edit; this.miEditArmy.Name = "miEditArmy"; - this.miEditArmy.Size = new System.Drawing.Size(136, 22); + this.miEditArmy.Size = new System.Drawing.Size(152, 22); this.miEditArmy.Text = "edit army"; this.miEditArmy.Click += new System.EventHandler(this.miEditArmy_Click); // @@ -103,7 +103,7 @@ // this.miEditUnit.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.gtk_edit; this.miEditUnit.Name = "miEditUnit"; - this.miEditUnit.Size = new System.Drawing.Size(136, 22); + this.miEditUnit.Size = new System.Drawing.Size(152, 22); this.miEditUnit.Text = "edit unit"; this.miEditUnit.Click += new System.EventHandler(this.miEdit_Click); // @@ -111,10 +111,18 @@ // this.miDeleteUnit.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.edit_delete; this.miDeleteUnit.Name = "miDeleteUnit"; - this.miDeleteUnit.Size = new System.Drawing.Size(136, 22); + this.miDeleteUnit.Size = new System.Drawing.Size(152, 22); this.miDeleteUnit.Text = "delete unit"; this.miDeleteUnit.Click += new System.EventHandler(this.miDelete_Click); // + // miAddUnit + // + this.miAddUnit.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.list_add; + this.miAddUnit.Name = "miAddUnit"; + this.miAddUnit.Size = new System.Drawing.Size(152, 22); + this.miAddUnit.Text = "add unit"; + this.miAddUnit.Click += new System.EventHandler(this.miAddUnit_Click); + // // toolStrip1 // this.toolStrip1.Dock = System.Windows.Forms.DockStyle.None; @@ -124,17 +132,9 @@ this.bttnDelete}); this.toolStrip1.Location = new System.Drawing.Point(3, 0); this.toolStrip1.Name = "toolStrip1"; - this.toolStrip1.Size = new System.Drawing.Size(112, 25); + this.toolStrip1.Size = new System.Drawing.Size(81, 25); this.toolStrip1.TabIndex = 0; // - // miAddUnit - // - this.miAddUnit.Image = global::IBBoard.WarFoundry.GUI.WinForms.Properties.Resources.list_add; - this.miAddUnit.Name = "miAddUnit"; - this.miAddUnit.Size = new System.Drawing.Size(136, 22); - this.miAddUnit.Text = "add unit"; - this.miAddUnit.Click += new System.EventHandler(this.miAddUnit_Click); - // // bttnAdd // this.bttnAdd.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; diff -r 55c94d438a4b -r 2c3474d652e1 FrmArmyTree.cs --- a/FrmArmyTree.cs Sat Mar 17 21:03:33 2012 +0000 +++ b/FrmArmyTree.cs Sat Apr 14 20:48:13 2012 +0100 @@ -298,9 +298,24 @@ private void treeView_AfterSelect(object sender, TreeViewEventArgs e) { TreeNode node = treeView.SelectedNode; - bttnAdd.Enabled = (node != null && node.Tag is ArmyCategory); - bttnDelete.Enabled = (node != null && node.Tag is Unit); - bttnEdit.Enabled = (node != null && (node.Tag is Unit || node.Tag is Army)); + Object tag = (node != null) ? node.Tag : null; + bool tagIsUnit = (tag is Unit); + bool tagIsUnitWithContained; + + if (tagIsUnit) + { + tagIsUnitWithContained = ((Unit)tag).UnitType.ContainedUnitTypes.Length > 0; + } + else + { + tagIsUnitWithContained = false; + } + + bool tagIsArmy = (tag is Army); + bool tagIsCategory = (tag is ArmyCategory); + bttnAdd.Enabled = tagIsCategory || tagIsUnitWithContained; + bttnDelete.Enabled = tagIsUnit; + bttnEdit.Enabled = tagIsArmy || tagIsUnit; } private void miEditArmy_Click(object sender, EventArgs e) @@ -330,6 +345,17 @@ TreeNode node = treeView.SelectedNode; Object tag = (node != null) ? node.Tag : null; bool tagIsUnit = (tag is Unit); + bool tagIsUnitWithContained; + + if (tagIsUnit) + { + tagIsUnitWithContained = ((Unit)tag).UnitType.ContainedUnitTypes.Length > 0; + } + else + { + tagIsUnitWithContained = false; + } + bool tagIsArmy = (tag is Army); bool tagIsCategory = (tag is ArmyCategory); @@ -342,7 +368,7 @@ miDeleteUnit.Visible = tagIsUnit; miEditUnit.Visible = tagIsUnit; miEditArmy.Visible = tagIsArmy; - miAddUnit.Visible = tagIsCategory; + miAddUnit.Visible = tagIsCategory || tagIsUnitWithContained; } } @@ -353,8 +379,28 @@ private void AddUnit() { - ArmyCategory tagData = treeView.SelectedNode.Tag as ArmyCategory; - AddUnitFromCategory(tagData); + object tag = treeView.SelectedNode.Tag; + + if (tag is Unit) + { + Unit unit = (Unit)tag; + UnitType[] unitTypes = unit.UnitType.ContainedUnitTypes; + FrmNewUnit newUnitFrm = new FrmNewUnit(WarFoundryCore.CurrentArmy, unitTypes); + DialogResult dr = newUnitFrm.ShowDialog(this); + + if (dr == DialogResult.OK) + { + UnitType newUnit = newUnitFrm.SelectedUnit; + CreateAndAddUnitCommand cmd = new CreateAndAddUnitCommand(newUnitFrm.SelectedUnit, WarFoundryCore.CurrentArmy.GetCategory(newUnit.MainCategory)); + commandStack.Execute(cmd); + MdiParent.OpenUnitDialog(cmd.Unit); + } + } + else + { + ArmyCategory tagData = tag as ArmyCategory; + AddUnitFromCategory(tagData); + } } private void AddUnitFromCategory(ArmyCategory tagData) diff -r 55c94d438a4b -r 2c3474d652e1 FrmNewUnit.cs --- a/FrmNewUnit.cs Sat Mar 17 21:03:33 2012 +0000 +++ b/FrmNewUnit.cs Sat Apr 14 20:48:13 2012 +0100 @@ -31,15 +31,20 @@ private System.Windows.Forms.Label lblNewUnitWarning; private System.Windows.Forms.Label lblWarningIcon; - public FrmNewUnit(Race race, Category cat, Army army) + public FrmNewUnit(Race race, Category cat, Army army) : this(army, race.GetUnitTypes(cat)) { + ControlTranslator.TranslateControl(this, cat.Name); + } + + public FrmNewUnit(Army army, UnitType[] unitTypes) + { + units = unitTypes; + this.army = army; InitializeComponent(); - ControlTranslator.TranslateControl(this, cat.Name); - units = race.GetUnitTypes(cat); - this.army = army; + ControlTranslator.TranslateControl(this); - for (int i = 0; i