Mercurial > repos > IBDev-IBBoard.WarFoundry.API
changeset 215:391446c9b250
Re #223: Use translations within the API
* Translate and cache undo/redo descriptions of commands
* Simplify "set equipment amount" descriptions because of ticket:224
Also:
* Line ending change on ICostedWarFoundryObject
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 22 Nov 2009 20:08:45 +0000 |
parents | 1b718b67f7f6 |
children | 65553d2c8612 |
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 api/Objects/ICostedWarFoundryObject.cs |
diffstat | 7 files changed, 118 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/api/Commands/AbstractReplaceUnitEquipmentCommand.cs Sat Nov 21 21:27:07 2009 +0000 +++ b/api/Commands/AbstractReplaceUnitEquipmentCommand.cs Sun Nov 22 20:08:45 2009 +0000 @@ -16,6 +16,8 @@ { private SetUnitEquipmentNumericAmountCommand removeOldCommand; private AbstractSetUnitEquipmentAmountCommand addNewCommand; + private string description; + private string undoDescription; public AbstractReplaceUnitEquipmentCommand(Unit unit, UnitEquipmentItem oldItem, AbstractSetUnitEquipmentAmountCommand addNewEquipmentCommand) { @@ -31,12 +33,28 @@ public override string Description { - get { return "Replace "+StringManipulation.CutToLength(removeOldCommand.EquipItem.Name, 20)+" with "+StringManipulation.CutToLength(addNewCommand.EquipItem.Name, 20)+ " for "+StringManipulation.CutToLength(removeOldCommand.Unit.Name, 20); } + 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; + } } public override string UndoDescription { - get { return "Replace "+StringManipulation.CutToLength(addNewCommand.EquipItem.Name, 20)+" with "+StringManipulation.CutToLength(removeOldCommand.EquipItem.Name, 20)+ " for "+StringManipulation.CutToLength(removeOldCommand.Unit.Name, 20); } + 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; + } } public override bool Execute() @@ -60,7 +78,10 @@ public override string Name { - get { return "Replace required equipment"; } + get + { + return "Replace required equipment"; + } } } }
--- a/api/Commands/AbstractSetUnitEquipmentAmountCommand.cs Sat Nov 21 21:27:07 2009 +0000 +++ b/api/Commands/AbstractSetUnitEquipmentAmountCommand.cs Sun Nov 22 20:08:45 2009 +0000 @@ -19,8 +19,8 @@ private UnitEquipmentItem equip; private double oldAmount; private bool oldAmountWasRatio; - private string equipName; - private string unitName; + private string description; + private string undoDescription; public AbstractSetUnitEquipmentAmountCommand(Unit unit, UnitEquipmentItem item) { @@ -28,8 +28,6 @@ equip = item; 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() @@ -41,7 +39,12 @@ { get { - return Translation.GetTranslation("setEquipmentAmountCommandDescription", "set {0} amount for {1} to {2}", equipName, unitName, GetNewAmountString()); + if (description == null) + { + description = Translation.GetTranslation("setEquipmentAmountCommandDescription", "set {0} amount for {1} to {2}", equip.Name, unit.Name, GetNewAmountString()); + } + + return description; } } @@ -57,15 +60,9 @@ { get { - string undoDescription; - - if (oldAmount == 0) + if (undoDescription == null) { - 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()); + undoDescription = Translation.GetTranslation("setEquipmentAmountCommandUndoDescription", "set {0} amount for {1} to {2}", equip.Name, unit.Name, GetOldAmountString()); } return undoDescription; @@ -104,8 +101,6 @@ return amountString; } - - public override bool Execute() { this.Redo();
--- a/api/Commands/CreateAndAddUnitCommand.cs Sat Nov 21 21:27:07 2009 +0000 +++ b/api/Commands/CreateAndAddUnitCommand.cs Sun Nov 22 20:08:45 2009 +0000 @@ -14,6 +14,8 @@ private UnitType addedUnitType; private ArmyCategory armyCat; private Unit addedUnit; + private string description; + private string undoDescription; public CreateAndAddUnitCommand(UnitType toAdd, ArmyCategory armyCatTo) { @@ -21,16 +23,6 @@ armyCat = armyCatTo; } - [Obsolete("Use two parameter constructor instead")] - public CreateAndAddUnitCommand(UnitType toAdd, ArmyCategory catTo, Army armyTo) : this(toAdd, catTo) - { - } - - [Obsolete("Use two parameter constructor instead")] - public CreateAndAddUnitCommand(UnitType toAdd, Category catTo, Army armyTo) : this (toAdd, armyTo.GetCategory(catTo), armyTo) - { - } - public override bool CanExecute() { return (addedUnitType!=null && armyCat!=null); @@ -38,12 +30,28 @@ public override string Description { - get { return "Add unit of "+StringManipulation.CutToLength(addedUnitType.Name, 20)+" to the army"; } + get + { + if (description == null) + { + description = Translation.GetTranslation("createAndAddUnitCommandDescription", "add unit of {0} to the army", addedUnitType.Name); + } + + return description; + } } public override string UndoDescription { - get { return "Remove unit of "+StringManipulation.CutToLength(addedUnitType.Name, 20)+" from army"; } + get + { + if (undoDescription == null) + { + undoDescription = Translation.GetTranslation("createAndAddUnitCommandUndoDescription", "remove unit of {0} from army", addedUnitType.Name); + } + + return undoDescription; + } } public override bool Execute()
--- a/api/Commands/RemoveUnitCommand.cs Sat Nov 21 21:27:07 2009 +0000 +++ b/api/Commands/RemoveUnitCommand.cs Sun Nov 22 20:08:45 2009 +0000 @@ -4,6 +4,7 @@ using System; using IBBoard.Commands; +using IBBoard.Lang; using IBBoard.WarFoundry.API.Objects; namespace IBBoard.WarFoundry.API.Commands @@ -15,6 +16,8 @@ { private Unit unit; private ArmyCategory cat; + private string description; + private string undoDescription; public RemoveUnitCommand(Unit toRemove) { @@ -29,12 +32,28 @@ public override string Description { - get { return "Remove an existing unit from the army"; } + get + { + if (description == null) + { + description = Translation.GetTranslation("removeUnitCommandDescription", "remove {0} from the army", unit.Name); + } + + return description; + } } public override string UndoDescription { - get { return "Replace a removed unit"; } + get + { + if (undoDescription == null) + { + undoDescription = Translation.GetTranslation("removeUnitCommandUndoDescription", "re-add {0} to the army", unit.Name); + } + + return undoDescription; + } } public override bool Execute()
--- a/api/Commands/SetNameCommand.cs Sat Nov 21 21:27:07 2009 +0000 +++ b/api/Commands/SetNameCommand.cs Sun Nov 22 20:08:45 2009 +0000 @@ -4,6 +4,7 @@ using System; using IBBoard.Commands; +using IBBoard.Lang; using IBBoard.WarFoundry.API.Objects; namespace IBBoard.WarFoundry.API.Commands @@ -15,6 +16,8 @@ { private WarFoundryObject obj; private string newName, oldName; + private string description; + private string undoDescription; public SetNameCommand(WarFoundryObject toRename, string name) { @@ -30,12 +33,28 @@ public override string Description { - get { return "Rename "+oldName; } + get + { + if (description == null) + { + description = Translation.GetTranslation("setUnitNameCommandDescription", "rename \"{0}\" to \"{1}\"", oldName, newName); + } + + return description; + } } public override string UndoDescription { - get { return "Revert name of "+newName; } + get + { + if (undoDescription == null) + { + undoDescription = Translation.GetTranslation("setUnitNameCommandUndoDescription", "rename \"{0}\" to \"{1}\"", newName, oldName); + } + + return undoDescription; + } } public override bool Execute()
--- a/api/Commands/SetUnitSizeCommand.cs Sat Nov 21 21:27:07 2009 +0000 +++ b/api/Commands/SetUnitSizeCommand.cs Sun Nov 22 20:08:45 2009 +0000 @@ -4,6 +4,7 @@ using System; using IBBoard.Commands; +using IBBoard.Lang; using IBBoard.WarFoundry.API.Objects; namespace IBBoard.WarFoundry.API.Commands @@ -15,6 +16,8 @@ { private Unit unit; private int newSize, oldSize; + private string description; + private string undoDescription; public SetUnitSizeCommand(Unit toResize, int size) { @@ -30,12 +33,28 @@ public override string Description { - get { return "Change size of "+unit.Name; } + get + { + if (description == null) + { + description = Translation.GetTranslation("setUnitSizeCommandDescription", "set size of {0} to {1}", unit.Name, newSize); + } + + return description; + } } public override string UndoDescription { - get { return "Revert size of "+unit.Name; } + get + { + if (undoDescription == null) + { + undoDescription = Translation.GetTranslation("setUnitSizeCommandUndoDescription", "set size of {0} to {1}", unit.Name, oldSize); + } + + return undoDescription; + } } public override bool Execute()
--- a/api/Objects/ICostedWarFoundryObject.cs Sat Nov 21 21:27:07 2009 +0000 +++ b/api/Objects/ICostedWarFoundryObject.cs Sun Nov 22 20:08:45 2009 +0000 @@ -1,4 +1,4 @@ -// This file (ICostedNamedObject.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard. +// This file (ICostedNamedObject.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard. // // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.