annotate FrmArmyTree.cs @ 19:ad2fe107d3e7

* Remove reference to Log4Net from the project (not needed) no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Wed, 17 Jun 2009 18:25:45 +0000
parents 475d3cdb75f4
children 7c366fe55635
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
1 // This file (FrmArmyTree.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard.
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
2 //
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
4
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
5 using System;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
6 using System.Drawing;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
7 using System.Collections;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
8 using System.ComponentModel;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
9 using System.Windows.Forms;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
10 using IBBoard.Commands;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
11 using IBBoard.WarFoundry.API;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
12 using IBBoard.WarFoundry.API.Commands;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
13 using IBBoard.Windows.Forms;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
14 using IBBoard.WarFoundry.API.Objects;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
15
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
16 namespace IBBoard.WarFoundry
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
17 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
18 /// <summary>
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
19 /// Summary description for FrmArmyTree.
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
20 /// </summary>
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
21 public class FrmArmyTree : IBBoard.Windows.Forms.IBBForm
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
22 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
23 private System.Windows.Forms.TreeView treeView;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
24 /// <summary>
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
25 /// Required designer variable.
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
26 /// </summary>
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
27 private System.ComponentModel.Container components = null;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
28 private Hashtable htNodes;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
29 private System.Windows.Forms.ContextMenu contextMenu;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
30 private System.Windows.Forms.MenuItem miDelete;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
31 private System.Windows.Forms.MenuItem miEdit;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
32 private Hashtable htUnitWindows;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
33
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
34 private ObjectAddDelegate UnitAddedMethod;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
35 private ObjectRemoveDelegate UnitRemovedMethod;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
36 private StringValChangedDelegate UnitNameChangedMethod, ArmyNameChangedMethod, TreeNameChangedMethod;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
37 private CommandStack commandStack;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
38
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
39 public FrmArmyTree(CommandStack cmdStack)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
40 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
41 commandStack = cmdStack;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
42 InitializeComponent();
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
43 UnitAddedMethod = new ObjectAddDelegate(AddUnit);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
44 UnitRemovedMethod = new ObjectRemoveDelegate(RemoveUnit);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
45 UnitNameChangedMethod = new StringValChangedDelegate(UpdateUnitName);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
46 ArmyNameChangedMethod = new StringValChangedDelegate(UpdateArmyName);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
47 TreeNameChangedMethod = new StringValChangedDelegate(FrmArmyTree_TreeNameChanged);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
48 htNodes = new Hashtable();
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
49 htUnitWindows = new Hashtable();
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
50 this.Name = "ArmyTree";
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
51 WarFoundryCore.ArmyChanged+= new ArmyChangedDelegate(FrmArmyTree_ArmyChanged);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
52 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
53
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
54 public FrmArmyTree(Army army, CommandStack cmdStack) : this(cmdStack)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
55 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
56 SetArmy(army);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
57 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
58
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
59 /// <summary>
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
60 /// Clean up any resources being used.
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
61 /// </summary>
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
62 protected override void Dispose( bool disposing )
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
63 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
64 if( disposing )
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
65 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
66 if(components != null)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
67 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
68 components.Dispose();
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
69 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
70 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
71 base.Dispose( disposing );
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
72 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
73
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
74 #region Windows Form Designer generated code
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
75 /// <summary>
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
76 /// Required method for Designer support - do not modify
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
77 /// the contents of this method with the code editor.
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
78 /// </summary>
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
79 private void InitializeComponent()
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
80 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
81 this.treeView = new System.Windows.Forms.TreeView();
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
82 this.contextMenu = new System.Windows.Forms.ContextMenu();
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
83 this.miEdit = new System.Windows.Forms.MenuItem();
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
84 this.miDelete = new System.Windows.Forms.MenuItem();
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
85 this.SuspendLayout();
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
86 //
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
87 // treeView
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
88 //
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
89 this.treeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
90 | System.Windows.Forms.AnchorStyles.Left)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
91 | System.Windows.Forms.AnchorStyles.Right)));
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
92 this.treeView.ContextMenu = this.contextMenu;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
93 this.treeView.FullRowSelect = true;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
94 this.treeView.ImageIndex = -1;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
95 this.treeView.Location = new System.Drawing.Point(0, 0);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
96 this.treeView.Name = "treeView";
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
97 this.treeView.SelectedImageIndex = -1;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
98 this.treeView.Size = new System.Drawing.Size(240, 278);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
99 this.treeView.TabIndex = 0;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
100 this.treeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeView_MouseDown);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
101 this.treeView.DoubleClick += new System.EventHandler(this.treeView_DoubleClick);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
102 //
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
103 // contextMenu
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
104 //
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
105 this.contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
106 this.miEdit,
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
107 this.miDelete});
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
108 this.contextMenu.Popup += new System.EventHandler(this.contextMenu_Popup);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
109 //
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
110 // miEdit
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
111 //
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
112 this.miEdit.Index = 0;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
113 this.miEdit.Text = "&Edit unit";
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
114 this.miEdit.Click += new System.EventHandler(this.miEdit_Click);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
115 //
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
116 // miDelete
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
117 //
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
118 this.miDelete.Index = 1;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
119 this.miDelete.Text = "&Delete unit";
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
120 this.miDelete.Click += new System.EventHandler(this.miDelete_Click);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
121 //
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
122 // FrmArmyTree
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
123 //
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
124 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
125 this.ClientSize = new System.Drawing.Size(240, 277);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
126 this.ControlBox = false;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
127 this.Controls.Add(this.treeView);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
128 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
129 this.MaximizeBox = false;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
130 this.MinimizeBox = false;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
131 this.Name = "FrmArmyTree";
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
132 this.Text = "FrmArmyTree";
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
133 this.ResumeLayout(false);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
134
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
135 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
136 #endregion
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
137
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
138 private void ClearArmy()
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
139 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
140 htNodes.Clear();
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
141 treeView.Nodes.Clear();
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
142
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
143 ArrayList list = new ArrayList(htUnitWindows.Values);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
144
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
145 foreach (FrmUnit window in list)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
146 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
147 window.Close();
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
148 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
149
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
150 htUnitWindows.Clear();
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
151 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
152
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
153 private void SetArmy(Army army)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
154 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
155 if (army!=null)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
156 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
157 ArmyCategory[] cats = army.Categories;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
158 TreeNode[] catNodes = new TreeNode[cats.Length];
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
159 Unit[] units;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
160
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
161 for (int i = 0; i<cats.Length; i++)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
162 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
163 units = army.GetUnits(cats[i]);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
164 cats[i].NameChanged += TreeNameChangedMethod;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
165 TreeNode[] unitNodes = new TreeNode[units.Length];
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
166 TreeNode temp;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
167
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
168 for (int j = 0; j<units.Length; j++)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
169 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
170 unitNodes[j] = createTreeNode(units[j]);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
171 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
172
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
173 temp = new TreeNode(cats[i].Name, unitNodes);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
174 temp.Tag = cats[i];
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
175 catNodes[i] = temp;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
176 htNodes[cats[i].ID] = temp;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
177 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
178
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
179 TreeNode root = new TreeNode(army.Name, catNodes);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
180 root.Tag = army;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
181 treeView.Nodes.Add(root);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
182 root.ExpandAll();
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
183 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
184 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
185
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
186 private TreeNode createTreeNode(Unit unit)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
187 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
188 TreeNode temp = new TreeNode(unit.Name);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
189 temp.Tag = unit;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
190 unit.NameChanged+= UnitNameChangedMethod;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
191 htNodes[unit.ID] = temp;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
192 return temp;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
193 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
194
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
195 /*private void FrmArmyTree_Move(object sender, System.EventArgs e)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
196 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
197 if (ParentForm is FrmMain)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
198 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
199 FrmMain main = (FrmMain)ParentForm;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
200 main.Invoke(new MethodInvoker(main.MdiChildMoved));
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
201 }
0
7dd160dacb60 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
202 }*/
7dd160dacb60 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
203
7dd160dacb60 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
204 public void FrmArmyTree_ArmyChanged(Army oldArmy, Army newArmy)
17
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
205 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
206 if (oldArmy != null)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
207 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
208 oldArmy.UnitAdded -= UnitAddedMethod;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
209 oldArmy.UnitRemoved -= UnitRemovedMethod;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
210 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
211
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
212 if (newArmy != null)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
213 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
214 newArmy.UnitAdded += UnitAddedMethod;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
215 newArmy.UnitRemoved += UnitRemovedMethod;
10
19bdbb80999c Closes #47 - Remove magic numbers
IBBoard <dev@ibboard.co.uk>
parents: 3
diff changeset
216 SetArmy(newArmy);
0
7dd160dacb60 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
217 }
7dd160dacb60 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
218 else
7dd160dacb60 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
219 {
7dd160dacb60 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
220 ClearArmy();
7dd160dacb60 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
221 }
17
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
222 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
223
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
224 private void AddUnit(object obj)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
225 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
226 if (obj is Unit)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
227 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
228 Unit unit = (Unit)obj;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
229 ArmyCategory cat = unit.Category;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
230 TreeNode parent = (TreeNode)htNodes[cat.ID];
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
231 TreeNode unitNode = createTreeNode(unit);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
232 parent.Nodes.Add(unitNode);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
233 parent.Expand(); //make sure it's expanded
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
234 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
235 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
236
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
237 private void RemoveUnit(object obj)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
238 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
239 if (obj is Unit)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
240 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
241 Unit unit = (Unit)obj;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
242 removeUnit(unit);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
243 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
244 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
245
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
246 private void removeUnit(Unit unit)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
247 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
248 TreeNode unitNode = (TreeNode)htNodes[unit.ID];
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
249 unit.NameChanged-= UnitNameChangedMethod;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
250
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
251 if (unitNode!=null)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
252 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
253 unitNode.Remove();
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
254 htNodes.Remove(unit.ID);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
255 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
256 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
257
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
258
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
259 private void contextMenu_Popup(object sender, System.EventArgs e)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
260 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
261 TreeNode node = treeView.SelectedNode;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
262 if (node!=null && node.Tag is Unit)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
263 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
264 foreach(MenuItem item in contextMenu.MenuItems)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
265 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
266 item.Visible = true;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
267 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
268 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
269 else
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
270 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
271 foreach(MenuItem item in contextMenu.MenuItems)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
272 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
273 item.Visible = false;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
274 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
275 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
276 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
277
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
278 private void treeView_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
279 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
280 if (e.Button == MouseButtons.Right)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
281 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
282 TreeNode tn = treeView.GetNodeAt(e.X, e.Y);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
283
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
284 if (tn!=null)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
285 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
286 treeView.SelectedNode = tn;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
287 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
288 else
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
289 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
290 treeView.SelectedNode = null;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
291 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
292 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
293 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
294
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
295 private void miDelete_Click(object sender, System.EventArgs e)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
296 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
297 TreeNode selected = treeView.SelectedNode;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
298
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
299 if (selected.Tag!=null && selected.Tag is Unit)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
300 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
301 Unit unit = (Unit)selected.Tag;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
302 commandStack.Execute(new RemoveUnitCommand(unit));
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
303 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
304 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
305
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
306 private void miEdit_Click(object sender, System.EventArgs e)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
307 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
308 editUnit();
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
309 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
310
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
311 private void treeView_DoubleClick(object sender, System.EventArgs e)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
312 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
313 editUnit();
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
314 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
315
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
316 private void editUnit()
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
317 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
318 TreeNode selected = treeView.SelectedNode;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
319
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
320 if (selected.Tag!=null && selected.Tag is Unit)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
321 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
322 Unit unit = (Unit)selected.Tag;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
323
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
324 if (htUnitWindows.ContainsKey(unit.ID))
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
325 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
326 ((FrmUnit)htUnitWindows[unit.ID]).Focus();
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
327 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
328 else
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
329 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
330 FrmUnit unitForm = new FrmUnit(unit, commandStack);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
331 htUnitWindows.Add(unit.ID, unitForm);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
332 unitForm.MdiParent = this.MdiParent;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
333 unitForm.Closing+=new CancelEventHandler(unitForm_Closing);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
334 unitForm.Show();
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
335 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
336 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
337 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
338
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
339 private void UpdateUnitName(WarFoundryObject obj, string oldValue, string newValue)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
340 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
341 if (obj is Unit)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
342 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
343 Unit unit = (Unit)obj;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
344 TreeNode node = (TreeNode)htNodes[unit.ID];
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
345
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
346 if (node!=null)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
347 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
348 node.Text = unit.Name;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
349 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
350 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
351 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
352
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
353 private void UpdateArmyName(WarFoundryObject obj, string oldValue, string newValue)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
354 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
355 if (obj is Army)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
356 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
357 Army army = (Army)obj;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
358 TreeNode node = treeView.Nodes[0];
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
359
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
360 if (node!=null)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
361 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
362 node.Text = army.Name;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
363 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
364 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
365 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
366
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
367 private void unitForm_Closing(object sender, CancelEventArgs e)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
368 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
369 if (sender is FrmUnit)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
370 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
371 FrmUnit unitForm = (FrmUnit)sender;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
372 htUnitWindows.Remove(unitForm.Unit.ID);
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
373 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
374 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
375
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
376 private void FrmArmyTree_TreeNameChanged(WarFoundryObject obj, string oldValue, string newValue)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
377 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
378 TreeNode node = (TreeNode)htNodes[obj.ID];
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
379
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
380 if (node!=null)
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
381 {
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
382 node.Text = obj.Name;
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
383 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
384 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
385 }
475d3cdb75f4 * White space cleanup
IBBoard <dev@ibboard.co.uk>
parents: 10
diff changeset
386 }