Mercurial > repos > IBBoard.WarFoundry.API
annotate api/Commands/CreateAndAddUnitCommand.cs @ 298:483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
* Merge translation-related changes from v0.1.1 branch
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 17 Jan 2011 20:02:41 +0000 |
parents | 391446c9b250 |
children |
rev | line source |
---|---|
104
2f3cafb69799
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
89
diff
changeset
|
1 // This file (CreateAndAddUnitCommand.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard. |
15 | 2 // |
104
2f3cafb69799
Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents:
89
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. |
82 | 4 |
5 using System; | |
0 | 6 using IBBoard.Commands; |
7 using IBBoard.Lang; | |
82 | 8 using IBBoard.WarFoundry.API.Objects; |
9 | |
10 namespace IBBoard.WarFoundry.API.Commands | |
11 { | |
12 public class CreateAndAddUnitCommand : Command | |
13 { | |
14 private UnitType addedUnitType; | |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
15 private ArmyCategory armyCat; |
58
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
16 private Unit addedUnit; |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
215
diff
changeset
|
17 |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
18 public CreateAndAddUnitCommand(UnitType toAdd, ArmyCategory armyCatTo) |
58
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
19 { |
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
20 addedUnitType = toAdd; |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
21 armyCat = armyCatTo; |
82 | 22 } |
23 | |
24 public override bool CanExecute() | |
25 { | |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
215
diff
changeset
|
26 return (addedUnitType != null && armyCat != null); |
82 | 27 } |
28 | |
29 public override string Description | |
30 { | |
215
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
31 get |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
32 { |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
215
diff
changeset
|
33 return Translation.GetTranslation("createAndAddUnitCommandDescription", "add unit of {0} to the army", addedUnitType.Name); |
215
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
34 } |
82 | 35 } |
58
e53ed2d613a1
Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
15
diff
changeset
|
36 |
82 | 37 public override string UndoDescription |
38 { | |
215
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
39 get |
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
40 { |
298
483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents:
215
diff
changeset
|
41 return Translation.GetTranslation("createAndAddUnitCommandUndoDescription", "remove unit of {0} from army", addedUnitType.Name); |
215
391446c9b250
Re #223: Use translations within the API
IBBoard <dev@ibboard.co.uk>
parents:
145
diff
changeset
|
42 } |
82 | 43 } |
44 | |
45 public override bool Execute() | |
46 { | |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
47 addedUnit = new Unit(addedUnitType, armyCat); |
82 | 48 this.Redo(); |
49 return true; | |
50 } | |
51 | |
52 public override void Redo() | |
53 { | |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
54 armyCat.AddUnit(addedUnit); |
82 | 55 } |
56 | |
57 public override void Undo() | |
89 | 58 { |
83
89cc29b4c012
Re #90: Stop new units showing up twice
IBBoard <dev@ibboard.co.uk>
parents:
82
diff
changeset
|
59 armyCat.RemoveUnit(addedUnit); |
82 | 60 } |
61 | |
62 public override string Name | |
63 { | |
64 get { return "Add new unit"; } | |
145 | 65 } |
66 | |
67 public Unit Unit | |
68 { | |
69 get { return addedUnit; } | |
82 | 70 } |
71 } | |
72 } |