changeset 423:314b8b8bf4f1

* Give Army objects a sensible default name, as we've been doing in UI * Make name generation method static so that UI can use it * Fire name change event when we change points with default name in case points were used in name
author IBBoard <dev@ibboard.co.uk>
date Wed, 12 Oct 2011 20:39:28 +0100
parents 87f4710b7f8c
children d992758b0150
files API/Objects/Army.cs
diffstat 1 files changed, 16 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Army.cs	Wed Oct 12 20:08:58 2011 +0100
     1.2 +++ b/API/Objects/Army.cs	Wed Oct 12 20:39:28 2011 +0100
     1.3 @@ -11,6 +11,7 @@
     1.4  using IBBoard.WarFoundry.API.Factories;
     1.5  using ICSharpCode.SharpZipLib.Zip;
     1.6  using IBBoard.WarFoundry.API.Objects.Requirement;
     1.7 +using IBBoard.Lang;
     1.8  
     1.9  namespace IBBoard.WarFoundry.API.Objects
    1.10  {
    1.11 @@ -19,6 +20,11 @@
    1.12  	/// </summary>
    1.13  	public class Army : WarFoundryLoadedObject, ICostedWarFoundryObject
    1.14  	{
    1.15 +		public static string GenerateDefaultName(Race race, int points, string ptsAbbrev)
    1.16 +		{
    1.17 +			return String.Format(race.ArmyDefaultName, Translation.GetTranslation("armySizePts", "{0}{1}", points, ptsAbbrev));
    1.18 +		}
    1.19 +
    1.20  		//private GameSystem system;
    1.21  		private Race armyRace;
    1.22  		private int maxPoints;
    1.23 @@ -42,6 +48,11 @@
    1.24  			maxPoints = maxArmyPoints;
    1.25  			PointsValueChangedMethod = new DoubleValChangedDelegate(PointsValueChangedHandler);
    1.26  		}
    1.27 +
    1.28 +		protected override string DefaultName()
    1.29 +		{
    1.30 +			return Army.GenerateDefaultName(Race, MaxPoints, GameSystem.GetPointsAbbrev(MaxPoints));
    1.31 +		}
    1.32  		
    1.33  		public ArmyCategory GetCategory(Category cat)
    1.34  		{
    1.35 @@ -191,6 +202,11 @@
    1.36  					{
    1.37  						MaxPointsValueChanged(this, oldPoints, maxPoints);
    1.38  					}
    1.39 +
    1.40 +					if (HasDefaultName())
    1.41 +					{
    1.42 +						OnNameChanged("", Name);
    1.43 +					}
    1.44  				}
    1.45  			}
    1.46  		}