Mercurial > repos > IBDev-IBBoard.WarFoundry.API
comparison API/Commands/EditArmyCommand.cs @ 412:48098a2d17d0
Re #101: Make army names and sizes modifiable after creation
* Add command to edit name/size of army
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 29 Aug 2011 16:47:54 +0100 |
parents | |
children | 87f4710b7f8c |
comparison
equal
deleted
inserted
replaced
411:20274b5b0fd6 | 412:48098a2d17d0 |
---|---|
1 // This file (EditArmyCommand.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard | |
2 // | |
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. | |
4 using System; | |
5 using IBBoard.Commands; | |
6 using IBBoard.WarFoundry.API.Objects; | |
7 using IBBoard.Lang; | |
8 | |
9 namespace IBBoard.WarFoundry.API.Commands | |
10 { | |
11 public class EditArmyCommand : Command | |
12 { | |
13 private Army army; | |
14 private string oldName; | |
15 private int oldSize; | |
16 | |
17 public EditArmyCommand(Army toEdit) | |
18 { | |
19 army = toEdit; | |
20 } | |
21 | |
22 public override bool CanExecute() | |
23 { | |
24 return army != null && (NewName != null || NewSize > 0); | |
25 } | |
26 | |
27 public override bool Execute() | |
28 { | |
29 if (!army.HasDefaultName()) | |
30 { | |
31 oldName = army.Name; | |
32 } | |
33 | |
34 oldSize = army.MaxPoints; | |
35 Redo(); | |
36 return true; | |
37 } | |
38 | |
39 public override void Undo() | |
40 { | |
41 SetName(oldName); | |
42 SetSize(oldSize); | |
43 } | |
44 | |
45 public override void Redo() | |
46 { | |
47 SetName(NewName); | |
48 SetSize(NewSize); | |
49 } | |
50 | |
51 void SetName (string name) | |
52 { | |
53 if (NewName != null) | |
54 { | |
55 army.Name = name; | |
56 } | |
57 } | |
58 | |
59 void SetSize (int size) | |
60 { | |
61 if (NewSize > 0) | |
62 { | |
63 army.MaxPoints = size; | |
64 } | |
65 } | |
66 | |
67 public override string Name | |
68 { | |
69 get | |
70 { | |
71 return "Edit army"; | |
72 } | |
73 } | |
74 | |
75 public override string Description | |
76 { | |
77 get | |
78 { | |
79 return Translation.GetTranslation("editArmyCommandDescription", "edit army name and/or size"); | |
80 } | |
81 } | |
82 | |
83 public override string UndoDescription | |
84 { | |
85 get | |
86 { | |
87 return Translation.GetTranslation("editArmyCommandDescription", "revert army nnd/or size"); | |
88 } | |
89 } | |
90 | |
91 public string NewName { get; set; } | |
92 | |
93 public int NewSize { get; set; } | |
94 } | |
95 } | |
96 |