Mercurial > repos > IBDev-IBBoard.WarFoundry.API
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/api/Commands/ReplaceUnitEquipmentCommand.cs Fri Dec 19 15:57:51 2008 +0000 @@ -0,0 +1,63 @@ +using System; +using IBBoard.Commands; +using IBBoard.Lang; +using IBBoard.WarFoundry.API.Objects; + +namespace IBBoard.WarFoundry.API.Commands +{ + /// <summary> + /// Summary description for ReplaceUnitEquipmentCommand. + /// </summary> + public class ReplaceUnitEquipmentCommand : Command + { + private SetUnitEquipmentAmountCommand removeOldCommand, addNewCommand; + //private Unit unit; + //private EquipmentItem oldEquip, newEquip; + //private float newAmount, oldAmount; + + public ReplaceUnitEquipmentCommand(Unit unit, EquipmentItem oldItem, EquipmentItem newItem, float amount) + { + removeOldCommand = new SetUnitEquipmentAmountCommand(unit, oldItem, 0); + addNewCommand = new SetUnitEquipmentAmountCommand(unit, newItem, amount); + } + + public override bool CanExecute() + { + return removeOldCommand.CanExecute() && addNewCommand.CanExecute(); + } + + public override string Description + { + get { return "Replace "+StringManipulation.CutToLength(removeOldCommand.EquipItem.Name, 20)+" with "+StringManipulation.CutToLength(addNewCommand.EquipItem.Name, 20)+ " for "+StringManipulation.CutToLength(removeOldCommand.Unit.Name, 20); } + } + + public override string UndoDescription + { + get { return "Replace "+StringManipulation.CutToLength(addNewCommand.EquipItem.Name, 20)+" with "+StringManipulation.CutToLength(removeOldCommand.EquipItem.Name, 20)+ " for "+StringManipulation.CutToLength(removeOldCommand.Unit.Name, 20); } + } + + public override bool Execute() + { + this.Redo(); + return true; + } + + public override void Redo() + { + removeOldCommand.Redo(); + addNewCommand.Redo(); + } + + public override void Undo() + { + addNewCommand.Undo(); + removeOldCommand.Undo(); + } + + + public override string Name + { + get { return "Replace required equipment"; } + } + } +}