changeset 214:1b718b67f7f6

Re #179: Make sure that translations are used throughout UI * Fix locations in the API that are used in the front-end
author IBBoard <dev@ibboard.co.uk>
date Sat, 21 Nov 2009 21:27:07 +0000
parents c6713a1b4c0d
children 391446c9b250
files AssemblyInfo.cs api/Commands/AbstractSetUnitEquipmentAmountCommand.cs api/Commands/SetUnitEquipmentNumericAmountCommand.cs api/Commands/SetUnitEquipmentRatioAmountCommand.cs api/Exporters/WarFoundryHtmlExporter.cs api/Factories/Xml/WarFoundryXmlSaver.cs api/Objects/Unit.cs api/Objects/UnitEquipmentRatioSelection.cs
diffstat 8 files changed, 87 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/AssemblyInfo.cs	Sat Nov 21 20:06:36 2009 +0000
+++ b/AssemblyInfo.cs	Sat Nov 21 21:27:07 2009 +0000
@@ -15,7 +15,7 @@
 [assembly: AssemblyConfiguration("")]
 [assembly: AssemblyCompany("")]
 [assembly: AssemblyProduct("IBBoard.WarFoundry.API")]
-[assembly: AssemblyCopyright("IBBoard 2009")]
+[assembly: AssemblyCopyright("IBBoard 2007, 2008, 2009")]
 [assembly: AssemblyTrademark("")]
 [assembly: AssemblyCulture("")]
 
--- a/api/Commands/AbstractSetUnitEquipmentAmountCommand.cs	Sat Nov 21 20:06:36 2009 +0000
+++ b/api/Commands/AbstractSetUnitEquipmentAmountCommand.cs	Sat Nov 21 21:27:07 2009 +0000
@@ -5,7 +5,8 @@
 using System;
 using IBBoard.Commands;
 using IBBoard.Lang;
-using IBBoard.WarFoundry.API.Objects;
+using IBBoard.WarFoundry.API.Objects;
+using IBBoard.WarFoundry.API.Util;
 
 namespace IBBoard.WarFoundry.API.Commands
 {
@@ -18,13 +19,17 @@
 		private UnitEquipmentItem equip;
 		private double oldAmount;
 		private bool oldAmountWasRatio;
+		private string equipName;
+		private string unitName;
 		
 		public AbstractSetUnitEquipmentAmountCommand(Unit unit, UnitEquipmentItem item)
 		{
 			this.unit = unit;
 			equip = item;
-			oldAmount = unit.GetEquipmentAmount(equip);
-			oldAmountWasRatio = unit.GetEquipmentAmountIsRatio(equip);
+			oldAmount = UnitEquipmentUtil.GetEquipmentAmount(unit, equip);
+			oldAmountWasRatio = UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, equip);
+			equipName = StringManipulation.CutToLength(equip.Name, 20);
+			unitName = StringManipulation.CutToLength(unit.Name, 20);
 		}
 
 		public override bool CanExecute()
@@ -36,7 +41,7 @@
 		{
 			get
 			{
-				return "Set " + StringManipulation.CutToLength(equip.Name, 20) + " ratio for " + StringManipulation.CutToLength(unit.Name, 20) + " to " + GetNewAmountString();
+				return Translation.GetTranslation("setEquipmentAmountCommandDescription", "set {0} amount for {1} to {2}", equipName, unitName, GetNewAmountString());
 			}
 		}
 
