changeset 413:48098a2d17d0

Re #101: Make army names and sizes modifiable after creation * Add command to edit name/size of army
author IBBoard <dev@ibboard.co.uk>
date Mon, 29 Aug 2011 16:47:54 +0100
parents 20274b5b0fd6
children 3f297a60db1e
files API/Commands/EditArmyCommand.cs IBBoard.WarFoundry.API.csproj
diffstat 2 files changed, 98 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/API/Commands/EditArmyCommand.cs	Mon Aug 29 16:47:54 2011 +0100
     1.3 @@ -0,0 +1,96 @@
     1.4 +// This file (EditArmyCommand.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard
     1.5 +// 
     1.6 +// 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.
     1.7 +using System;
     1.8 +using IBBoard.Commands;
     1.9 +using IBBoard.WarFoundry.API.Objects;
    1.10 +using IBBoard.Lang;
    1.11 +
    1.12 +namespace IBBoard.WarFoundry.API.Commands
    1.13 +{
    1.14 +	public class EditArmyCommand : Command
    1.15 +	{
    1.16 +		private Army army;
    1.17 +		private string oldName;
    1.18 +		private int oldSize;
    1.19 +
    1.20 +		public EditArmyCommand(Army toEdit)
    1.21 +		{
    1.22 +			army = toEdit;
    1.23 +		}
    1.24 +
    1.25 +		public override bool CanExecute()
    1.26 +		{
    1.27 +			return army != null && (NewName != null || NewSize > 0);
    1.28 +		}
    1.29 +
    1.30 +		public override bool Execute()
    1.31 +		{
    1.32 +			if (!army.HasDefaultName())
    1.33 +			{
    1.34 +				oldName = army.Name;
    1.35 +			}
    1.36 +
    1.37 +			oldSize = army.MaxPoints;
    1.38 +			Redo();
    1.39 +			return true;
    1.40 +		}
    1.41 +
    1.42 +		public override void Undo()
    1.43 +		{
    1.44 +			SetName(oldName);
    1.45 +			SetSize(oldSize);
    1.46 +		}
    1.47 +
    1.48 +		public override void Redo()
    1.49 +		{
    1.50 +			SetName(NewName);
    1.51 +			SetSize(NewSize);
    1.52 +		}
    1.53 +
    1.54 +		void SetName (string name)
    1.55 +		{
    1.56 +			if (NewName != null)
    1.57 +			{
    1.58 +				army.Name = name;
    1.59 +			}
    1.60 +		}
    1.61 +
    1.62 +		void SetSize (int size)
    1.63 +		{
    1.64 +			if (NewSize > 0)
    1.65 +			{
    1.66 +				army.MaxPoints = size;
    1.67 +			}
    1.68 +		}
    1.69 +
    1.70 +		public override string Name
    1.71 +		{
    1.72 +			get
    1.73 +			{
    1.74 +				return "Edit army";
    1.75 +			}
    1.76 +		}
    1.77 +
    1.78 +		public override string Description
    1.79 +		{
    1.80 +			get
    1.81 +			{
    1.82 +				return Translation.GetTranslation("editArmyCommandDescription", "edit army name and/or size");
    1.83 +			}
    1.84 +		}
    1.85 +
    1.86 +		public override string UndoDescription
    1.87 +		{
    1.88 +			get
    1.89 +			{
    1.90 +				return Translation.GetTranslation("editArmyCommandDescription", "revert army nnd/or size");
    1.91 +			}
    1.92 +		}
    1.93 +
    1.94 +		public string NewName { get; set; }
    1.95 +
    1.96 +		public int NewSize { get; set; }
    1.97 +	}
    1.98 +}
    1.99 +
     2.1 --- a/IBBoard.WarFoundry.API.csproj	Fri Aug 26 20:04:52 2011 +0100
     2.2 +++ b/IBBoard.WarFoundry.API.csproj	Mon Aug 29 16:47:54 2011 +0100
     2.3 @@ -1,4 +1,4 @@
     2.4 -<?xml version="1.0" encoding="utf-8"?>
     2.5 +<?xml version="1.0" encoding="utf-8"?>
     2.6  <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
     2.7    <PropertyGroup>
     2.8      <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     2.9 @@ -182,6 +182,7 @@
    2.10      <Compile Include="API\Factories\Xml\CategoryLoader.cs" />
    2.11      <Compile Include="API\Factories\IRaceFactory.cs" />
    2.12      <Compile Include="API\Factories\Requirement\IRequirementFactory.cs" />
    2.13 +    <Compile Include="API\Commands\EditArmyCommand.cs" />
    2.14    </ItemGroup>
    2.15    <ItemGroup>
    2.16      <Reference Include="System.Xml" />