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