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 wrap: on
line diff
--- a/API/Objects/Army.cs	Wed Oct 12 20:08:58 2011 +0100
+++ b/API/Objects/Army.cs	Wed Oct 12 20:39:28 2011 +0100
@@ -11,6 +11,7 @@
 using IBBoard.WarFoundry.API.Factories;
 using ICSharpCode.SharpZipLib.Zip;
 using IBBoard.WarFoundry.API.Objects.Requirement;
+using IBBoard.Lang;
 
 namespace IBBoard.WarFoundry.API.Objects
 {
@@ -19,6 +20,11 @@
 	/// </summary>
 	public class Army : WarFoundryLoadedObject, ICostedWarFoundryObject
 	{
+		public static string GenerateDefaultName(Race race, int points, string ptsAbbrev)
+		{
+			return String.Format(race.ArmyDefaultName, Translation.GetTranslation("armySizePts", "{0}{1}", points, ptsAbbrev));
+		}
+
 		//private GameSystem system;
 		private Race armyRace;
 		private int maxPoints;
@@ -42,6 +48,11 @@
 			maxPoints = maxArmyPoints;
 			PointsValueChangedMethod = new DoubleValChangedDelegate(PointsValueChangedHandler);
 		}
+
+		protected override string DefaultName()
+		{
+			return Army.GenerateDefaultName(Race, MaxPoints, GameSystem.GetPointsAbbrev(MaxPoints));
+		}
 		
 		public ArmyCategory GetCategory(Category cat)
 		{
@@ -191,6 +202,11 @@
 					{
 						MaxPointsValueChanged(this, oldPoints, maxPoints);
 					}
+
+					if (HasDefaultName())
+					{
+						OnNameChanged("", Name);
+					}
 				}
 			}
 		}