15
|
1 // This file (CreateAndAddUnitCommand.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard.
|
|
2 //
|
|
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
|
|
4
|
0
|
5 using System;
|
|
6 using IBBoard.Commands;
|
|
7 using IBBoard.Lang;
|
|
8 using IBBoard.WarFoundry.API.Objects;
|
|
9
|
|
10 namespace IBBoard.WarFoundry.API.Commands
|
|
11 {
|
|
12 public class CreateAndAddUnitCommand : Command
|
|
13 {
|
|
14 private UnitType addedUnitType;
|
|
15 private Army army;
|
|
16 private ArmyCategory cat;
|
|
17 private Unit addedUnit;
|
|
18
|
|
19 public CreateAndAddUnitCommand(UnitType toAdd, ArmyCategory catTo, Army armyTo)
|
|
20 {
|
|
21 addedUnitType = toAdd;
|
|
22 cat = catTo;
|
|
23 army = armyTo;
|
|
24 }
|
|
25
|
|
26 public CreateAndAddUnitCommand(UnitType toAdd, Category catTo, Army armyTo) : this (toAdd, armyTo.GetCategory(catTo), armyTo)
|
|
27 {
|
|
28 }
|
|
29
|
|
30 public override bool CanExecute()
|
|
31 {
|
|
32 return (addedUnitType!=null && army!=null);
|
|
33 }
|
|
34
|
|
35 public override string Description
|
|
36 {
|
|
37 get { return "Add unit of "+StringManipulation.CutToLength(addedUnitType.Name, 20)+" to the army"; }
|
|
38 }
|
|
39
|
|
40 public override string UndoDescription
|
|
41 {
|
|
42 get { return "Remove unit of "+StringManipulation.CutToLength(addedUnitType.Name, 20)+" from army"; }
|
|
43 }
|
|
44
|
|
45 public override bool Execute()
|
|
46 {
|
|
47 addedUnit = new Unit(addedUnitType, army);
|
|
48 this.Redo();
|
|
49 return true;
|
|
50 }
|
|
51
|
|
52 public override void Redo()
|
|
53 {
|
|
54 cat.AddUnit(addedUnit);
|
|
55 }
|
|
56
|
|
57 public override void Undo()
|
|
58 {
|
|
59 cat.RemoveUnit(addedUnit);
|
|
60 }
|
|
61
|
|
62
|
|
63 public override string Name
|
|
64 {
|
|
65 get { return "Add new unit"; }
|
|
66 }
|
|
67 }
|
|
68 }
|