annotate FrmArmyTree.cs @ 208:256f2f2f6e8c xml-export-ui

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