annotate api/Commands/AbstractSetUnitEquipmentAmountCommand.cs @ 325:e0580a009e75

Re #324: Add saving of Race and System data to files * Remove extra interfaces, as their replacements would be implementation specific and the break-down is now only a clean coding issue * Strip out extra code from Army and GameSystem saver
author IBBoard <dev@ibboard.co.uk>
date Sat, 12 Mar 2011 20:32:08 +0000
parents 483b491d18f4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
101
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
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
104
2f3cafb69799 Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents: 101
diff changeset
2 //
2f3cafb69799 Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents: 101
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.
101
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System;
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using IBBoard.Commands;
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using IBBoard.Lang;
216
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 215
diff changeset
8 using IBBoard.WarFoundry.API.Objects;
214
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
9 using IBBoard.WarFoundry.API.Util;
101
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 namespace IBBoard.WarFoundry.API.Commands
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 {
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 /// <summary>
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
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
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 /// </summary>
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 public abstract class AbstractSetUnitEquipmentAmountCommand : Command
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 {
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 private Unit unit;
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 private UnitEquipmentItem equip;
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 private double oldAmount;
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 private bool oldAmountWasRatio;
298
483b491d18f4 Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents: 216
diff changeset
22
101
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 public AbstractSetUnitEquipmentAmountCommand(Unit unit, UnitEquipmentItem item)
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 {
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 this.unit = unit;
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 equip = item;
216
65553d2c8612 * Line-ending fix
IBBoard <dev@ibboard.co.uk>
parents: 215
diff changeset
27 oldAmount = UnitEquipmentUtil.GetEquipmentAmount(unit, equip);
214
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
28 oldAmountWasRatio = UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, equip);
101
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 }
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 public override bool CanExecute()
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 {
298
483b491d18f4 Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents: 216
diff changeset
33 return (unit != null && equip != null);
101
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 }
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 public override string Description
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 {
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 get
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 {
298
483b491d18f4 Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents: 216
diff changeset
40 return Translation.GetTranslation("setEquipmentAmountCommandDescription", "set {0} amount for {1} to {2}", equip.Name, unit.Name, GetNewAmountString());
101
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 }
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 }
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 /// <summary>
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 /// Gets the string representation for the new amount of the equipment item to take
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 /// </summary>
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 /// <returns>
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 /// the string representation for the new amount of the equipment item to take
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 /// </returns>
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 protected abstract string GetNewAmountString();
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 public override string UndoDescription
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 {
214
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
54 get
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
55 {
298
483b491d18f4 Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents: 216
diff changeset
56 return Translation.GetTranslation("setEquipmentAmountCommandUndoDescription", "set {0} amount for {1} to {2}", equip.Name, unit.Name, GetOldAmountString());
101
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 }
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 }
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60 /// <summary>
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 /// Gets the string representation for the old amount of the equipment item to take
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 /// </summary>
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 /// <returns>
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 /// the string representation for the old amount of the equipment item to take
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 /// </returns>
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 protected string GetOldAmountString()
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 {
214
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
68 return oldAmountWasRatio ? GetRatioAmountString(oldAmount, UnitEquipmentRatioSelection.CalculateNumberTaken(Unit, EquipItem, oldAmount)) : GetNumberAmountString((int)oldAmount);
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
69 }
298
483b491d18f4 Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents: 216
diff changeset
70
214
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
71 protected string GetNumberAmountString(int number)
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
72 {
298
483b491d18f4 Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents: 216
diff changeset
73 return Translation.GetTranslation("equipmentAmountNumber", "{0}", number);
214
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
74 }
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
75
298
483b491d18f4 Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents: 216
diff changeset
76 protected string GetRatioAmountString(double amount, int number)
214
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
77 {
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
78 string amountString;
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
79
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
80 if (amount == 100)
101
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81 {
298
483b491d18f4 Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents: 216
diff changeset
82 amountString = Translation.GetTranslation("equipmentAmountAll", "all ({1})", amount, number);
101
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
83 }
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
84 else
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
85 {
298
483b491d18f4 Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents: 216
diff changeset
86 amountString = Translation.GetTranslation("equipmentAmountPercentage", "{0}% ({1})", amount, number);
101
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
87 }
214
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
88
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
89 return amountString;
1b718b67f7f6 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
90 }
101
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
92 public override bool Execute()
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
93 {
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94 this.Redo();
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95 return true;
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
96 }
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
97
298
483b491d18f4 Fixes #337: Merge API v0.1.1 changes into v0.2
IBBoard <dev@ibboard.co.uk>
parents: 216
diff changeset
98 public override void Undo()
101
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
99 {
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
100 if (oldAmountWasRatio)
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
101 {
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
102 unit.SetEquipmentRatio(equip, oldAmount);
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
103 }
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
104 else
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
105 {
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
106 unit.SetEquipmentAmount(equip, (int)oldAmount);
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
107 }
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
108 }
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
109
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
110 public UnitEquipmentItem EquipItem
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
111 {
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
112 get { return equip; }
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
113 }
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
114
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
115 public Unit Unit
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
116 {
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
117 get { return unit; }
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
118 }
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
119 }
f7b9423c2a5a Big mess of updates, breaking our rules on "commit little and often" because the code was so ugly.
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
120 }