annotate Util/UnitEquipmentChoice.cs @ 176:0e39412353c4

Fixes #153: Default name for armies * Merge back in to Trunk
author IBBoard <dev@ibboard.co.uk>
date Wed, 08 Sep 2010 20:17:48 +0000
parents 3e78af88ceb3
children 1ca23c47345a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
1 // This file (UnitEquipmentChoice.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard.
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
2 //
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
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.
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
4
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
5 using System;
99
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
6 using IBBoard.Lang;
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
7 using IBBoard.WarFoundry.API.Objects;
99
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
8 using IBBoard.WarFoundry.API.Util;
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
9
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
10 namespace IBBoard.WarFoundry.GUI.WinForms.Util
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
11 {
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
12 /// <summary>
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
13 /// A helper object that holds an equipment choice for a unit.
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
14 /// </summary>
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
15
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
16 public class UnitEquipmentChoice
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
17 {
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
18 private Unit unit;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
19 private UnitEquipmentItem item;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
20
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
21 public UnitEquipmentChoice(Unit unit, UnitEquipmentItem unitItem)
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
22 {
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
23 this.unit = unit;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
24 item = unitItem;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
25 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
26
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
27 public override string ToString()
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
28 {
99
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
29 String translation = "";
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
30
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
31 if (item.Cost == 0)
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
32 {
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
33 translation = Translation.GetTranslation("equipmentAmountWithZeroCost", "{0} ({1} - free)", item.Name, GetAmountString());
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
34 }
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
35 else
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
36 {
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
37 translation = Translation.GetTranslation("equipmentAmountWithCost", "{0} ({1} at {2}pts each)", item.Name, GetAmountString(), item.Cost);
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
38 }
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
39
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
40 return translation;
34
3ceb0efd261f Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 24
diff changeset
41 }
3ceb0efd261f Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 24
diff changeset
42
3ceb0efd261f Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 24
diff changeset
43 private string GetAmountString()
3ceb0efd261f Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 24
diff changeset
44 {
99
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
45 double amount = UnitEquipmentUtil.GetEquipmentAmount(unit, item);
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
46 string amountString = "";
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
47
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
48 if (UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, item))
34
3ceb0efd261f Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 24
diff changeset
49 {
99
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
50 int number = UnitEquipmentUtil.GetEquipmentAmountTaken(unit, item);
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
51
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
52 if (amount == 100)
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
53 {
101
3e78af88ceb3 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
54 amountString = Translation.GetTranslation("equipmentChoiceAmountAll", "all ({1})", amount, number);
99
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
55 }
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
56 else
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
57 {
101
3e78af88ceb3 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
58 amountString = Translation.GetTranslation("equipmentChoiceAmountPercentage", "{0}% ({1})", amount, number);
99
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
59 }
34
3ceb0efd261f Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 24
diff changeset
60 }
3ceb0efd261f Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 24
diff changeset
61 else
3ceb0efd261f Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 24
diff changeset
62 {
101
3e78af88ceb3 Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents: 99
diff changeset
63 amountString = Translation.GetTranslation("equipmentChoiceAmountNumber", "{0}", amount);
34
3ceb0efd261f Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 24
diff changeset
64 }
99
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
65
acaea18ac0a1 Fixes #220: Make percentage and numeric amounts more obvious
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
66 return amountString;
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
67 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
68
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
69 public UnitEquipmentItem Item
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
70 {
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
71 get { return item; }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
72 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
73 }
8
755e60be28be Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74 }