changeset 207:53d79e1be712

Re #354: Single-button Add Unit * Start creating new form
author IBBoard <dev@ibboard.co.uk>
date Tue, 16 Aug 2011 21:01:45 +0100
parents 314d90a059d8
children 19a88383dfa7
files FrmMain.cs FrmNewUnitFromTree.Designer.cs FrmNewUnitFromTree.cs FrmNewUnitFromTree.resx IBBoard.WarFoundry.GUI.WinForms.csproj
diffstat 5 files changed, 264 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/FrmMain.cs	Tue Aug 16 20:34:46 2011 +0100
+++ b/FrmMain.cs	Tue Aug 16 21:01:45 2011 +0100
@@ -59,6 +59,7 @@
 		//public FailedUnitRequirementDelegate FailedUnitRequirementMethod;
 
 		private FrmArmyTree armyTree;
+        private FrmNewUnitFromTree newUnitTree;
 		private string loadedFilePath;
 		private Dictionary<string, FrmUnit> unitWindows;
 
@@ -184,6 +185,24 @@
 			armyTree.Location = new Point(this.DisplayRectangle.Width - armyTree.Width - 10, 10);
 		}
 
+        private FrmNewUnitFromTree GetNewUnitTree()
+        {
+            if (newUnitTree == null || newUnitTree.IsDisposed)
+            {
+                CreateNewUnitTree();
+            }
+
+            return newUnitTree;
+        }
+
+        private void CreateNewUnitTree()
+        {
+            newUnitTree = new FrmNewUnitFromTree();
+            newUnitTree.MdiParent = this;
+            newUnitTree.StartPosition = FormStartPosition.Manual;
+            newUnitTree.Location = new Point(10, 10);
+        }
+
 		private void TranslateControls()
 		{
 			ControlTranslator.TranslateControls(Controls);
@@ -957,6 +976,7 @@
 			miExportArmyAs.Enabled = false;
 			DisableCategoryButtons();
 			GetArmyTree().Hide();
+            GetNewUnitTree().Hide();
 		}
 
 		private void SetNonNullArmyState(Army newArmy)
@@ -967,6 +987,7 @@
 			miCloseArmy.Enabled = true;
 			miExportArmyAs.Enabled = true;
 			GetArmyTree().Show();
+            GetNewUnitTree().Show();
 		}
 
 		private void SetCategoryButtons(Category[] cats)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FrmNewUnitFromTree.Designer.cs	Tue Aug 16 21:01:45 2011 +0100
@@ -0,0 +1,60 @@
+namespace IBBoard.WarFoundry.GUI.WinForms
+{
+    partial class FrmNewUnitFromTree
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.unitTypeTree = new System.Windows.Forms.TreeView();
+            this.SuspendLayout();
+            // 
+            // unitTypeTree
+            // 
+            this.unitTypeTree.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+                        | System.Windows.Forms.AnchorStyles.Left)
+                        | 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.TabIndex = 0;
+            // 
+            // 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.Controls.Add(this.unitTypeTree);
+            this.Name = "FrmNewUnitFromTree";
+            this.Text = "FrmNewUnitFromTree";
+            this.ResumeLayout(false);
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.TreeView unitTypeTree;
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FrmNewUnitFromTree.cs	Tue Aug 16 21:01:45 2011 +0100
@@ -0,0 +1,54 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+using IBBoard.WarFoundry.API.Objects;
+using IBBoard.WarFoundry.API;
+
+namespace IBBoard.WarFoundry.GUI.WinForms
+{
+    public partial class FrmNewUnitFromTree : Form
+    {
+        public FrmNewUnitFromTree()
+        {
+            InitializeComponent();
+            WarFoundryCore.ArmyChanged += new ArmyChangedDelegate(ArmyChanged);
+        }
+
+        private void ArmyChanged(Army newArmy, Army oldArmy)
+        {
+            unitTypeTree.Nodes.Clear();
+
+            if (newArmy != null)
+            {
+                BuildTree(newArmy.Race);
+            }
+        }
+
+        private void BuildTree(Race race)
+        {
+            foreach (Category cat in race.Categories)
+            {
+                UnitType[] unitTypes = race.GetUnitTypes(cat);
+                TreeNode[] unitNodes = new TreeNode[unitTypes.Length];
+
+                for (int i = 0; i < unitTypes.Length; i++)
+                {
+                    UnitType unitType = unitTypes[i];
+                    TreeNode temp = new TreeNode(unitType.Name);
+                    temp.Tag = unitType;
+                    unitNodes[i] = temp;
+                }
+
+                TreeNode catTemp = new TreeNode(cat.Name, unitNodes);
+                catTemp.Tag = cat;
+                unitTypeTree.Nodes.Add(catTemp);
+                catTemp.ExpandAll();
+            }
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FrmNewUnitFromTree.resx	Tue Aug 16 21:01:45 2011 +0100
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>
\ No newline at end of file
--- a/IBBoard.WarFoundry.GUI.WinForms.csproj	Tue Aug 16 20:34:46 2011 +0100
+++ b/IBBoard.WarFoundry.GUI.WinForms.csproj	Tue Aug 16 21:01:45 2011 +0100
@@ -150,6 +150,12 @@
     <Compile Include="FrmNewUnitEquipment.cs">
       <SubType>Form</SubType>
     </Compile>
+    <Compile Include="FrmNewUnitFromTree.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="FrmNewUnitFromTree.Designer.cs">
+      <DependentUpon>FrmNewUnitFromTree.cs</DependentUpon>
+    </Compile>
     <Compile Include="FrmPreferences.cs">
       <SubType>Form</SubType>
     </Compile>
@@ -206,6 +212,9 @@
       <DependentUpon>FrmNewUnitEquipment.cs</DependentUpon>
       <SubType>Designer</SubType>
     </EmbeddedResource>
+    <EmbeddedResource Include="FrmNewUnitFromTree.resx">
+      <DependentUpon>FrmNewUnitFromTree.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="FrmPreferences.resx">
       <SubType>Designer</SubType>
       <DependentUpon>FrmPreferences.cs</DependentUpon>