Mercurial > repos > IBBoard.WarFoundry.API
comparison API/Commands/AbstractReplaceUnitEquipmentCommand.cs @ 337:3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 03 Apr 2011 18:50:32 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
336:3631c1493c7f | 337:3c4a6403a88c |
---|---|
1 // This file (AbstractReplaceUnitEquipmentCommand.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 and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING 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 /// <summary> | |
13 /// An abstract implementation of the core method for replacing one equipment item with another | |
14 /// </summary> | |
15 public abstract class AbstractReplaceUnitEquipmentCommand : Command | |
16 { | |
17 private SetUnitEquipmentNumericAmountCommand removeOldCommand; | |
18 private AbstractSetUnitEquipmentAmountCommand addNewCommand; | |
19 | |
20 public AbstractReplaceUnitEquipmentCommand(Unit unit, UnitEquipmentItem oldItem, AbstractSetUnitEquipmentAmountCommand addNewEquipmentCommand) | |
21 { | |
22 //We can get away with a numeric amount here even if it is a ratio item because we're setting it to 0 | |
23 removeOldCommand = new SetUnitEquipmentNumericAmountCommand(unit, oldItem, 0); | |
24 addNewCommand = addNewEquipmentCommand; | |
25 } | |
26 | |
27 public override bool CanExecute() | |
28 { | |
29 return removeOldCommand.CanExecute() && addNewCommand.CanExecute(); | |
30 } | |
31 | |
32 public override string Description | |
33 { | |
34 get | |
35 { | |
36 return Translation.GetTranslation("replaceUnitEquipmentCommandDescription", "replace {0} with {1} for {2}", removeOldCommand.EquipItem.Name, addNewCommand.EquipItem.Name, removeOldCommand.Unit.Name); | |
37 } | |
38 } | |
39 | |
40 public override string UndoDescription | |
41 { | |
42 get | |
43 { | |
44 return Translation.GetTranslation("replaceUnitEquipmentCommandUndoDescription", "replace {0} with {1} for {2}", addNewCommand.EquipItem.Name, removeOldCommand.EquipItem.Name, removeOldCommand.Unit.Name); | |
45 } | |
46 } | |
47 | |
48 public override bool Execute() | |
49 { | |
50 this.Redo(); | |
51 return true; | |
52 } | |
53 | |
54 public override void Redo() | |
55 { | |
56 removeOldCommand.Redo(); | |
57 addNewCommand.Redo(); | |
58 } | |
59 | |
60 public override void Undo() | |
61 { | |
62 addNewCommand.Undo(); | |
63 removeOldCommand.Undo(); | |
64 } | |
65 | |
66 public override string Name | |
67 { | |
68 get | |
69 { | |
70 return "Replace required equipment"; | |
71 } | |
72 } | |
73 } | |
74 } |