0
|
1 using System;
|
|
2 using IBBoard.Commands;
|
|
3 using IBBoard.Lang;
|
|
4 using IBBoard.WarFoundry.API.Objects;
|
|
5
|
|
6 namespace IBBoard.WarFoundry.API.Commands
|
|
7 {
|
|
8 /// <summary>
|
|
9 /// Summary description for AddUnitCommand.
|
|
10 /// </summary>
|
|
11 public class CreateAndAddUnitCommand : Command
|
|
12 {
|
|
13 private UnitType addedUnitType;
|
|
14 private Army army;
|
|
15 private ArmyCategory cat;
|
|
16 private Unit addedUnit;
|
|
17
|
|
18 public CreateAndAddUnitCommand(UnitType toAdd, ArmyCategory catTo, Army armyTo)
|
|
19 {
|
|
20 addedUnitType = toAdd;
|
|
21 cat = catTo;
|
|
22 army = armyTo;
|
|
23 }
|
|
24
|
|
25 public CreateAndAddUnitCommand(UnitType toAdd, Category catTo, Army armyTo) : this (toAdd, armyTo.GetCategory(catTo), armyTo)
|
|
26 {
|
|
27 }
|
|
28
|
|
29 public override bool CanExecute()
|
|
30 {
|
|
31 return (addedUnitType!=null && army!=null);
|
|
32 }
|
|
33
|
|
34 public override string Description
|
|
35 {
|
|
36 get { return "Add unit of "+StringManipulation.CutToLength(addedUnitType.Name, 20)+" to the army"; }
|
|
37 }
|
|
38
|
|
39 public override string UndoDescription
|
|
40 {
|
|
41 get { return "Remove unit of "+StringManipulation.CutToLength(addedUnitType.Name, 20)+" from army"; }
|
|
42 }
|
|
43
|
|
44 public override bool Execute()
|
|
45 {
|
|
46 addedUnit = new Unit(addedUnitType, army);
|
|
47 this.Redo();
|
|
48 return true;
|
|
49 }
|
|
50
|
|
51 public override void Redo()
|
|
52 {
|
|
53 cat.AddUnit(addedUnit);
|
|
54 }
|
|
55
|
|
56 public override void Undo()
|
|
57 {
|
|
58 cat.RemoveUnit(addedUnit);
|
|
59 }
|
|
60
|
|
61
|
|
62 public override string Name
|
|
63 {
|
|
64 get { return "Add new unit"; }
|
|
65 }
|
|
66 }
|
|
67 }
|