# HG changeset patch # User IBBoard # Date 1253389373 0 # Node ID 7f13ffcb876583f948d4c41efa5158f14b301eeb # Parent b4d1ed68549042f942769eeed3f2240a1b0c7e9f 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 diff -r b4d1ed685490 -r 7f13ffcb8765 IBBoard.WarFoundry.API.csproj --- 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 @@ - + Debug @@ -53,6 +53,7 @@ PreserveNewest + @@ -156,7 +157,4 @@ libs\ICSharpCode.SharpZipLib.dll - - - \ No newline at end of file diff -r b4d1ed685490 -r 7f13ffcb8765 IBBoard.WarFoundry.API.csproj.user --- 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 @@ - - - ProjectFiles - - \ No newline at end of file diff -r b4d1ed685490 -r 7f13ffcb8765 api/Exporters/WarFoundryHtmlExporter.cs --- 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; diff -r b4d1ed685490 -r 7f13ffcb8765 api/Objects/Army.cs --- 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 description for Army. /// - 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; diff -r b4d1ed685490 -r 7f13ffcb8765 api/Objects/ArmyCategory.cs --- 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 description for ArmyCategory. /// - public class ArmyCategory : WarFoundryObject + public class ArmyCategory : WarFoundryObject, ICostedWarFoundryObject { private Category category; private Army parentArmy; @@ -19,10 +19,10 @@ private List units; private Dictionary 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 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); } } } diff -r b4d1ed685490 -r 7f13ffcb8765 api/Objects/ICostedWarFoundryObject.cs --- /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 +{ + /// + /// An interface for WarFoundry objects that have a points value (cost) + /// + public interface ICostedWarFoundryObject : IWarFoundryObject + { + /// + /// A getter for the points value of the costed object + /// + double Points { get; } + + /// + /// An event that is fired when the points value of the object changes + /// + event DoubleValChangedDelegate PointsValueChanged; + } +} diff -r b4d1ed685490 -r 7f13ffcb8765 api/Objects/Unit.cs --- 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 description for UnitInstance. /// - 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)