comparison 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
comparison
equal deleted inserted replaced
213:c6713a1b4c0d 214:1b718b67f7f6
4 4
5 using System; 5 using System;
6 using IBBoard.Commands; 6 using IBBoard.Commands;
7 using IBBoard.Lang; 7 using IBBoard.Lang;
8 using IBBoard.WarFoundry.API.Objects; 8 using IBBoard.WarFoundry.API.Objects;
9 using IBBoard.WarFoundry.API.Util;
9 10
10 namespace IBBoard.WarFoundry.API.Commands 11 namespace IBBoard.WarFoundry.API.Commands
11 { 12 {
12 /// <summary> 13 /// <summary>
13 /// Abstract parent class for commands that set the amount of an equipment item a unit has to a fixed numeric or ratio value 14 /// Abstract parent class for commands that set the amount of an equipment item a unit has to a fixed numeric or ratio value
16 { 17 {
17 private Unit unit; 18 private Unit unit;
18 private UnitEquipmentItem equip; 19 private UnitEquipmentItem equip;
19 private double oldAmount; 20 private double oldAmount;
20 private bool oldAmountWasRatio; 21 private bool oldAmountWasRatio;
22 private string equipName;
23 private string unitName;
21 24
22 public AbstractSetUnitEquipmentAmountCommand(Unit unit, UnitEquipmentItem item) 25 public AbstractSetUnitEquipmentAmountCommand(Unit unit, UnitEquipmentItem item)
23 { 26 {
24 this.unit = unit; 27 this.unit = unit;
25 equip = item; 28 equip = item;
26 oldAmount = unit.GetEquipmentAmount(equip); 29 oldAmount = UnitEquipmentUtil.GetEquipmentAmount(unit, equip);
27 oldAmountWasRatio = unit.GetEquipmentAmountIsRatio(equip); 30 oldAmountWasRatio = UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, equip);
31 equipName = StringManipulation.CutToLength(equip.Name, 20);
32 unitName = StringManipulation.CutToLength(unit.Name, 20);
28 } 33 }
29 34
30 public override bool CanExecute() 35 public override bool CanExecute()
31 { 36 {
32 return (unit!=null && equip!=null); 37 return (unit!=null && equip!=null);
34 39
35 public override string Description 40 public override string Description
36 { 41 {
37 get 42 get
38 { 43 {
39 return "Set " + StringManipulation.CutToLength(equip.Name, 20) + " ratio for " + StringManipulation.CutToLength(unit.Name, 20) + " to " + GetNewAmountString(); 44 return Translation.GetTranslation("setEquipmentAmountCommandDescription", "set {0} amount for {1} to {2}", equipName, unitName, GetNewAmountString());
40 } 45 }
41 } 46 }
42 47
43 /// <summary> 48 /// <summary>
44 /// Gets the string representation for the new amount of the equipment item to take 49 /// Gets the string representation for the new amount of the equipment item to take
48 /// </returns> 53 /// </returns>
49 protected abstract string GetNewAmountString(); 54 protected abstract string GetNewAmountString();
50 55
51 public override string UndoDescription 56 public override string UndoDescription
52 { 57 {
53 get { 58 get
54 return "Set " + StringManipulation.CutToLength(equip.Name, 20) + " ratio for " + StringManipulation.CutToLength(unit.Name, 20) + " to " + GetOldAmountString(); 59 {
60 string undoDescription;
61
62 if (oldAmount == 0)
63 {
64 undoDescription = Translation.GetTranslation("setEquipmentAmountCommandRemoveDescription", "remove {0} from {1}", equipName, unitName);
65 }
66 else
67 {
68 undoDescription = Translation.GetTranslation("setEquipmentAmountCommandUndoDescription", "set {0} amount for {1} to {2}", equipName, unitName, GetOldAmountString());
69 }
70
71 return undoDescription;
55 } 72 }
56 } 73 }
57 74
58 /// <summary> 75 /// <summary>
59 /// Gets the string representation for the old amount of the equipment item to take 76 /// Gets the string representation for the old amount of the equipment item to take
61 /// <returns> 78 /// <returns>
62 /// the string representation for the old amount of the equipment item to take 79 /// the string representation for the old amount of the equipment item to take
63 /// </returns> 80 /// </returns>
64 protected string GetOldAmountString() 81 protected string GetOldAmountString()
65 { 82 {
66 string oldAmountString; 83 return oldAmountWasRatio ? GetRatioAmountString(oldAmount, UnitEquipmentRatioSelection.CalculateNumberTaken(Unit, EquipItem, oldAmount)) : GetNumberAmountString((int)oldAmount);
67 if (oldAmountWasRatio) 84 }
85
86 protected string GetNumberAmountString(int number)
87 {
88 return Translation.GetTranslation ("equipmentAmountNumber", "{0}", number);
89 }
90
91 protected string GetRatioAmountString (double amount, int number)
92 {
93 string amountString;
94
95 if (amount == 100)
68 { 96 {
69 oldAmountString = UnitEquipmentRatioSelection.GetEquipmentAmountString(oldAmount); 97 amountString = Translation.GetTranslation ("equipmentAmountAll", "all ({1})", amount, number);
70 } 98 }
71 else 99 else
72 { 100 {
73 oldAmountString = UnitEquipmentNumericSelection.GetEquipmentAmountString(oldAmount); 101 amountString = Translation.GetTranslation ("equipmentAmountPercentage", "{0}% ({1})", amount, number);
74 } 102 }
103
104 return amountString;
105 }
75 106
76 return oldAmountString;
77 }
78 107
79 108
80 public override bool Execute() 109 public override bool Execute()
81 { 110 {
82 this.Redo(); 111 this.Redo();