Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.WinForms
annotate FrmArmyTree.cs @ 60:c283545d2d0b
Re #168: Combine "required" and "optional" equipment boxes
* Alter "Unit" form to have a single weapon section
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 19 Sep 2009 13:57:35 +0000 |
parents | f272e70a9f71 |
children | a0ec03c24cd9 |
rev | line source |
---|---|
33 | 1 // This file (FrmArmyTree.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard. |
2 // | |
36 | 3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. |
33 | 4 |
5 using System; | |
6 using System.Drawing; | |
45
1c74b51abac1
Re #137: Remove use of old collections
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
7 using System.Collections.Generic; |
33 | 8 using System.ComponentModel; |
9 using System.Windows.Forms; | |
10 using IBBoard.Commands; | |
57
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
11 using IBBoard.Windows.Forms.I18N; |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
12 using IBBoard.Windows.Forms; |
33 | 13 using IBBoard.WarFoundry.API; |
14 using IBBoard.WarFoundry.API.Commands; | |
27
526fefefb16b
Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
24
diff
changeset
|
15 using IBBoard.WarFoundry.API.Objects; |
526fefefb16b
Fixes #91: Fix WinForms rendering of unit stats
IBBoard <dev@ibboard.co.uk>
parents:
24
diff
changeset
|
16 |
40
740350673006
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
17 namespace IBBoard.WarFoundry.GUI.WinForms |
33 | 18 { |
19 /// <summary> | |
20 /// Summary description for FrmArmyTree. | |
21 /// </summary> | |
22 public class FrmArmyTree : IBBoard.Windows.Forms.IBBForm | |
23 { | |
24 private System.Windows.Forms.TreeView treeView; | |
57
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
25 private IContainer components; |
49
93b3d23147ba
Fixes #160: Army tree is visible when no army is available
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
26 private Dictionary<string, TreeNode> nodes; |
33 | 27 private System.Windows.Forms.ContextMenu contextMenu; |
57
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
28 private IBBMenuItem miDelete; |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
29 private IBBMenuItem miEdit; |
49
93b3d23147ba
Fixes #160: Army tree is visible when no army is available
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
30 private Dictionary<string, FrmUnit> unitWindows; |
33 | 31 |
32 private ObjectAddDelegate UnitAddedMethod; | |
33 private ObjectRemoveDelegate UnitRemovedMethod; | |
34 private StringValChangedDelegate UnitNameChangedMethod, ArmyNameChangedMethod, TreeNameChangedMethod; | |
57
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
35 private ToolBar toolBar; |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
36 private IBBToolBarButton bttnEdit; |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
37 private IBBToolBarButton bttnDelete; |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
38 private ImageList imageList; |
33 | 39 private CommandStack commandStack; |
40 | |
41 public FrmArmyTree(CommandStack cmdStack) | |
42 { | |
43 commandStack = cmdStack; | |
44 InitializeComponent(); | |
45 UnitAddedMethod = new ObjectAddDelegate(AddUnit); | |
46 UnitRemovedMethod = new ObjectRemoveDelegate(RemoveUnit); | |
47 UnitNameChangedMethod = new StringValChangedDelegate(UpdateUnitName); | |
48 ArmyNameChangedMethod = new StringValChangedDelegate(UpdateArmyName); | |
49 TreeNameChangedMethod = new StringValChangedDelegate(FrmArmyTree_TreeNameChanged); | |
49
93b3d23147ba
Fixes #160: Army tree is visible when no army is available
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
50 nodes = new Dictionary<string, TreeNode>(); |
93b3d23147ba
Fixes #160: Army tree is visible when no army is available
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
51 unitWindows = new Dictionary<string, FrmUnit>(); |
33 | 52 this.Name = "ArmyTree"; |
53 WarFoundryCore.ArmyChanged+= new ArmyChangedDelegate(FrmArmyTree_ArmyChanged); | |
57
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
54 |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
55 foreach (Control ctrl in Controls) |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
56 { |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
57 ControlTranslator.TranslateControl(ctrl); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
58 } |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
59 |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
60 foreach (Component comp in components.Components) |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
61 { |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
62 ControlTranslator.TranslateComponent(comp); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
63 } |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
64 |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
65 foreach (IBBMenuItem mi in contextMenu.MenuItems) |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
66 { |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
67 ControlTranslator.TranslateComponent(mi); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
68 } |
33 | 69 } |
70 | |
71 public FrmArmyTree(Army army, CommandStack cmdStack) : this(cmdStack) | |
72 { | |
73 SetArmy(army); | |
74 } | |
75 | |
76 /// <summary> | |
77 /// Clean up any resources being used. | |
78 /// </summary> | |
79 protected override void Dispose( bool disposing ) | |
80 { | |
81 if( disposing ) | |
82 { | |
83 if(components != null) | |
84 { | |
85 components.Dispose(); | |
86 } | |
87 } | |
88 base.Dispose( disposing ); | |
89 } | |
90 | |
91 #region Windows Form Designer generated code | |
92 /// <summary> | |
93 /// Required method for Designer support - do not modify | |
94 /// the contents of this method with the code editor. | |
95 /// </summary> | |
96 private void InitializeComponent() | |
97 { | |
57
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
98 this.components = new System.ComponentModel.Container(); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
99 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmArmyTree)); |
33 | 100 this.contextMenu = new System.Windows.Forms.ContextMenu(); |
57
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
101 this.miEdit = new IBBoard.Windows.Forms.IBBMenuItem(); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
102 this.miDelete = new IBBoard.Windows.Forms.IBBMenuItem(); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
103 this.imageList = new System.Windows.Forms.ImageList(this.components); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
104 this.toolBar = new System.Windows.Forms.ToolBar(); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
105 this.bttnEdit = new IBBoard.Windows.Forms.IBBToolBarButton(); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
106 this.bttnDelete = new IBBoard.Windows.Forms.IBBToolBarButton(); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
107 this.treeView = new System.Windows.Forms.TreeView(); |
33 | 108 this.SuspendLayout(); |
109 // | |
110 // contextMenu | |
111 // | |
112 this.contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { | |
57
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
113 this.miEdit, |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
114 this.miDelete}); |
33 | 115 this.contextMenu.Popup += new System.EventHandler(this.contextMenu_Popup); |
116 // | |
117 // miEdit | |
118 // | |
119 this.miEdit.Index = 0; | |
57
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
120 this.miEdit.Text = "&edit unit"; |
33 | 121 this.miEdit.Click += new System.EventHandler(this.miEdit_Click); |
122 // | |
123 // miDelete | |
124 // | |
125 this.miDelete.Index = 1; | |
57
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
126 this.miDelete.Text = "&delete unit"; |
33 | 127 this.miDelete.Click += new System.EventHandler(this.miDelete_Click); |
128 // | |
57
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
129 // imageList |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
130 // |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
131 this.imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer) (resources.GetObject("imageList.ImageStream"))); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
132 this.imageList.TransparentColor = System.Drawing.Color.Transparent; |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
133 this.imageList.Images.SetKeyName(0, "gtk-edit.png"); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
134 this.imageList.Images.SetKeyName(1, "edit-delete.png"); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
135 // |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
136 // toolBar |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
137 // |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
138 this.toolBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] { |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
139 this.bttnEdit, |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
140 this.bttnDelete}); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
141 this.toolBar.ButtonSize = new System.Drawing.Size(16, 16); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
142 this.toolBar.DropDownArrows = true; |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
143 this.toolBar.ImageList = this.imageList; |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
144 this.toolBar.Location = new System.Drawing.Point(0, 0); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
145 this.toolBar.Name = "toolBar"; |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
146 this.toolBar.ShowToolTips = true; |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
147 this.toolBar.Size = new System.Drawing.Size(240, 28); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
148 this.toolBar.TabIndex = 3; |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
149 this.toolBar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar_ButtonClick); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
150 // |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
151 // bttnEdit |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
152 // |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
153 this.bttnEdit.Enabled = false; |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
154 this.bttnEdit.ImageIndex = 0; |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
155 this.bttnEdit.Name = "bttnEdit"; |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
156 // |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
157 // bttnDelete |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
158 // |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
159 this.bttnDelete.Enabled = false; |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
160 this.bttnDelete.ImageIndex = 1; |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
161 this.bttnDelete.Name = "bttnDelete"; |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
162 // |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
163 // treeView |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
164 // |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
165 this.treeView.Anchor = ((System.Windows.Forms.AnchorStyles) ((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
166 | System.Windows.Forms.AnchorStyles.Left) |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
167 | System.Windows.Forms.AnchorStyles.Right))); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
168 this.treeView.ContextMenu = this.contextMenu; |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
169 this.treeView.FullRowSelect = true; |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
170 this.treeView.Location = new System.Drawing.Point(0, 28); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
171 this.treeView.Name = "treeView"; |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
172 this.treeView.Size = new System.Drawing.Size(240, 250); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
173 this.treeView.TabIndex = 0; |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
174 this.treeView.DoubleClick += new System.EventHandler(this.treeView_DoubleClick); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
175 this.treeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView_AfterSelect); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
176 this.treeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeView_MouseDown); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
177 // |
33 | 178 // FrmArmyTree |
179 // | |
180 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); | |
181 this.ClientSize = new System.Drawing.Size(240, 277); | |
182 this.ControlBox = false; | |
57
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
183 this.Controls.Add(this.toolBar); |
33 | 184 this.Controls.Add(this.treeView); |
185 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow; | |
186 this.MaximizeBox = false; | |
187 this.MinimizeBox = false; | |
188 this.Name = "FrmArmyTree"; | |
189 this.Text = "FrmArmyTree"; | |
190 this.ResumeLayout(false); | |
57
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
191 this.PerformLayout(); |
33 | 192 |
193 } | |
194 #endregion | |
195 | |
196 private void ClearArmy() | |
197 { | |
49
93b3d23147ba
Fixes #160: Army tree is visible when no army is available
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
198 nodes.Clear(); |
33 | 199 treeView.Nodes.Clear(); |
49
93b3d23147ba
Fixes #160: Army tree is visible when no army is available
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
200 FrmUnit[] unitForms = DictionaryUtils.ToArray(unitWindows); |
33 | 201 |
44
1486ccd744dc
Fixes #135: Closing army crashes WinForms
IBBoard <dev@ibboard.co.uk>
parents:
40
diff
changeset
|
202 foreach (FrmUnit window in unitForms) |
33 | 203 { |
204 window.Close(); | |
205 } | |
206 | |
49
93b3d23147ba
Fixes #160: Army tree is visible when no army is available
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
207 unitWindows.Clear(); |
33 | 208 } |
209 | |
210 private void SetArmy(Army army) | |
211 { | |
212 ClearArmy(); | |
213 | |
214 if (army != null) | |
215 { | |
216 ArmyCategory[] cats = army.Categories; | |
217 TreeNode[] catNodes = new TreeNode[cats.Length]; | |
218 Unit[] units; | |
219 | |
220 for (int i = 0; i < cats.Length; i++) | |
221 { | |
222 units = army.GetUnits(cats[i]); | |
223 cats[i].NameChanged += TreeNameChangedMethod; | |
224 TreeNode[] unitNodes = new TreeNode[units.Length]; | |
225 TreeNode temp; | |
226 | |
227 for (int j = 0; j < units.Length; j++) | |
228 { | |
229 unitNodes[j] = createTreeNode(units[j]); | |
230 } | |
231 | |
232 temp = new TreeNode(cats[i].Name, unitNodes); | |
233 temp.Tag = cats[i]; | |
234 catNodes[i] = temp; | |
49
93b3d23147ba
Fixes #160: Army tree is visible when no army is available
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
235 nodes[cats[i].ID] = temp; |
33 | 236 } |
237 | |
238 TreeNode root = new TreeNode(army.Name, catNodes); | |
239 root.Tag = army; | |
240 treeView.Nodes.Add(root); | |
241 root.ExpandAll(); | |
242 } | |
243 } | |
244 | |
245 private TreeNode createTreeNode(Unit unit) | |
246 { | |
247 TreeNode temp = new TreeNode(unit.Name); | |
248 temp.Tag = unit; | |
249 unit.NameChanged+= UnitNameChangedMethod; | |
49
93b3d23147ba
Fixes #160: Army tree is visible when no army is available
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
250 nodes[unit.ID] = temp; |
33 | 251 return temp; |
252 } | |
253 | |
254 /*private void FrmArmyTree_Move(object sender, System.EventArgs e) | |
255 { | |
256 if (ParentForm is FrmMain) | |
257 { | |
258 FrmMain main = (FrmMain)ParentForm; | |
259 main.Invoke(new MethodInvoker(main.MdiChildMoved)); | |
260 } | |
261 }*/ | |
262 | |
263 public void FrmArmyTree_ArmyChanged(Army oldArmy, Army newArmy) | |
264 { | |
265 if (oldArmy != null) | |
266 { | |
267 oldArmy.UnitAdded -= UnitAddedMethod; | |
268 oldArmy.UnitRemoved -= UnitRemovedMethod; | |
269 } | |
270 | |
271 if (newArmy != null) | |
272 { | |
273 newArmy.UnitAdded += UnitAddedMethod; | |
274 newArmy.UnitRemoved += UnitRemovedMethod; | |
275 } | |
276 | |
277 SetArmy(newArmy); | |
278 } | |
45
1c74b51abac1
Re #137: Remove use of old collections
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
279 |
1c74b51abac1
Re #137: Remove use of old collections
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
280 private void AddUnit(WarFoundryObject obj) |
33 | 281 { |
282 if (obj is Unit) | |
283 { | |
284 Unit unit = (Unit)obj; | |
285 ArmyCategory cat = unit.Category; | |
49
93b3d23147ba
Fixes #160: Army tree is visible when no army is available
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
286 TreeNode parent = nodes[cat.ID]; |
33 | 287 TreeNode unitNode = createTreeNode(unit); |
288 parent.Nodes.Add(unitNode); | |
289 parent.Expand(); //make sure it's expanded | |
290 } | |
291 } | |
292 | |
45
1c74b51abac1
Re #137: Remove use of old collections
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
293 private void RemoveUnit(WarFoundryObject obj) |
33 | 294 { |
295 if (obj is Unit) | |
296 { | |
297 Unit unit = (Unit)obj; | |
45
1c74b51abac1
Re #137: Remove use of old collections
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
298 RemoveUnitFromTree(unit); |
33 | 299 } |
300 } | |
301 | |
45
1c74b51abac1
Re #137: Remove use of old collections
IBBoard <dev@ibboard.co.uk>
parents:
44
diff
changeset
|
302 private void RemoveUnitFromTree(Unit unit) |
33 | 303 { |
49
93b3d23147ba
Fixes #160: Army tree is visible when no army is available
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
304 TreeNode unitNode = nodes[unit.ID]; |
33 | 305 unit.NameChanged-= UnitNameChangedMethod; |
306 | |
307 if (unitNode!=null) | |
308 { | |
309 unitNode.Remove(); | |
49
93b3d23147ba
Fixes #160: Army tree is visible when no army is available
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
310 nodes.Remove(unit.ID); |
33 | 311 } |
312 } | |
313 | |
314 | |
315 private void contextMenu_Popup(object sender, System.EventArgs e) | |
316 { | |
317 TreeNode node = treeView.SelectedNode; | |
57
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
318 |
33 | 319 if (node!=null && node.Tag is Unit) |
320 { | |
321 foreach(MenuItem item in contextMenu.MenuItems) | |
322 { | |
323 item.Visible = true; | |
324 } | |
325 } | |
326 else | |
327 { | |
328 foreach(MenuItem item in contextMenu.MenuItems) | |
329 { | |
330 item.Visible = false; | |
331 } | |
332 } | |
333 } | |
334 | |
335 private void treeView_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) | |
336 { | |
337 if (e.Button == MouseButtons.Right) | |
338 { | |
339 TreeNode tn = treeView.GetNodeAt(e.X, e.Y); | |
340 | |
341 if (tn!=null) | |
342 { | |
343 treeView.SelectedNode = tn; | |
344 } | |
345 else | |
346 { | |
347 treeView.SelectedNode = null; | |
348 } | |
349 } | |
350 } | |
351 | |
352 private void miDelete_Click(object sender, System.EventArgs e) | |
353 { | |
57
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
354 DeleteUnit(); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
355 } |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
356 |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
357 private void DeleteUnit() |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
358 { |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
359 |
33 | 360 TreeNode selected = treeView.SelectedNode; |
361 | |
57
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
362 if (selected.Tag != null && selected.Tag is Unit) |
33 | 363 { |
57
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
364 Unit unit = (Unit) selected.Tag; |
33 | 365 commandStack.Execute(new RemoveUnitCommand(unit)); |
366 } | |
367 } | |
368 | |
369 private void miEdit_Click(object sender, System.EventArgs e) | |
370 { | |
49
93b3d23147ba
Fixes #160: Army tree is visible when no army is available
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
371 EditUnit(); |
33 | 372 } |
373 | |
374 private void treeView_DoubleClick(object sender, System.EventArgs e) | |
375 { | |
49
93b3d23147ba
Fixes #160: Army tree is visible when no army is available
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
376 EditUnit(); |
33 | 377 } |
378 | |
49
93b3d23147ba
Fixes #160: Army tree is visible when no army is available
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
379 private void EditUnit() |
33 | 380 { |
381 TreeNode selected = treeView.SelectedNode; | |
50
c972fb283675
Fixes #149: Crash with edit on null tree item
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
382 object tagData = selected.Tag; |
33 | 383 |
50
c972fb283675
Fixes #149: Crash with edit on null tree item
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
384 if (tagData is Unit) |
33 | 385 { |
50
c972fb283675
Fixes #149: Crash with edit on null tree item
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
386 Unit unit = (Unit) tagData; |
c972fb283675
Fixes #149: Crash with edit on null tree item
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
387 string unitID = unit.ID; |
33 | 388 |
50
c972fb283675
Fixes #149: Crash with edit on null tree item
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
389 if (unitWindows.ContainsKey(unitID)) |
33 | 390 { |
50
c972fb283675
Fixes #149: Crash with edit on null tree item
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
391 unitWindows[unitID].Focus(); |
33 | 392 } |
393 else | |
394 { | |
395 FrmUnit unitForm = new FrmUnit(unit, commandStack); | |
50
c972fb283675
Fixes #149: Crash with edit on null tree item
IBBoard <dev@ibboard.co.uk>
parents:
49
diff
changeset
|
396 unitWindows.Add(unitID, unitForm); |
33 | 397 unitForm.MdiParent = this.MdiParent; |
398 unitForm.Closing+=new CancelEventHandler(unitForm_Closing); | |
399 unitForm.Show(); | |
400 } | |
401 } | |
402 } | |
403 | |
404 private void UpdateUnitName(WarFoundryObject obj, string oldValue, string newValue) | |
405 { | |
406 if (obj is Unit) | |
407 { | |
408 Unit unit = (Unit)obj; | |
49
93b3d23147ba
Fixes #160: Army tree is visible when no army is available
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
409 TreeNode node = nodes[unit.ID]; |
33 | 410 |
411 if (node!=null) | |
412 { | |
413 node.Text = unit.Name; | |
414 } | |
415 } | |
416 } | |
417 | |
418 private void UpdateArmyName(WarFoundryObject obj, string oldValue, string newValue) | |
419 { | |
420 if (obj is Army) | |
421 { | |
422 Army army = (Army)obj; | |
423 TreeNode node = treeView.Nodes[0]; | |
424 | |
425 if (node!=null) | |
426 { | |
427 node.Text = army.Name; | |
428 } | |
429 } | |
430 } | |
431 | |
432 private void unitForm_Closing(object sender, CancelEventArgs e) | |
433 { | |
434 if (sender is FrmUnit) | |
435 { | |
436 FrmUnit unitForm = (FrmUnit)sender; | |
49
93b3d23147ba
Fixes #160: Army tree is visible when no army is available
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
437 unitWindows.Remove(unitForm.Unit.ID); |
33 | 438 } |
439 } | |
440 | |
441 private void FrmArmyTree_TreeNameChanged(WarFoundryObject obj, string oldValue, string newValue) | |
442 { | |
49
93b3d23147ba
Fixes #160: Army tree is visible when no army is available
IBBoard <dev@ibboard.co.uk>
parents:
45
diff
changeset
|
443 TreeNode node = nodes[obj.ID]; |
33 | 444 |
445 if (node!=null) | |
446 { | |
447 node.Text = obj.Name; | |
448 } | |
449 } | |
57
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
450 |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
451 private void toolBar_ButtonClick(object sender, ToolBarButtonClickEventArgs e) |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
452 { |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
453 if (e.Button == bttnDelete) |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
454 { |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
455 DeleteUnit(); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
456 } |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
457 else if (e.Button == bttnEdit) |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
458 { |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
459 EditUnit(); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
460 } |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
461 } |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
462 |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
463 private void treeView_AfterSelect(object sender, TreeViewEventArgs e) |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
464 { |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
465 TreeNode node = treeView.SelectedNode; |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
466 |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
467 bttnDelete.Enabled = (node != null && node.Tag is Unit); |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
468 bttnEdit.Enabled = bttnDelete.Enabled; |
f272e70a9f71
Fixes #169: Add more obvious edit and delete options to Army Tree
IBBoard <dev@ibboard.co.uk>
parents:
50
diff
changeset
|
469 } |
33 | 470 } |
471 } |