@@ -50,8 +55,20 @@
 
 		public override string UndoDescription
 		{
-			get {
-				return "Set " + StringManipulation.CutToLength(equip.Name, 20) + " ratio for " + StringManipulation.CutToLength(unit.Name, 20) + " to " + GetOldAmountString();
+			get
+			{
+				string undoDescription;
+				
+				if (oldAmount == 0)
+				{
+					undoDescription = Translation.GetTranslation("setEquipmentAmountCommandRemoveDescription", "remove {0} from {1}", equipName, unitName);
+				}
+				else
+				{
+					undoDescription = Translation.GetTranslation("setEquipmentAmountCommandUndoDescription", "set {0} amount for {1} to {2}", equipName, unitName, GetOldAmountString());
+				}
+				
+				return undoDescription;
 			}
 		}
 
@@ -63,18 +80,30 @@
 		/// </returns>
 		protected string GetOldAmountString()
 		{
-			string oldAmountString;
-			if (oldAmountWasRatio)
+			return oldAmountWasRatio ? GetRatioAmountString(oldAmount, UnitEquipmentRatioSelection.CalculateNumberTaken(Unit, EquipItem, oldAmount)) : GetNumberAmountString((int)oldAmount);
+		}
+		
+		protected string GetNumberAmountString(int number)
+		{
+			return Translation.GetTranslation ("equipmentAmountNumber", "{0}", number);
+		}
+
+		protected string GetRatioAmountString (double amount, int number)
+		{
+			string amountString;
+			
+			if (amount == 100)
 			{
-				oldAmountString = UnitEquipmentRatioSelection.GetEquipmentAmountString(oldAmount);
+				amountString = Translation.GetTranslation ("equipmentAmountAll", "all ({1})", amount, number);
 			}
 			else
 			{
-				oldAmountString = UnitEquipmentNumericSelection.GetEquipmentAmountString(oldAmount);
+				amountString = Translation.GetTranslation ("equipmentAmountPercentage", "{0}% ({1})", amount, number);
 			}
+			
+			return amountString;
+		}
 
-			return oldAmountString;
-		}
 
 
 		public override bool Execute()
--- a/api/Commands/SetUnitEquipmentNumericAmountCommand.cs	Sat Nov 21 20:06:36 2009 +0000
+++ b/api/Commands/SetUnitEquipmentNumericAmountCommand.cs	Sat Nov 21 21:27:07 2009 +0000
@@ -23,7 +23,7 @@
 
 		protected override string GetNewAmountString ()
 		{
-			return UnitEquipmentNumericSelection.GetEquipmentAmountString(newAmount);
+			return GetNumberAmountString(newAmount);
 		}
 		
 		public override void Redo()
--- a/api/Commands/SetUnitEquipmentRatioAmountCommand.cs	Sat Nov 21 20:06:36 2009 +0000
+++ b/api/Commands/SetUnitEquipmentRatioAmountCommand.cs	Sat Nov 21 21:27:07 2009 +0000
@@ -23,7 +23,7 @@
 
 		protected override string GetNewAmountString ()
 		{
-			return UnitEquipmentRatioSelection.GetEquipmentAmountString(newAmount);
+			return GetRatioAmountString(newAmount, UnitEquipmentRatioSelection.CalculateNumberTaken(Unit, EquipItem, newAmount));
 		}
 
 		public override void Redo()
--- a/api/Exporters/WarFoundryHtmlExporter.cs	Sat Nov 21 20:06:36 2009 +0000
+++ b/api/Exporters/WarFoundryHtmlExporter.cs	Sat Nov 21 21:27:07 2009 +0000
@@ -10,7 +10,8 @@
 using System.Xml.Schema;
 using IBBoard.Lang;
 using IBBoard.Xml;
-using IBBoard.WarFoundry.API.Objects;
+using IBBoard.WarFoundry.API.Objects;
+using IBBoard.WarFoundry.API.Util;
 
 namespace IBBoard.WarFoundry.API.Exporters
 {
@@ -158,9 +159,30 @@
 					else
 					{
 						sb.Append(", ");
-					}
-	
-					sb.Append(Translation.GetTranslation("armyHtmlExportEquipAmountRatio", "{0} for {1}", equip.Name, unit.GetEquipmentAmountString(equip)));
+					}
+
+					string amountString;
+					double amount = UnitEquipmentUtil.GetEquipmentAmount(unit, equip);
+
+					if (UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, equip))
+					{
+						int number = UnitEquipmentUtil.GetEquipmentAmountTaken(unit, equip);
+
+						if (amount == 100)
+						{
+							amountString = Translation.GetTranslation("armyHtmlExportEquipAmountAll", "all ({1})", amount, number);
+						}
+						else
+						{
+							amountString = Translation.GetTranslation("armyHtmlExportEquipAmountPercentage", "{0}% ({1})", amount, number);
+						}
+					}
+					else
+					{
+						amountString = amount.ToString();
+					}
+
+					sb.Append(Translation.GetTranslation("armyHtmlExportEquipAmountRatio", "{0} for {1}", equip.Name, amountString));
 				}
 				
 				sb.Append(". ");
