15
|
1 // This file (ReplaceUnitEquipmentCommand.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 /// <summary>
|
|
13 /// Summary description for ReplaceUnitEquipmentCommand.
|
|
14 /// </summary>
|
|
15 public class ReplaceUnitEquipmentCommand : Command
|
|
16 {
|
|
17 private SetUnitEquipmentAmountCommand removeOldCommand, addNewCommand;
|
|
18 //private Unit unit;
|
|
19 //private EquipmentItem oldEquip, newEquip;
|
|
20 //private float newAmount, oldAmount;
|
|
21
|
|
22 public ReplaceUnitEquipmentCommand(Unit unit, EquipmentItem oldItem, EquipmentItem newItem, float amount)
|
|
23 {
|
|
24 removeOldCommand = new SetUnitEquipmentAmountCommand(unit, oldItem, 0);
|
|
25 addNewCommand = new SetUnitEquipmentAmountCommand(unit, newItem, amount);
|
|
26 }
|
|
27
|
|
28 public override bool CanExecute()
|
|
29 {
|
|
30 return removeOldCommand.CanExecute() && addNewCommand.CanExecute();
|
|
31 }
|
|
32
|
|
33 public override string Description
|
|
34 {
|
|
35 get { return "Replace "+StringManipulation.CutToLength(removeOldCommand.EquipItem.Name, 20)+" with "+StringManipulation.CutToLength(addNewCommand.EquipItem.Name, 20)+ " for "+StringManipulation.CutToLength(removeOldCommand.Unit.Name, 20); }
|
|
36 }
|
|
37
|
|
38 public override string UndoDescription
|
|
39 {
|
|
40 get { return "Replace "+StringManipulation.CutToLength(addNewCommand.EquipItem.Name, 20)+" with "+StringManipulation.CutToLength(removeOldCommand.EquipItem.Name, 20)+ " for "+StringManipulation.CutToLength(removeOldCommand.Unit.Name, 20); }
|
|
41 }
|
|
42
|
|
43 public override bool Execute()
|
|
44 {
|
|
45 this.Redo();
|
|
46 return true;
|
|
47 }
|
|
48
|
|
49 public override void Redo()
|
|
50 {
|
|
51 removeOldCommand.Redo();
|
|
52 addNewCommand.Redo();
|
|
53 }
|
|
54
|
|
55 public override void Undo()
|
|
56 {
|
|
57 addNewCommand.Undo();
|
|
58 removeOldCommand.Undo();
|
|
59 }
|
|
60
|
|
61
|
|
62 public override string Name
|
|
63 {
|
|
64 get { return "Replace required equipment"; }
|
|
65 }
|
|
66 }
|
|
67 }
|