comparison api/Commands/ReplaceUnitEquipmentCommand.cs @ 0:520818033bb6

Initial commit of WarFoundry code
author IBBoard <dev@ibboard.co.uk>
date Fri, 19 Dec 2008 15:57:51 +0000
parents
children 306558904c2a
comparison
equal deleted inserted replaced
-1:000000000000 0:520818033bb6
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 ReplaceUnitEquipmentCommand.
10 /// </summary>
11 public class ReplaceUnitEquipmentCommand : Command
12 {
13 private SetUnitEquipmentAmountCommand removeOldCommand, addNewCommand;
14 //private Unit unit;
15 //private EquipmentItem oldEquip, newEquip;
16 //private float newAmount, oldAmount;
17
18 public ReplaceUnitEquipmentCommand(Unit unit, EquipmentItem oldItem, EquipmentItem newItem, float amount)
19 {
20 removeOldCommand = new SetUnitEquipmentAmountCommand(unit, oldItem, 0);
21 addNewCommand = new SetUnitEquipmentAmountCommand(unit, newItem, amount);
22 }
23
24 public override bool CanExecute()
25 {
26 return removeOldCommand.CanExecute() && addNewCommand.CanExecute();
27 }
28
29 public override string Description
30 {
31 get { return "Replace "+StringManipulation.CutToLength(removeOldCommand.EquipItem.Name, 20)+" with "+StringManipulation.CutToLength(addNewCommand.EquipItem.Name, 20)+ " for "+StringManipulation.CutToLength(removeOldCommand.Unit.Name, 20); }
32 }
33
34 public override string UndoDescription
35 {
36 get { return "Replace "+StringManipulation.CutToLength(addNewCommand.EquipItem.Name, 20)+" with "+StringManipulation.CutToLength(removeOldCommand.EquipItem.Name, 20)+ " for "+StringManipulation.CutToLength(removeOldCommand.Unit.Name, 20); }
37 }
38
39 public override bool Execute()
40 {
41 this.Redo();
42 return true;
43 }
44
45 public override void Redo()
46 {
47 removeOldCommand.Redo();
48 addNewCommand.Redo();
49 }
50
51 public override void Undo()
52 {
53 addNewCommand.Undo();
54 removeOldCommand.Undo();
55 }
56
57
58 public override string Name
59 {
60 get { return "Replace required equipment"; }
61 }
62 }
63 }