Mercurial > repos > IBDev-IBBoard.WarFoundry.API
changeset 289:650bbe79b884 WarFoundry_v0.1
Fixes #336: Command descriptions don't refresh on language change
* Remove cached string values and just return the text each time
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 02 Jan 2011 21:01:20 +0000 |
parents | 5c4b3d91795f |
children | |
files | api/Commands/AbstractReplaceUnitEquipmentCommand.cs api/Commands/AbstractSetUnitEquipmentAmountCommand.cs api/Commands/CreateAndAddUnitCommand.cs api/Commands/RemoveUnitCommand.cs api/Commands/SetNameCommand.cs api/Commands/SetUnitSizeCommand.cs |
diffstat | 6 files changed, 26 insertions(+), 100 deletions(-) [+] |
line wrap: on
line diff
--- a/api/Commands/AbstractReplaceUnitEquipmentCommand.cs Sun Jan 02 16:04:49 2011 +0000 +++ b/api/Commands/AbstractReplaceUnitEquipmentCommand.cs Sun Jan 02 21:01:20 2011 +0000 @@ -16,9 +16,7 @@ { private SetUnitEquipmentNumericAmountCommand removeOldCommand; private AbstractSetUnitEquipmentAmountCommand addNewCommand; - private string description; - private string undoDescription; - + public AbstractReplaceUnitEquipmentCommand(Unit unit, UnitEquipmentItem oldItem, AbstractSetUnitEquipmentAmountCommand addNewEquipmentCommand) { //We can get away with a numeric amount here even if it is a ratio item because we're setting it to 0 @@ -35,12 +33,7 @@ { get { - if (description == null) - { - description = Translation.GetTranslation("replaceUnitEquipmentCommandDescription", "replace {0} with {1} for {2}", removeOldCommand.EquipItem.Name, addNewCommand.EquipItem.Name, removeOldCommand.Unit.Name); - } - - return description; + return Translation.GetTranslation("replaceUnitEquipmentCommandDescription", "replace {0} with {1} for {2}", removeOldCommand.EquipItem.Name, addNewCommand.EquipItem.Name, removeOldCommand.Unit.Name); } } @@ -48,12 +41,7 @@ { get { - if (undoDescription == null) - { - undoDescription = Translation.GetTranslation("replaceUnitEquipmentCommandUndoDescription", "replace {0} with {1} for {2}", addNewCommand.EquipItem.Name, removeOldCommand.EquipItem.Name, removeOldCommand.Unit.Name); - } - - return undoDescription; + return Translation.GetTranslation("replaceUnitEquipmentCommandUndoDescription", "replace {0} with {1} for {2}", addNewCommand.EquipItem.Name, removeOldCommand.EquipItem.Name, removeOldCommand.Unit.Name); } } @@ -75,7 +63,6 @@ removeOldCommand.Undo(); } - public override string Name { get
--- a/api/Commands/AbstractSetUnitEquipmentAmountCommand.cs Sun Jan 02 16:04:49 2011 +0000 +++ b/api/Commands/AbstractSetUnitEquipmentAmountCommand.cs Sun Jan 02 21:01:20 2011 +0000 @@ -19,9 +19,7 @@ private UnitEquipmentItem equip; private double oldAmount; private bool oldAmountWasRatio; - private string description; - private string undoDescription; - + public AbstractSetUnitEquipmentAmountCommand(Unit unit, UnitEquipmentItem item) { this.unit = unit; @@ -32,19 +30,14 @@ public override bool CanExecute() { - return (unit!=null && equip!=null); + return (unit != null && equip != null); } public override string Description { get { - if (description == null) - { - description = Translation.GetTranslation("setEquipmentAmountCommandDescription", "set {0} amount for {1} to {2}", equip.Name, unit.Name, GetNewAmountString()); - } - - return description; + return Translation.GetTranslation("setEquipmentAmountCommandDescription", "set {0} amount for {1} to {2}", equip.Name, unit.Name, GetNewAmountString()); } } @@ -60,12 +53,7 @@ { get { - if (undoDescription == null) - { - undoDescription = Translation.GetTranslation("setEquipmentAmountCommandUndoDescription", "set {0} amount for {1} to {2}", equip.Name, unit.Name, GetOldAmountString()); - } - - return undoDescription; + return Translation.GetTranslation("setEquipmentAmountCommandUndoDescription", "set {0} amount for {1} to {2}", equip.Name, unit.Name, GetOldAmountString()); } } @@ -79,23 +67,23 @@ { return oldAmountWasRatio ? GetRatioAmountString(oldAmount, UnitEquipmentRatioSelection.CalculateNumberTaken(Unit, EquipItem, oldAmount)) : GetNumberAmountString((int)oldAmount); } - + protected string GetNumberAmountString(int number) { - return Translation.GetTranslation ("equipmentAmountNumber", "{0}", number); + return Translation.GetTranslation("equipmentAmountNumber", "{0}", number); } - protected string GetRatioAmountString (double amount, int number) + protected string GetRatioAmountString(double amount, int number) { string amountString; if (amount == 100) { - amountString = Translation.GetTranslation ("equipmentAmountAll", "all ({1})", amount, number); + amountString = Translation.GetTranslation("equipmentAmountAll", "all ({1})", amount, number); } else { - amountString = Translation.GetTranslation ("equipmentAmountPercentage", "{0}% ({1})", amount, number); + amountString = Translation.GetTranslation("equipmentAmountPercentage", "{0}% ({1})", amount, number); } return amountString; @@ -107,7 +95,7 @@ return true; } - public override void Undo () + public override void Undo() { if (oldAmountWasRatio) { @@ -119,7 +107,6 @@ } } - public UnitEquipmentItem EquipItem { get { return equip; }
--- a/api/Commands/CreateAndAddUnitCommand.cs Sun Jan 02 16:04:49 2011 +0000 +++ b/api/Commands/CreateAndAddUnitCommand.cs Sun Jan 02 21:01:20 2011 +0000 @@ -14,9 +14,7 @@ private UnitType addedUnitType; private ArmyCategory armyCat; private Unit addedUnit; - private string description; - private string undoDescription; - + public CreateAndAddUnitCommand(UnitType toAdd, ArmyCategory armyCatTo) { addedUnitType = toAdd; @@ -25,19 +23,14 @@ public override bool CanExecute() { - return (addedUnitType!=null && armyCat!=null); + return (addedUnitType != null && armyCat != null); } public override string Description { get { - if (description == null) - { - description = Translation.GetTranslation("createAndAddUnitCommandDescription", "add unit of {0} to the army", addedUnitType.Name); - } - - return description; + return Translation.GetTranslation("createAndAddUnitCommandDescription", "add unit of {0} to the army", addedUnitType.Name); } } @@ -45,12 +38,7 @@ { get { - if (undoDescription == null) - { - undoDescription = Translation.GetTranslation("createAndAddUnitCommandUndoDescription", "remove unit of {0} from army", addedUnitType.Name); - } - - return undoDescription; + return Translation.GetTranslation("createAndAddUnitCommandUndoDescription", "remove unit of {0} from army", addedUnitType.Name); } }
--- a/api/Commands/RemoveUnitCommand.cs Sun Jan 02 16:04:49 2011 +0000 +++ b/api/Commands/RemoveUnitCommand.cs Sun Jan 02 21:01:20 2011 +0000 @@ -16,8 +16,6 @@ { private Unit unit; private ArmyCategory cat; - private string description; - private string undoDescription; public RemoveUnitCommand(Unit toRemove) { @@ -27,19 +25,14 @@ public override bool CanExecute() { - return (unit!=null); + return (unit != null); } public override string Description { get { - if (description == null) - { - description = Translation.GetTranslation("removeUnitCommandDescription", "remove {0} from the army", unit.Name); - } - - return description; + return Translation.GetTranslation("removeUnitCommandDescription", "remove {0} from the army", unit.Name); } } @@ -47,12 +40,7 @@ { get { - if (undoDescription == null) - { - undoDescription = Translation.GetTranslation("removeUnitCommandUndoDescription", "re-add {0} to the army", unit.Name); - } - - return undoDescription; + return Translation.GetTranslation("removeUnitCommandUndoDescription", "re-add {0} to the army", unit.Name); } }
--- a/api/Commands/SetNameCommand.cs Sun Jan 02 16:04:49 2011 +0000 +++ b/api/Commands/SetNameCommand.cs Sun Jan 02 21:01:20 2011 +0000 @@ -16,8 +16,6 @@ { private WarFoundryObject obj; private string newName, oldName; - private string description; - private string undoDescription; public SetNameCommand(WarFoundryObject toRename, string name) { @@ -28,19 +26,14 @@ public override bool CanExecute() { - return (obj!=null && newName!=null && newName!=""); + return (obj != null && newName != null && newName != ""); } public override string Description { get { - if (description == null) - { - description = Translation.GetTranslation("setUnitNameCommandDescription", "rename \"{0}\" to \"{1}\"", oldName, newName); - } - - return description; + return Translation.GetTranslation("setUnitNameCommandDescription", "rename \"{0}\" to \"{1}\"", oldName, newName); } } @@ -48,12 +41,7 @@ { get { - if (undoDescription == null) - { - undoDescription = Translation.GetTranslation("setUnitNameCommandUndoDescription", "rename \"{0}\" to \"{1}\"", newName, oldName); - } - - return undoDescription; + return Translation.GetTranslation("setUnitNameCommandUndoDescription", "rename \"{0}\" to \"{1}\"", newName, oldName); } }
--- a/api/Commands/SetUnitSizeCommand.cs Sun Jan 02 16:04:49 2011 +0000 +++ b/api/Commands/SetUnitSizeCommand.cs Sun Jan 02 21:01:20 2011 +0000 @@ -16,8 +16,6 @@ { private Unit unit; private int newSize, oldSize; - private string description; - private string undoDescription; public SetUnitSizeCommand(Unit toResize, int size) { @@ -28,19 +26,14 @@ public override bool CanExecute() { - return (unit!=null && newSize >0 && oldSize > 0); + return (unit != null && newSize > 0 && oldSize > 0); } public override string Description { get { - if (description == null) - { - description = Translation.GetTranslation("setUnitSizeCommandDescription", "set size of {0} to {1}", unit.Name, newSize); - } - - return description; + return Translation.GetTranslation("setUnitSizeCommandDescription", "set size of {0} to {1}", unit.Name, newSize); } } @@ -48,12 +41,7 @@ { get { - if (undoDescription == null) - { - undoDescription = Translation.GetTranslation("setUnitSizeCommandUndoDescription", "set size of {0} to {1}", unit.Name, oldSize); - } - - return undoDescription; + return Translation.GetTranslation("setUnitSizeCommandUndoDescription", "set size of {0} to {1}", unit.Name, oldSize); } }