Mercurial > repos > IBDev-IBBoard.WarFoundry.API
comparison api/Commands/AbstractSetUnitEquipmentAmountCommand.cs @ 298:483b491d18f4
Fixes #337: Merge API v0.1.1 changes into v0.2
* Merge translation-related changes from v0.1.1 branch
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 17 Jan 2011 20:02:41 +0000 |
parents | 65553d2c8612 |
children |
comparison
equal
deleted
inserted
replaced
297:349e521785c1 | 298:483b491d18f4 |
---|---|
17 { | 17 { |
18 private Unit unit; | 18 private Unit unit; |
19 private UnitEquipmentItem equip; | 19 private UnitEquipmentItem equip; |
20 private double oldAmount; | 20 private double oldAmount; |
21 private bool oldAmountWasRatio; | 21 private bool oldAmountWasRatio; |
22 private string description; | 22 |
23 private string undoDescription; | |
24 | |
25 public AbstractSetUnitEquipmentAmountCommand(Unit unit, UnitEquipmentItem item) | 23 public AbstractSetUnitEquipmentAmountCommand(Unit unit, UnitEquipmentItem item) |
26 { | 24 { |
27 this.unit = unit; | 25 this.unit = unit; |
28 equip = item; | 26 equip = item; |
29 oldAmount = UnitEquipmentUtil.GetEquipmentAmount(unit, equip); | 27 oldAmount = UnitEquipmentUtil.GetEquipmentAmount(unit, equip); |
30 oldAmountWasRatio = UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, equip); | 28 oldAmountWasRatio = UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, equip); |
31 } | 29 } |
32 | 30 |
33 public override bool CanExecute() | 31 public override bool CanExecute() |
34 { | 32 { |
35 return (unit!=null && equip!=null); | 33 return (unit != null && equip != null); |
36 } | 34 } |
37 | 35 |
38 public override string Description | 36 public override string Description |
39 { | 37 { |
40 get | 38 get |
41 { | 39 { |
42 if (description == null) | 40 return Translation.GetTranslation("setEquipmentAmountCommandDescription", "set {0} amount for {1} to {2}", equip.Name, unit.Name, GetNewAmountString()); |
43 { | |
44 description = Translation.GetTranslation("setEquipmentAmountCommandDescription", "set {0} amount for {1} to {2}", equip.Name, unit.Name, GetNewAmountString()); | |
45 } | |
46 | |
47 return description; | |
48 } | 41 } |
49 } | 42 } |
50 | 43 |
51 /// <summary> | 44 /// <summary> |
52 /// Gets the string representation for the new amount of the equipment item to take | 45 /// Gets the string representation for the new amount of the equipment item to take |
58 | 51 |
59 public override string UndoDescription | 52 public override string UndoDescription |
60 { | 53 { |
61 get | 54 get |
62 { | 55 { |
63 if (undoDescription == null) | 56 return Translation.GetTranslation("setEquipmentAmountCommandUndoDescription", "set {0} amount for {1} to {2}", equip.Name, unit.Name, GetOldAmountString()); |
64 { | |
65 undoDescription = Translation.GetTranslation("setEquipmentAmountCommandUndoDescription", "set {0} amount for {1} to {2}", equip.Name, unit.Name, GetOldAmountString()); | |
66 } | |
67 | |
68 return undoDescription; | |
69 } | 57 } |
70 } | 58 } |
71 | 59 |
72 /// <summary> | 60 /// <summary> |
73 /// Gets the string representation for the old amount of the equipment item to take | 61 /// Gets the string representation for the old amount of the equipment item to take |
77 /// </returns> | 65 /// </returns> |
78 protected string GetOldAmountString() | 66 protected string GetOldAmountString() |
79 { | 67 { |
80 return oldAmountWasRatio ? GetRatioAmountString(oldAmount, UnitEquipmentRatioSelection.CalculateNumberTaken(Unit, EquipItem, oldAmount)) : GetNumberAmountString((int)oldAmount); | 68 return oldAmountWasRatio ? GetRatioAmountString(oldAmount, UnitEquipmentRatioSelection.CalculateNumberTaken(Unit, EquipItem, oldAmount)) : GetNumberAmountString((int)oldAmount); |
81 } | 69 } |
82 | 70 |
83 protected string GetNumberAmountString(int number) | 71 protected string GetNumberAmountString(int number) |
84 { | 72 { |
85 return Translation.GetTranslation ("equipmentAmountNumber", "{0}", number); | 73 return Translation.GetTranslation("equipmentAmountNumber", "{0}", number); |
86 } | 74 } |
87 | 75 |
88 protected string GetRatioAmountString (double amount, int number) | 76 protected string GetRatioAmountString(double amount, int number) |
89 { | 77 { |
90 string amountString; | 78 string amountString; |
91 | 79 |
92 if (amount == 100) | 80 if (amount == 100) |
93 { | 81 { |
94 amountString = Translation.GetTranslation ("equipmentAmountAll", "all ({1})", amount, number); | 82 amountString = Translation.GetTranslation("equipmentAmountAll", "all ({1})", amount, number); |
95 } | 83 } |
96 else | 84 else |
97 { | 85 { |
98 amountString = Translation.GetTranslation ("equipmentAmountPercentage", "{0}% ({1})", amount, number); | 86 amountString = Translation.GetTranslation("equipmentAmountPercentage", "{0}% ({1})", amount, number); |
99 } | 87 } |
100 | 88 |
101 return amountString; | 89 return amountString; |
102 } | 90 } |
103 | 91 |
105 { | 93 { |
106 this.Redo(); | 94 this.Redo(); |
107 return true; | 95 return true; |
108 } | 96 } |
109 | 97 |
110 public override void Undo () | 98 public override void Undo() |
111 { | 99 { |
112 if (oldAmountWasRatio) | 100 if (oldAmountWasRatio) |
113 { | 101 { |
114 unit.SetEquipmentRatio(equip, oldAmount); | 102 unit.SetEquipmentRatio(equip, oldAmount); |
115 } | 103 } |
116 else | 104 else |
117 { | 105 { |
118 unit.SetEquipmentAmount(equip, (int)oldAmount); | 106 unit.SetEquipmentAmount(equip, (int)oldAmount); |
119 } | 107 } |
120 } | 108 } |
121 | |
122 | 109 |
123 public UnitEquipmentItem EquipItem | 110 public UnitEquipmentItem EquipItem |
124 { | 111 { |
125 get { return equip; } | 112 get { return equip; } |
126 } | 113 } |