Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate API/Commands/AbstractSetUnitEquipmentAmountCommand.cs @ 337:3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 03 Apr 2011 18:50:32 +0000 |
parents | |
children | c8002429ab45 |
rev | line source |
---|---|
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 // This file (AbstractSetUnitEquipmentAmountCommand.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 // |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
3 // 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. |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 using System; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 using IBBoard.Commands; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 using IBBoard.Lang; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 using IBBoard.WarFoundry.API.Objects; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 using IBBoard.WarFoundry.API.Util; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 namespace IBBoard.WarFoundry.API.Commands |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 /// <summary> |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 /// Abstract parent class for commands that set the amount of an equipment item a unit has to a fixed numeric or ratio value |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 /// </summary> |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 public abstract class AbstractSetUnitEquipmentAmountCommand : Command |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 private Unit unit; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 private UnitEquipmentItem equip; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 private double oldAmount; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 private bool oldAmountWasRatio; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
22 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 public AbstractSetUnitEquipmentAmountCommand(Unit unit, UnitEquipmentItem item) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 this.unit = unit; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 equip = item; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 oldAmount = UnitEquipmentUtil.GetEquipmentAmount(unit, equip); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 oldAmountWasRatio = UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, equip); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
30 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
31 public override bool CanExecute() |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
32 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
33 return (unit != null && equip != null); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
34 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
35 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
36 public override string Description |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
37 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
38 get |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
39 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
40 return Translation.GetTranslation("setEquipmentAmountCommandDescription", "set {0} amount for {1} to {2}", equip.Name, unit.Name, GetNewAmountString()); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
41 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
42 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
43 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
44 /// <summary> |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
45 /// Gets the string representation for the new amount of the equipment item to take |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
46 /// </summary> |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
47 /// <returns> |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
48 /// the string representation for the new amount of the equipment item to take |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
49 /// </returns> |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
50 protected abstract string GetNewAmountString(); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
51 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
52 public override string UndoDescription |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
53 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
54 get |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
55 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
56 return Translation.GetTranslation("setEquipmentAmountCommandUndoDescription", "set {0} amount for {1} to {2}", equip.Name, unit.Name, GetOldAmountString()); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
57 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
58 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
59 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
60 /// <summary> |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
61 /// Gets the string representation for the old amount of the equipment item to take |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
62 /// </summary> |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
63 /// <returns> |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
64 /// the string representation for the old amount of the equipment item to take |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
65 /// </returns> |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
66 protected string GetOldAmountString() |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
67 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
68 return oldAmountWasRatio ? GetRatioAmountString(oldAmount, UnitEquipmentRatioSelection.CalculateNumberTaken(Unit, EquipItem, oldAmount)) : GetNumberAmountString((int)oldAmount); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
69 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
70 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
71 protected string GetNumberAmountString(int number) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
72 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
73 return Translation.GetTranslation("equipmentAmountNumber", "{0}", number); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
74 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
75 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
76 protected string GetRatioAmountString(double amount, int number) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
77 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
78 string amountString; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
79 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
80 if (amount == 100) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
81 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
82 amountString = Translation.GetTranslation("equipmentAmountAll", "all ({1})", amount, number); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
83 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
84 else |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
85 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
86 amountString = Translation.GetTranslation("equipmentAmountPercentage", "{0}% ({1})", amount, number); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
87 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
88 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
89 return amountString; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
90 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
91 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
92 public override bool Execute() |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
93 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
94 this.Redo(); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
95 return true; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
96 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
97 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
98 public override void Undo() |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
99 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
100 if (oldAmountWasRatio) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
101 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
102 unit.SetEquipmentRatio(equip, oldAmount); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
103 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
104 else |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
105 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
106 unit.SetEquipmentAmount(equip, (int)oldAmount); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
107 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
108 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
109 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
110 public UnitEquipmentItem EquipItem |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
111 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
112 get { return equip; } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
113 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
114 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
115 public Unit Unit |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
116 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
117 get { return unit; } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
118 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
119 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
120 } |