| 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 | |
|---|
| 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 Unit addedUnit; |
|---|
| 17 | |
|---|
| 18 | public CreateAndAddUnitCommand(UnitType toAdd, Army armyTo) |
|---|
| 19 | { |
|---|
| 20 | addedUnitType = toAdd; |
|---|
| 21 | army = armyTo; |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | [Obsolete("Use two parameter constructor instead")] |
|---|
| 25 | public CreateAndAddUnitCommand(UnitType toAdd, ArmyCategory catTo, Army armyTo) : this(toAdd, armyTo) |
|---|
| 26 | { |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | [Obsolete("Use two parameter constructor instead")] |
|---|
| 30 | public CreateAndAddUnitCommand(UnitType toAdd, Category catTo, Army armyTo) : this (toAdd, armyTo.GetCategory(catTo), armyTo) |
|---|
| 31 | { |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | public override bool CanExecute() |
|---|
| 35 | { |
|---|
| 36 | return (addedUnitType!=null && army!=null); |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | public override string Description |
|---|
| 40 | { |
|---|
| 41 | get { return "Add unit of "+StringManipulation.CutToLength(addedUnitType.Name, 20)+" to the army"; } |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | public override string UndoDescription |
|---|
| 45 | { |
|---|
| 46 | get { return "Remove unit of "+StringManipulation.CutToLength(addedUnitType.Name, 20)+" from army"; } |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | public override bool Execute() |
|---|
| 50 | { |
|---|
| 51 | addedUnit = new Unit(addedUnitType, army); |
|---|
| 52 | this.Redo(); |
|---|
| 53 | return true; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | public override void Redo() |
|---|
| 57 | { |
|---|
| 58 | army.AddUnit(addedUnit); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | public override void Undo() |
|---|
| 62 | { |
|---|
| 63 | army.RemoveUnit(addedUnit); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | public override string Name |
|---|
| 68 | { |
|---|
| 69 | get { return "Add new unit"; } |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | } |
|---|