Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.WinForms
annotate FrmEditUnitEquipment.cs @ 99:acaea18ac0a1
Fixes #220: Make percentage and numeric amounts more obvious
* Differentiate between "free" and costed and build up a new string with more options
* Make use of translations for all of the parts of the line
Re #179: Make sure that translations are used throughout UI
* Add new translations to file
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 21 Nov 2009 16:41:28 +0000 |
parents | c7afc7824f50 |
children | 3e78af88ceb3 |
rev | line source |
---|---|
36 | 1 // This file (FrmEditUnitEquipment.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard. |
2 // | |
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. | |
4 | |
5 using System; | |
6 using System.Drawing; | |
7 using System.ComponentModel; | |
8 using System.Windows.Forms; | |
9 using IBBoard.Commands; | |
85
0bb9f40d44eb
Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
10 using IBBoard.Lang; |
80
c243b043aa62
Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
11 using IBBoard.Windows.Forms; |
c243b043aa62
Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
12 using IBBoard.Windows.Forms.I18N; |
36 | 13 using IBBoard.WarFoundry.API; |
14 using IBBoard.WarFoundry.API.Commands; | |
15 using IBBoard.WarFoundry.API.Objects; | |
16 | |
42
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
17 namespace IBBoard.WarFoundry.GUI.WinForms |
36 | 18 { |
19 /// <summary> | |
20 /// Summary description for FrmEditUnitEquipment. | |
21 /// </summary> | |
85
0bb9f40d44eb
Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
22 public class FrmEditUnitEquipment : IBBForm |
36 | 23 { |
24 private Unit unit; | |
25 private UnitEquipmentItem equipItem; | |
26 private CommandStack commandStack; | |
80
c243b043aa62
Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
27 private IBBLabel lblAmount; |
c243b043aa62
Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
28 private IBBButton bttnCancel; |
c243b043aa62
Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents:
77
diff
changeset
|
29 private IBBButton bttnOkay; |
42
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
30 private IBBoard.WarFoundry.GUI.WinForms.UI.EquipmentAmountControl equipmentAmount; |
36 | 31 /// <summary> |
32 /// Required designer variable. | |
33 /// </summary> | |
34 private System.ComponentModel.Container components = null; | |
35 | |
36 public FrmEditUnitEquipment(Unit unit, UnitEquipmentItem equipItem, CommandStack stack) | |
37 { | |
38 commandStack = stack; | |
39 this.unit = unit; | |
40 this.equipItem = equipItem; | |
41 InitializeComponent(); | |
85
0bb9f40d44eb
Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
42 ControlTranslator.TranslateControl(this); |
0bb9f40d44eb
Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
43 this.Text = Translation.GetTranslation("FrmEditUnitEquipment", "edit {0} for {1}", equipItem.Name, unit.Name); |
42
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
44 equipmentAmount.SetUnit(unit); |
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
45 equipmentAmount.SetUnitEquipmentItem(equipItem); |
36 | 46 } |
47 | |
48 /// <summary> | |
49 /// Clean up any resources being used. | |
50 /// </summary> | |
51 protected override void Dispose( bool disposing ) | |
52 { | |
53 if( disposing ) | |
54 { | |
55 if(components != null) | |
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
|
56 { |
36 | 57 components.Dispose(); |
58 } | |
59 } | |
60 base.Dispose( disposing ); | |
61 } | |
62 | |
63 #region Windows Form Designer generated code | |
64 /// <summary> | |
65 /// Required method for Designer support - do not modify | |
66 /// the contents of this method with the code editor. | |
67 /// </summary> | |
68 private void InitializeComponent() | |
69 { | |
85
0bb9f40d44eb
Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
70 this.lblAmount = new IBBoard.Windows.Forms.IBBLabel(); |
0bb9f40d44eb
Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
71 this.bttnCancel = new IBBoard.Windows.Forms.IBBButton(); |
0bb9f40d44eb
Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
72 this.bttnOkay = new IBBoard.Windows.Forms.IBBButton(); |
42
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
73 this.equipmentAmount = new IBBoard.WarFoundry.GUI.WinForms.UI.EquipmentAmountControl(); |
36 | 74 this.SuspendLayout(); |
75 // | |
76 // lblAmount | |
77 // | |
85
0bb9f40d44eb
Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
78 this.lblAmount.Location = new System.Drawing.Point(12, 8); |
36 | 79 this.lblAmount.Name = "lblAmount"; |
85
0bb9f40d44eb
Re #88: Complete initial WinForms UI
IBBoard <dev@ibboard.co.uk>
parents:
80
diff
changeset
|
80 this.lblAmount.Size = new System.Drawing.Size(68, 74); |
36 | 81 this.lblAmount.TabIndex = 2; |
82 this.lblAmount.Text = "amount"; | |
83 this.lblAmount.TextAlign = System.Drawing.ContentAlignment.TopRight; | |
84 // | |
85 // bttnCancel | |
86 // | |
87 this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; | |
88 this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; | |
42
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
89 this.bttnCancel.Location = new System.Drawing.Point(153, 95); |
36 | 90 this.bttnCancel.Name = "bttnCancel"; |
42
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
91 this.bttnCancel.Size = new System.Drawing.Size(75, 23); |
36 | 92 this.bttnCancel.TabIndex = 3; |
93 this.bttnCancel.Text = "cancel"; | |
94 this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click); | |
95 // | |
96 // bttnOkay | |
97 // | |
98 this.bttnOkay.Enabled = false; | |
99 this.bttnOkay.FlatStyle = System.Windows.Forms.FlatStyle.System; | |
42
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
100 this.bttnOkay.Location = new System.Drawing.Point(12, 95); |
36 | 101 this.bttnOkay.Name = "bttnOkay"; |
42
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
102 this.bttnOkay.Size = new System.Drawing.Size(75, 23); |
36 | 103 this.bttnOkay.TabIndex = 4; |
104 this.bttnOkay.Text = "okay"; | |
105 this.bttnOkay.Click += new System.EventHandler(this.bttnOkay_Click); | |
106 // | |
42
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
107 // equipmentAmount |
36 | 108 // |
42
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
109 this.equipmentAmount.Location = new System.Drawing.Point(88, 5); |
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
110 this.equipmentAmount.Name = "equipmentAmount"; |
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
111 this.equipmentAmount.Size = new System.Drawing.Size(155, 77); |
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
112 this.equipmentAmount.TabIndex = 5; |
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
113 this.equipmentAmount.ValueChanged += new System.EventHandler(this.equipmentAmount_ValueChanged); |
36 | 114 // |
115 // FrmEditUnitEquipment | |
116 // | |
117 this.AcceptButton = this.bttnOkay; | |
118 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); | |
119 this.CancelButton = this.bttnCancel; | |
42
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
120 this.ClientSize = new System.Drawing.Size(240, 130); |
36 | 121 this.ControlBox = false; |
42
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
122 this.Controls.Add(this.equipmentAmount); |
36 | 123 this.Controls.Add(this.bttnOkay); |
124 this.Controls.Add(this.bttnCancel); | |
125 this.Controls.Add(this.lblAmount); | |
126 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; | |
127 this.Name = "FrmEditUnitEquipment"; | |
128 this.ShowInTaskbar = false; | |
129 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; | |
130 this.Text = "FrmEditUnitEquipment"; | |
131 this.ResumeLayout(false); | |
132 | |
133 } | |
134 #endregion | |
135 | |
136 private void bttnOkay_Click(object sender, System.EventArgs e) | |
137 { | |
43
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
138 if (SetValue()) |
36 | 139 { |
140 this.Close(); | |
141 } | |
142 } | |
143 | |
43
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
144 private bool SetValue() |
36 | 145 { |
43
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
146 bool setValue = true; |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
147 double amount = equipmentAmount.EquipmentAmount; |
36 | 148 |
43
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
149 if (amount == 0) |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
150 { |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
151 if (equipItem.IsRequired) |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
152 { |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
153 MessageBox.Show(this, "This item is required and cannot be removed. It must have a quantity of at least one or be replaced by an alternative.", "Required item", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
154 setValue = false; |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
155 } |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
156 else |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
157 { |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
158 DialogResult dr = MessageBox.Show(this, "This will remove the item from the unit. Continue?", "Confirm remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); |
36 | 159 |
43
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
160 if (dr != DialogResult.Yes) |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
161 { |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
162 setValue = false; |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
163 } |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
164 } |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
165 } |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
166 |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
167 double oldAmount = unit.GetEquipmentAmount(equipItem); |
36 | 168 |
43
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
169 if (setValue && oldAmount != amount) |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
170 { |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
171 if (equipmentAmount.IsRatioEquipmentAmount) |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
172 { |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
173 commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, amount)); |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
174 } |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
175 else |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
176 { |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
177 commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int)amount)); |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
178 } |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
179 } |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
180 |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
181 return setValue; |
36 | 182 } |
183 | |
184 private void bttnCancel_Click(object sender, System.EventArgs e) | |
185 { | |
186 this.Close(); | |
187 } | |
188 | |
98
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
189 private void SetOkayButton() |
36 | 190 { |
43
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
191 double equipAmount = equipmentAmount.EquipmentAmount; |
98
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
192 bttnOkay.Enabled = equipAmount > 0 || !equipItem.IsRequired; |
36 | 193 } |
194 | |
42
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
195 private void equipmentAmount_ValueChanged(object sender, EventArgs e) |
36 | 196 { |
98
c7afc7824f50
Fixes #218: "Amount too high" warning can result in negative items
IBBoard <dev@ibboard.co.uk>
parents:
85
diff
changeset
|
197 SetOkayButton(); |
36 | 198 } |
199 } | |
200 } |