changeset 143:7f13ffcb8765 WarFoundry_v0.1beta2_Winforms

Re #164: Show unit cost in army tree * Do prep work and create "ICostedWarFoundryObject" interface that defines objects with a "Points" property * Implement new interface where necessary * Deprecate old variations on "points value" * Remove references to deprecated code
author IBBoard <dev@ibboard.co.uk>
date Sat, 19 Sep 2009 19:42:53 +0000
parents b4d1ed685490
children 721891008b5c
files IBBoard.WarFoundry.API.csproj IBBoard.WarFoundry.API.csproj.user api/Exporters/WarFoundryHtmlExporter.cs api/Objects/Army.cs api/Objects/ArmyCategory.cs api/Objects/ICostedWarFoundryObject.cs api/Objects/Unit.cs
diffstat 7 files changed, 56 insertions(+), 21 deletions(-) [+]
line diff
     1.1 --- a/IBBoard.WarFoundry.API.csproj	Sat Sep 19 14:12:57 2009 +0000
     1.2 +++ b/IBBoard.WarFoundry.API.csproj	Sat Sep 19 19:42:53 2009 +0000
     1.3 @@ -1,4 +1,4 @@
     1.4 -<?xml version="1.0" encoding="utf-8"?>
     1.5 +<?xml version="1.0" encoding="utf-8"?>
     1.6  <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     1.7    <PropertyGroup>
     1.8      <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     1.9 @@ -53,6 +53,7 @@
    1.10        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    1.11      </None>
    1.12      <None Include="COPYING" />
    1.13 +    <Compile Include="api\Objects\ICostedWarFoundryObject.cs" />
    1.14    </ItemGroup>
    1.15    <ItemGroup>
    1.16      <Compile Include="api\Commands\CreateAndAddUnitCommand.cs" />
    1.17 @@ -156,7 +157,4 @@
    1.18        <HintPath>libs\ICSharpCode.SharpZipLib.dll</HintPath>
    1.19      </Reference>
    1.20    </ItemGroup>
    1.21 -  <ItemGroup>
    1.22 -    <Folder Include="api\Exporters\" />
    1.23 -  </ItemGroup>
    1.24  </Project>
    1.25 \ No newline at end of file
     2.1 --- a/IBBoard.WarFoundry.API.csproj.user	Sat Sep 19 14:12:57 2009 +0000
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,5 +0,0 @@
     2.4 -<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     2.5 -  <PropertyGroup>
     2.6 -    <ProjectView>ProjectFiles</ProjectView>
     2.7 -  </PropertyGroup>
     2.8 -</Project>
     2.9 \ No newline at end of file
     3.1 --- a/api/Exporters/WarFoundryHtmlExporter.cs	Sat Sep 19 14:12:57 2009 +0000
     3.2 +++ b/api/Exporters/WarFoundryHtmlExporter.cs	Sat Sep 19 19:42:53 2009 +0000
     3.3 @@ -52,7 +52,7 @@
     3.4  			XmlElement body = doc.CreateElement("body");
     3.5  			html.AppendChild(body);
     3.6  			XmlElement header = doc.CreateElement("h1");
     3.7 -			header.InnerText = Translation.GetTranslation("armyHtmlOutputBodyHeader", "{0} - {1}pts", army.Name, army.PointsTotal);
     3.8 +			header.InnerText = Translation.GetTranslation("armyHtmlOutputBodyHeader", "{0} - {1}pts", army.Name, army.Points);
     3.9  			body.AppendChild(header);
    3.10  			
    3.11  			foreach (XmlElement table in CreateTables(army, doc))
    3.12 @@ -152,7 +152,7 @@
    3.13  			row.AppendChild(notes);
    3.14  			
    3.15  			XmlElement points = doc.CreateElement("td");
    3.16 -			points.InnerText = unit.PointsValue.ToString();
    3.17 +			points.InnerText = unit.Points.ToString();
    3.18  			row.AppendChild(points);
    3.19  			
    3.20  			return row;
     4.1 --- a/api/Objects/Army.cs	Sat Sep 19 14:12:57 2009 +0000
     4.2 +++ b/api/Objects/Army.cs	Sat Sep 19 19:42:53 2009 +0000
     4.3 @@ -17,7 +17,7 @@
     4.4  	/// <summary>
     4.5  	/// Summary description for Army.
     4.6  	/// </summary>
     4.7 -	public class Army : WarFoundryObject
     4.8 +	public class Army : WarFoundryObject, ICostedWarFoundryObject
     4.9  	{
    4.10  		//private GameSystem system;
    4.11  		private Race armyRace;
    4.12 @@ -156,11 +156,17 @@
    4.13  			}
    4.14  		}
    4.15  
    4.16 +		[Obsolete("Use Points instead")]
    4.17  		public double PointsTotal
    4.18  		{
    4.19  			get { return TotalPoints; }
    4.20  		}
    4.21  		
    4.22 +		public double Points
    4.23 +		{
    4.24 +			get { return TotalPoints; }
    4.25 +		}
    4.26 +		
    4.27  		public void AddUnit(Unit unit)
    4.28  		{
    4.29  			ArmyCategory armyCat = GetCategory(unit.UnitType.MainCategory);
    4.30 @@ -214,7 +220,7 @@
    4.31  
    4.32  				foreach (ArmyCategory cat in Categories)
    4.33  				{
    4.34 -					points+= cat.PointsTotal;
    4.35 +					points+= cat.Points;
    4.36  				}
    4.37  
    4.38  				TotalPoints = points;
     5.1 --- a/api/Objects/ArmyCategory.cs	Sat Sep 19 14:12:57 2009 +0000
     5.2 +++ b/api/Objects/ArmyCategory.cs	Sat Sep 19 19:42:53 2009 +0000
     5.3 @@ -11,7 +11,7 @@
     5.4  	/// <summary>
     5.5  	/// Summary description for ArmyCategory.
     5.6  	/// </summary>
     5.7 -	public class ArmyCategory : WarFoundryObject
     5.8 +	public class ArmyCategory : WarFoundryObject, ICostedWarFoundryObject
     5.9  	{
    5.10  		private Category category;
    5.11  		private Army parentArmy;
    5.12 @@ -19,10 +19,10 @@
    5.13  		private List<Unit> units;
    5.14  		private Dictionary<string, int> unitTypes;
    5.15  		private DoubleValChangedDelegate PointsValueChangedMethod;
    5.16 +		public event ObjectAddDelegate UnitAdded;
    5.17 +		public event ObjectRemoveDelegate UnitRemoved;
    5.18 +		public event FailedUnitRequirementDelegate FailedRequirement;
    5.19  		public event DoubleValChangedDelegate PointsValueChanged;
    5.20 -		public event ObjectAddDelegate UnitAdded;
    5.21 -		public event ObjectRemoveDelegate UnitRemoved;
    5.22 -		public event FailedUnitRequirementDelegate FailedRequirement;
    5.23  
    5.24  		public ArmyCategory(Army army, Category cat) : base()
    5.25  		{
    5.26 @@ -74,7 +74,7 @@
    5.27  			int unitTypeCount;
    5.28  			unitTypes.TryGetValue(unit.UnitType.ID, out unitTypeCount);
    5.29  			unitTypes[unit.UnitType.ID] = (int)unitTypeCount + 1;
    5.30 -			TotalPoints+= unit.PointsValue;
    5.31 +			TotalPoints+= unit.Points;
    5.32  			OnUnitAdded(unit, failedReqs);
    5.33  		}
    5.34  
    5.35 @@ -83,7 +83,7 @@
    5.36  			List<FailedUnitRequirement> failedReqs = ParentArmy.CanRemoveUnit(unit);
    5.37  			units.Remove(unit);
    5.38  			unitTypes[unit.UnitType.ID] = ((int)unitTypes[unit.UnitType.ID])-1;
    5.39 -			TotalPoints-= unit.PointsValue;
    5.40 +			TotalPoints-= unit.Points;
    5.41  			unit.PointsValueChanged-= PointsValueChangedMethod;
    5.42  			OnUnitRemoved(unit, failedReqs);
    5.43  		}
    5.44 @@ -113,11 +113,17 @@
    5.45  			}
    5.46  		}
    5.47  
    5.48 +		[Obsolete("Use Points instead")]
    5.49  		public double PointsTotal
    5.50  		{
    5.51  			get { return TotalPoints; }
    5.52  		}
    5.53  
    5.54 +		public double Points
    5.55 +		{
    5.56 +			get { return TotalPoints; }
    5.57 +		}
    5.58 +
    5.59  		private void PointsValueChangedHandler(WarFoundryObject obj, double oldVal, double newVal)
    5.60  		{
    5.61  			if (obj is Unit)
    5.62 @@ -178,7 +184,7 @@
    5.63  				
    5.64  		public int GetPointsPercentage()
    5.65  		{
    5.66 -			return (int)Math.Round((PointsTotal / ParentArmy.MaxPoints) * 100, 0);
    5.67 +			return (int)Math.Round((Points / ParentArmy.MaxPoints) * 100, 0);
    5.68  		}
    5.69  	}
    5.70  }
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/api/Objects/ICostedWarFoundryObject.cs	Sat Sep 19 19:42:53 2009 +0000
     6.3 @@ -0,0 +1,24 @@
     6.4 +// This file (ICostedNamedObject.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard.
     6.5 +//
     6.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.
     6.7 +
     6.8 +using System;
     6.9 +
    6.10 +namespace IBBoard.WarFoundry.API.Objects
    6.11 +{
    6.12 +	/// <summary>
    6.13 +	/// An interface for WarFoundry objects that have a points value (cost)
    6.14 +	/// </summary>
    6.15 +	public interface ICostedWarFoundryObject : IWarFoundryObject
    6.16 +	{
    6.17 +		/// <summary>
    6.18 +		/// A getter for the points value of the costed object
    6.19 +		/// </summary>
    6.20 +		double Points { get; }
    6.21 +		
    6.22 +		/// <summary>
    6.23 +		/// An event that is fired when the points value of the object changes
    6.24 +		/// </summary>
    6.25 +		event DoubleValChangedDelegate PointsValueChanged;
    6.26 +	}
    6.27 +}
     7.1 --- a/api/Objects/Unit.cs	Sat Sep 19 14:12:57 2009 +0000
     7.2 +++ b/api/Objects/Unit.cs	Sat Sep 19 19:42:53 2009 +0000
     7.3 @@ -13,7 +13,7 @@
     7.4  	/// <summary>
     7.5  	/// Summary description for UnitInstance.
     7.6  	/// </summary>
     7.7 -	public class Unit : WarFoundryObject
     7.8 +	public class Unit : WarFoundryObject, ICostedWarFoundryObject
     7.9  	{
    7.10  		private UnitType type;
    7.11  		private int size;
    7.12 @@ -157,8 +157,14 @@
    7.13  			set { cat = value; }
    7.14  		}
    7.15  
    7.16 +		[Obsolete("Use Points instead")]
    7.17  		public double PointsValue
    7.18  		{
    7.19 +			get { return Points; }
    7.20 +		}
    7.21 +		
    7.22 +		public double Points
    7.23 +		{
    7.24  			get 
    7.25  			{
    7.26  				if (points == 0)