Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.WinForms
comparison FrmArmyTree.cs @ 10:19bdbb80999c
Closes #47 - Remove magic numbers
* Replace "magic number" -1s in WinForms with WarFoundryCore.INFINITY
Also:
* Code cleanup to remove warnings
* Code cleanup to replace space indentation with tabs
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 19 May 2009 18:51:32 +0000 |
parents | 8935971e307c |
children | 475d3cdb75f4 |
comparison
equal
deleted
inserted
replaced
9:ffb49ec86df7 | 10:19bdbb80999c |
---|---|
32 private Hashtable htUnitWindows; | 32 private Hashtable htUnitWindows; |
33 | 33 |
34 private ObjectAddDelegate UnitAddedMethod; | 34 private ObjectAddDelegate UnitAddedMethod; |
35 private ObjectRemoveDelegate UnitRemovedMethod; | 35 private ObjectRemoveDelegate UnitRemovedMethod; |
36 private StringValChangedDelegate UnitNameChangedMethod, ArmyNameChangedMethod, TreeNameChangedMethod; | 36 private StringValChangedDelegate UnitNameChangedMethod, ArmyNameChangedMethod, TreeNameChangedMethod; |
37 private CommandStack commandStack; | 37 private CommandStack commandStack; |
38 | 38 |
39 public FrmArmyTree(CommandStack cmdStack) | 39 public FrmArmyTree(CommandStack cmdStack) |
40 { | 40 { |
41 commandStack = cmdStack; | 41 commandStack = cmdStack; |
42 InitializeComponent(); | 42 InitializeComponent(); |
43 UnitAddedMethod = new ObjectAddDelegate(AddUnit); | 43 UnitAddedMethod = new ObjectAddDelegate(AddUnit); |
44 UnitRemovedMethod = new ObjectRemoveDelegate(RemoveUnit); | 44 UnitRemovedMethod = new ObjectRemoveDelegate(RemoveUnit); |
45 UnitNameChangedMethod = new StringValChangedDelegate(UpdateUnitName); | 45 UnitNameChangedMethod = new StringValChangedDelegate(UpdateUnitName); |
46 ArmyNameChangedMethod = new StringValChangedDelegate(UpdateArmyName); | 46 ArmyNameChangedMethod = new StringValChangedDelegate(UpdateArmyName); |
159 Unit[] units; | 159 Unit[] units; |
160 | 160 |
161 for (int i = 0; i<cats.Length; i++) | 161 for (int i = 0; i<cats.Length; i++) |
162 { | 162 { |
163 units = army.GetUnits(cats[i]); | 163 units = army.GetUnits(cats[i]); |
164 cats[i].NameChanged += TreeNameChangedMethod; | 164 cats[i].NameChanged += TreeNameChangedMethod; |
165 TreeNode[] unitNodes = new TreeNode[units.Length]; | 165 TreeNode[] unitNodes = new TreeNode[units.Length]; |
166 TreeNode temp; | 166 TreeNode temp; |
167 | 167 |
168 for (int j = 0; j<units.Length; j++) | 168 for (int j = 0; j<units.Length; j++) |
169 { | 169 { |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 private TreeNode createTreeNode(Unit unit) | 186 private TreeNode createTreeNode(Unit unit) |
187 { | 187 { |
188 TreeNode temp = new TreeNode(unit.Name); | 188 TreeNode temp = new TreeNode(unit.Name); |
189 temp.Tag = unit; | 189 temp.Tag = unit; |
190 unit.NameChanged+= UnitNameChangedMethod; | 190 unit.NameChanged+= UnitNameChangedMethod; |
191 htNodes[unit.ID] = temp; | 191 htNodes[unit.ID] = temp; |
192 return temp; | 192 return temp; |
193 } | 193 } |
201 } | 201 } |
202 }*/ | 202 }*/ |
203 | 203 |
204 public void FrmArmyTree_ArmyChanged(Army oldArmy, Army newArmy) | 204 public void FrmArmyTree_ArmyChanged(Army oldArmy, Army newArmy) |
205 { | 205 { |
206 if (oldArmy != null) | 206 if (oldArmy != null) |
207 { | 207 { |
208 oldArmy.UnitAdded -= UnitAddedMethod; | 208 oldArmy.UnitAdded -= UnitAddedMethod; |
209 oldArmy.UnitRemoved -= UnitRemovedMethod; | 209 oldArmy.UnitRemoved -= UnitRemovedMethod; |
210 } | 210 } |
211 | 211 |
212 if (newArmy != null) | 212 if (newArmy != null) |
213 { | 213 { |
214 newArmy.UnitAdded += UnitAddedMethod; | 214 newArmy.UnitAdded += UnitAddedMethod; |
215 newArmy.UnitRemoved += UnitRemovedMethod; | 215 newArmy.UnitRemoved += UnitRemovedMethod; |
216 SetArmy(newArmy); | 216 SetArmy(newArmy); |
217 } | 217 } |
218 else | 218 else |
219 { | 219 { |
220 ClearArmy(); | 220 ClearArmy(); |
221 } | 221 } |
343 Unit unit = (Unit)obj; | 343 Unit unit = (Unit)obj; |
344 TreeNode node = (TreeNode)htNodes[unit.ID]; | 344 TreeNode node = (TreeNode)htNodes[unit.ID]; |
345 | 345 |
346 if (node!=null) | 346 if (node!=null) |
347 { | 347 { |
348 node.Text = unit.Name; | 348 node.Text = unit.Name; |
349 } | 349 } |
350 } | 350 } |
351 } | 351 } |
352 | 352 |
353 private void UpdateArmyName(WarFoundryObject obj, string oldValue, string newValue) | 353 private void UpdateArmyName(WarFoundryObject obj, string oldValue, string newValue) |
357 Army army = (Army)obj; | 357 Army army = (Army)obj; |
358 TreeNode node = treeView.Nodes[0]; | 358 TreeNode node = treeView.Nodes[0]; |
359 | 359 |
360 if (node!=null) | 360 if (node!=null) |
361 { | 361 { |
362 node.Text = army.Name; | 362 node.Text = army.Name; |
363 } | 363 } |
364 } | 364 } |
365 } | 365 } |
366 | 366 |
367 private void unitForm_Closing(object sender, CancelEventArgs e) | 367 private void unitForm_Closing(object sender, CancelEventArgs e) |
377 { | 377 { |
378 TreeNode node = (TreeNode)htNodes[obj.ID]; | 378 TreeNode node = (TreeNode)htNodes[obj.ID]; |
379 | 379 |
380 if (node!=null) | 380 if (node!=null) |
381 { | 381 { |
382 node.Text = obj.Name; | 382 node.Text = obj.Name; |
383 } | 383 } |
384 } | 384 } |
385 } | 385 } |
386 } | 386 } |