15
|
1 // This file (SetUnitEquipmentAmountCommand.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 SetUnitEquipmentAmountCommand.
|
|
14 /// </summary>
|
|
15 public class SetUnitEquipmentAmountCommand : Command
|
|
16 {
|
|
17 private Unit unit;
|
|
18 private EquipmentItem equip;
|
|
19 private float newAmount, oldAmount;
|
|
20
|
|
21 public SetUnitEquipmentAmountCommand(Unit unit, EquipmentItem item, float amount)
|
|
22 {
|
|
23 this.unit = unit;
|
|
24 equip = item;
|
|
25 newAmount = amount;
|
|
26 oldAmount = unit.GetEquipmentAmount(equip.ID);
|
|
27 }
|
|
28
|
|
29 public override bool CanExecute()
|
|
30 {
|
|
31 return (unit!=null && equip!=null);
|
|
32 }
|
|
33
|
|
34 public override string Description
|
|
35 {
|
|
36 get { return "Set "+StringManipulation.CutToLength(equip.Name, 20)+" amount for "+StringManipulation.CutToLength(unit.Name, 20)+" to "+UnitEquipmentItemObj.FormatEquipmentAmount(equip, newAmount); }
|
|
37 }
|
|
38
|
|
39 public override string UndoDescription
|
|
40 {
|
|
41 get { return "Set "+StringManipulation.CutToLength(equip.Name, 20)+" amount for "+StringManipulation.CutToLength(unit.Name, 20)+" to "+UnitEquipmentItemObj.FormatEquipmentAmount(equip, oldAmount); }
|
|
42 }
|
|
43
|
|
44 public override bool Execute()
|
|
45 {
|
|
46 this.Redo();
|
|
47 return true;
|
|
48 }
|
|
49
|
|
50 public override void Redo()
|
|
51 {
|
|
52 unit.SetEquipmentAmount(equip.ID, newAmount);
|
|
53 }
|
|
54
|
|
55 public override void Undo()
|
|
56 {
|
|
57 unit.SetEquipmentAmount(equip.ID, oldAmount);
|
|
58 }
|
|
59
|
|
60 public override string Name
|
|
61 {
|
|
62 get { return "Set equipment amount"; }
|
|
63 }
|
|
64
|
|
65 public EquipmentItem EquipItem
|
|
66 {
|
|
67 get { return equip; }
|
|
68 }
|
|
69
|
|
70 public Unit Unit
|
|
71 {
|
|
72 get { return unit; }
|
|
73 }
|
|
74 }
|
|
75 }
|