view api/Commands/ReplaceUnitEquipmentCommand.cs @ 82:3ea0ab04352b

* Fix line terminators no-open-ticket
author IBBoard <dev@ibboard.co.uk>
date Sat, 27 Jun 2009 18:59:49 +0000
parents 3a90f70dac73
children
line wrap: on
line source

// This file (ReplaceUnitEquipmentCommand.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard.
//
// 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.

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;
		
		public ReplaceUnitEquipmentCommand(Unit unit, UnitEquipmentItem oldItem, UnitEquipmentItem newItem, double 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"; }
		}
	}
}