--- a/api/Factories/Xml/WarFoundryXmlSaver.cs	Sat Nov 21 20:06:36 2009 +0000
+++ b/api/Factories/Xml/WarFoundryXmlSaver.cs	Sat Nov 21 21:27:07 2009 +0000
@@ -10,8 +10,9 @@
 using IBBoard.Lang;
 using IBBoard.Xml;
 using IBBoard.WarFoundry.API.Factories.Xml.Zip;
-using IBBoard.WarFoundry.API.Objects;
-using IBBoard.WarFoundry.API.Savers;
+using IBBoard.WarFoundry.API.Objects;
+using IBBoard.WarFoundry.API.Savers;
+using IBBoard.WarFoundry.API.Util;
 using ICSharpCode.SharpZipLib.Zip;
 
 namespace IBBoard.WarFoundry.API.Factories.Xml
@@ -146,8 +147,8 @@
 		{
 			XmlElement equipmentItemElem = doc.CreateElement("equipItem");
 			equipmentItemElem.SetAttribute("id", item.ID);
-			equipmentItemElem.SetAttribute("amount", unit.GetEquipmentAmount(item).ToString());
-			equipmentItemElem.SetAttribute("amountType", unit.GetEquipmentAmountIsRatio(item) ? "ratio" : "fixed");
+			equipmentItemElem.SetAttribute("amount", UnitEquipmentUtil.GetEquipmentAmount(unit, item).ToString());
+			equipmentItemElem.SetAttribute("amountType", UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, item) ? "ratio" : "fixed");
 			return equipmentItemElem;
 		}
 		
--- a/api/Objects/Unit.cs	Sat Nov 21 20:06:36 2009 +0000
+++ b/api/Objects/Unit.cs	Sat Nov 21 21:27:07 2009 +0000
@@ -407,8 +407,8 @@
 		}
 		
 		private void RemoveEquipmentItem(UnitEquipmentItem equip)
-		{
-			double oldAmount = GetEquipmentAmount(equip);
+		{
+			double oldAmount = UnitEquipmentUtil.GetEquipmentAmount(this, equip);
 		
 			if (oldAmount != 0)
 			{
--- a/api/Objects/UnitEquipmentRatioSelection.cs	Sat Nov 21 20:06:36 2009 +0000
+++ b/api/Objects/UnitEquipmentRatioSelection.cs	Sat Nov 21 21:27:07 2009 +0000
@@ -27,12 +27,17 @@
 		{
 			get
 			{
-				double exactNumberTaken = (AmountTaken / 100) * EquipmentForUnit.Size;
-				int wholeNumberTaken = (int) IBBMath.Round(exactNumberTaken, EquipmentItem.RoundNumberUp);
-				int maxTaken = UnitEquipmentUtil.GetMaxEquipmentCount(EquipmentForUnit, EquipmentItem);
-				int minTaken = UnitEquipmentUtil.GetMinEquipmentCount(EquipmentForUnit, EquipmentItem);
-				return Math.Min(Math.Max(wholeNumberTaken, minTaken), maxTaken);
+				return CalculateNumberTaken (EquipmentForUnit, EquipmentItem, AmountTaken);
 			}
+		}
+
+		internal static int CalculateNumberTaken (Unit unit, UnitEquipmentItem item, double ratioTaken)
+		{
+			double exactNumberTaken = (ratioTaken / 100) * unit.Size;
+			int wholeNumberTaken = (int)IBBMath.Round (exactNumberTaken, item.RoundNumberUp);
+			int maxTaken = UnitEquipmentUtil.GetMaxEquipmentCount (unit, item);
+			int minTaken = UnitEquipmentUtil.GetMinEquipmentCount (unit, item);
+			return Math.Min (Math.Max (wholeNumberTaken, minTaken), maxTaken);
 		}
 
 		[Obsolete("Implementation is down to the UI")]