Mercurial > repos > snowblizz-super-API-ideas
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 wrap: on
line diff
--- a/IBBoard.WarFoundry.API.csproj Sat Sep 19 14:12:57 2009 +0000 +++ b/IBBoard.WarFoundry.API.csproj Sat Sep 19 19:42:53 2009 +0000 @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> @@ -53,6 +53,7 @@ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Include="COPYING" /> + <Compile Include="api\Objects\ICostedWarFoundryObject.cs" /> </ItemGroup> <ItemGroup> <Compile Include="api\Commands\CreateAndAddUnitCommand.cs" /> @@ -156,7 +157,4 @@ <HintPath>libs\ICSharpCode.SharpZipLib.dll</HintPath> </Reference> </ItemGroup> - <ItemGroup> - <Folder Include="api\Exporters\" /> - </ItemGroup> </Project> \ No newline at end of file
--- a/IBBoard.WarFoundry.API.csproj.user Sat Sep 19 14:12:57 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <PropertyGroup> - <ProjectView>ProjectFiles</ProjectView> - </PropertyGroup> -</Project> \ No newline at end of file
--- a/api/Exporters/WarFoundryHtmlExporter.cs Sat Sep 19 14:12:57 2009 +0000 +++ b/api/Exporters/WarFoundryHtmlExporter.cs Sat Sep 19 19:42:53 2009 +0000 @@ -52,7 +52,7 @@ XmlElement body = doc.CreateElement("body"); html.AppendChild(body); XmlElement header = doc.CreateElement("h1"); - header.InnerText = Translation.GetTranslation("armyHtmlOutputBodyHeader", "{0} - {1}pts", army.Name, army.PointsTotal); + header.InnerText = Translation.GetTranslation("armyHtmlOutputBodyHeader", "{0} - {1}pts", army.Name, army.Points); body.AppendChild(header); foreach (XmlElement table in CreateTables(army, doc)) @@ -152,7 +152,7 @@ row.AppendChild(notes); XmlElement points = doc.CreateElement("td"); - points.InnerText = unit.PointsValue.ToString(); + points.InnerText = unit.Points.ToString(); row.AppendChild(points); return row;
--- a/api/Objects/Army.cs Sat Sep 19 14:12:57 2009 +0000 +++ b/api/Objects/Army.cs Sat Sep 19 19:42:53 2009 +0000 @@ -17,7 +17,7 @@ /// <summary> /// Summary description for Army. /// </summary> - public class Army : WarFoundryObject + public class Army : WarFoundryObject, ICostedWarFoundryObject { //private GameSystem system; private Race armyRace; @@ -156,11 +156,17 @@ } } + [Obsolete("Use Points instead")] public double PointsTotal { get { return TotalPoints; } } + public double Points + { + get { return TotalPoints; } + } + public void AddUnit(Unit unit) { ArmyCategory armyCat = GetCategory(unit.UnitType.MainCategory); @@ -214,7 +220,7 @@ foreach (ArmyCategory cat in Categories) { - points+= cat.PointsTotal; + points+= cat.Points; } TotalPoints = points;
--- a/api/Objects/ArmyCategory.cs Sat Sep 19 14:12:57 2009 +0000 +++ b/api/Objects/ArmyCategory.cs Sat Sep 19 19:42:53 2009 +0000 @@ -11,7 +11,7 @@ /// <summary> /// Summary description for ArmyCategory. /// </summary> - public class ArmyCategory : WarFoundryObject + public class ArmyCategory : WarFoundryObject, ICostedWarFoundryObject { private Category category; private Army parentArmy; @@ -19,10 +19,10 @@ private List<Unit> units; private Dictionary<string, int> unitTypes; private DoubleValChangedDelegate PointsValueChangedMethod; + public event ObjectAddDelegate UnitAdded; + public event ObjectRemoveDelegate UnitRemoved; + public event FailedUnitRequirementDelegate FailedRequirement; public event DoubleValChangedDelegate PointsValueChanged; - public event ObjectAddDelegate UnitAdded; - public event ObjectRemoveDelegate UnitRemoved; - public event FailedUnitRequirementDelegate FailedRequirement; public ArmyCategory(Army army, Category cat) : base() { @@ -74,7 +74,7 @@ int unitTypeCount; unitTypes.TryGetValue(unit.UnitType.ID, out unitTypeCount); unitTypes[unit.UnitType.ID] = (int)unitTypeCount + 1; - TotalPoints+= unit.PointsValue; + TotalPoints+= unit.Points; OnUnitAdded(unit, failedReqs); } @@ -83,7 +83,7 @@ List<FailedUnitRequirement> failedReqs = ParentArmy.CanRemoveUnit(unit); units.Remove(unit); unitTypes[unit.UnitType.ID] = ((int)unitTypes[unit.UnitType.ID])-1; - TotalPoints-= unit.PointsValue; + TotalPoints-= unit.Points; unit.PointsValueChanged-= PointsValueChangedMethod; OnUnitRemoved(unit, failedReqs); } @@ -113,11 +113,17 @@ } } + [Obsolete("Use Points instead")] public double PointsTotal { get { return TotalPoints; } } + public double Points + { + get { return TotalPoints; } + } + private void PointsValueChangedHandler(WarFoundryObject obj, double oldVal, double newVal) { if (obj is Unit) @@ -178,7 +184,7 @@ public int GetPointsPercentage() { - return (int)Math.Round((PointsTotal / ParentArmy.MaxPoints) * 100, 0); + return (int)Math.Round((Points / ParentArmy.MaxPoints) * 100, 0); } } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/api/Objects/ICostedWarFoundryObject.cs Sat Sep 19 19:42:53 2009 +0000 @@ -0,0 +1,24 @@ +// This file (ICostedNamedObject.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 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. + +using System; + +namespace IBBoard.WarFoundry.API.Objects +{ + /// <summary> + /// An interface for WarFoundry objects that have a points value (cost) + /// </summary> + public interface ICostedWarFoundryObject : IWarFoundryObject + { + /// <summary> + /// A getter for the points value of the costed object + /// </summary> + double Points { get; } + + /// <summary> + /// An event that is fired when the points value of the object changes + /// </summary> + event DoubleValChangedDelegate PointsValueChanged; + } +}
--- a/api/Objects/Unit.cs Sat Sep 19 14:12:57 2009 +0000 +++ b/api/Objects/Unit.cs Sat Sep 19 19:42:53 2009 +0000 @@ -13,7 +13,7 @@ /// <summary> /// Summary description for UnitInstance. /// </summary> - public class Unit : WarFoundryObject + public class Unit : WarFoundryObject, ICostedWarFoundryObject { private UnitType type; private int size; @@ -157,8 +157,14 @@ set { cat = value; } } + [Obsolete("Use Points instead")] public double PointsValue { + get { return Points; } + } + + public double Points + { get { if (points == 0)