Mercurial > repos > IBBoard.WarFoundry.API
diff api/Commands/AbstractSetUnitEquipmentAmountCommand.cs @ 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 | 2f3cafb69799 |
children | 391446c9b250 |
line wrap: on
line diff
--- 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()