Mercurial > repos > IBBoard.WarFoundry.GUI.WinForms
annotate FrmReplaceUnitEquipment.cs @ 113:c1a3993297b1
Re #115: Typing number for equipment amount doesn't update Okay button
* Switch to using ControlTranslator for the EquipmentAmountControl to resolve issues with the VisualStudio form designer erroring out because the translations aren't initialised (they still won't be, but it seems to be happy now)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 24 Dec 2009 10:52:03 +0000 |
parents | 3e78af88ceb3 |
children | b7899d084a14 |
rev | line source |
---|---|
36 | 1 // This file (FrmReplaceUnitEquipment.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2008, 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; | |
10 using IBBoard.Commands; | |
11 using IBBoard.WarFoundry.API; | |
12 using IBBoard.WarFoundry.API.Commands; | |
13 using IBBoard.WarFoundry.API.Objects; | |
101
3e78af88ceb3
Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
14 using IBBoard.WarFoundry.API.Util; |
36 | 15 |
16 namespace IBBoard.WarFoundry | |
17 { | |
18 /// <summary> | |
19 /// Summary description for FrmNewUnitEquipment. | |
20 /// </summary> | |
21 public class FrmReplaceUnitEquipment : System.Windows.Forms.Form | |
22 { | |
23 private Unit unit; | |
24 private UnitEquipmentItem oldItem; | |
25 private CommandStack commandStack; | |
26 private System.Windows.Forms.Label lblAmount; | |
27 private System.Windows.Forms.Button bttnCancel; | |
28 private System.Windows.Forms.Button bttnOkay; | |
29 private System.Windows.Forms.Label lblItem; | |
30 private System.Windows.Forms.ListBox listItems; | |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
31 private IBBoard.WarFoundry.GUI.WinForms.UI.EquipmentAmountControl equipmentAmount; |
36 | 32 /// <summary> |
33 /// Required designer variable. | |
34 /// </summary> | |
35 private System.ComponentModel.Container components = null; | |
36 | |
37 public FrmReplaceUnitEquipment(Unit unit, UnitEquipmentItem item, CommandStack stack) | |
38 { | |
39 commandStack = stack; | |
40 this.unit = unit; | |
41 oldItem = item; | |
42 InitializeComponent(); | |
43 this.Text = "Replace " + item.EquipmentItem.Name + " with new equipment"; | |
70
a8667ab60362
Re #180: Add multiple mutex groups
IBBoard <dev@ibboard.co.uk>
parents:
69
diff
changeset
|
44 object[] items = Arrays.Subtract(unit.UnitType.GetEquipmentItemsByExclusionGroups(item.MutexGroups), unit.GetEquipment()); |
36 | 45 listItems.Items.AddRange(items); |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
46 equipmentAmount.SetUnit(unit); |
36 | 47 } |
48 | |
49 /// <summary> | |
50 /// Clean up any resources being used. | |
51 /// </summary> | |
52 protected override void Dispose( bool disposing ) | |
53 { | |
54 if( disposing ) | |
55 { | |
56 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
|
57 { |
36 | 58 components.Dispose(); |
59 } | |
60 } | |
61 base.Dispose( disposing ); | |
62 } | |
63 | |
64 #region Windows Form Designer generated code | |
65 /// <summary> | |
66 /// Required method for Designer support - do not modify | |
67 /// the contents of this method with the code editor. | |
68 /// </summary> | |
69 private void InitializeComponent() | |
70 { | |
71 this.lblAmount = new System.Windows.Forms.Label(); | |
72 this.bttnCancel = new System.Windows.Forms.Button(); | |
73 this.bttnOkay = new System.Windows.Forms.Button(); | |
74 this.lblItem = new System.Windows.Forms.Label(); | |
75 this.listItems = new System.Windows.Forms.ListBox(); | |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
76 this.equipmentAmount = new IBBoard.WarFoundry.GUI.WinForms.UI.EquipmentAmountControl(); |
36 | 77 this.SuspendLayout(); |
78 // | |
79 // lblAmount | |
80 // | |
81 this.lblAmount.Location = new System.Drawing.Point(8, 80); | |
82 this.lblAmount.Name = "lblAmount"; | |
83 this.lblAmount.Size = new System.Drawing.Size(72, 23); | |
84 this.lblAmount.TabIndex = 2; | |
85 this.lblAmount.Text = "amount"; | |
86 this.lblAmount.TextAlign = System.Drawing.ContentAlignment.TopRight; | |
87 // | |
88 // bttnCancel | |
89 // | |
90 this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; | |
91 this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; | |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
92 this.bttnCancel.Location = new System.Drawing.Point(159, 184); |
36 | 93 this.bttnCancel.Name = "bttnCancel"; |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
94 this.bttnCancel.Size = new System.Drawing.Size(75, 23); |
36 | 95 this.bttnCancel.TabIndex = 3; |
96 this.bttnCancel.Text = "cancel"; | |
97 this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click); | |
98 // | |
99 // bttnOkay | |
100 // | |
101 this.bttnOkay.Enabled = false; | |
102 this.bttnOkay.FlatStyle = System.Windows.Forms.FlatStyle.System; | |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
103 this.bttnOkay.Location = new System.Drawing.Point(11, 184); |
36 | 104 this.bttnOkay.Name = "bttnOkay"; |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
105 this.bttnOkay.Size = new System.Drawing.Size(75, 23); |
36 | 106 this.bttnOkay.TabIndex = 4; |
107 this.bttnOkay.Text = "okay"; | |
108 this.bttnOkay.Click += new System.EventHandler(this.bttnOkay_Click); | |
109 // | |
110 // lblItem | |
111 // | |
112 this.lblItem.Location = new System.Drawing.Point(0, 8); | |
113 this.lblItem.Name = "lblItem"; | |
114 this.lblItem.Size = new System.Drawing.Size(80, 23); | |
115 this.lblItem.TabIndex = 6; | |
116 this.lblItem.Text = "item"; | |
117 this.lblItem.TextAlign = System.Drawing.ContentAlignment.TopRight; | |
118 // | |
119 // listItems | |
120 // | |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
121 this.listItems.Location = new System.Drawing.Point(86, 8); |
36 | 122 this.listItems.Name = "listItems"; |
123 this.listItems.Size = new System.Drawing.Size(144, 69); | |
124 this.listItems.TabIndex = 7; | |
125 this.listItems.SelectedIndexChanged += new System.EventHandler(this.listItems_SelectedIndexChanged); | |
126 // | |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
127 // equipmentAmount |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
128 // |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
129 this.equipmentAmount.Location = new System.Drawing.Point(86, 83); |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
130 this.equipmentAmount.Name = "equipmentAmount"; |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
131 this.equipmentAmount.Size = new System.Drawing.Size(155, 77); |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
132 this.equipmentAmount.TabIndex = 8; |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
133 // |
36 | 134 // FrmReplaceUnitEquipment |
135 // | |
136 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); | |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
137 this.ClientSize = new System.Drawing.Size(246, 219); |
36 | 138 this.ControlBox = false; |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
139 this.Controls.Add(this.equipmentAmount); |
36 | 140 this.Controls.Add(this.listItems); |
141 this.Controls.Add(this.lblItem); | |
142 this.Controls.Add(this.bttnOkay); | |
143 this.Controls.Add(this.bttnCancel); | |
144 this.Controls.Add(this.lblAmount); | |
145 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; | |
146 this.Name = "FrmReplaceUnitEquipment"; | |
147 this.ShowInTaskbar = false; | |
148 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; | |
149 this.Text = "FrmEditUnitEquipment"; | |
150 this.ResumeLayout(false); | |
151 | |
152 } | |
153 #endregion | |
154 | |
155 private void bttnOkay_Click(object sender, System.EventArgs e) | |
156 { | |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
157 SetValue(); |
36 | 158 this.Close(); |
159 } | |
160 | |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
161 private void SetValue() |
36 | 162 { |
163 UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem; | |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
164 bool setValue = true; |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
165 double amount = equipmentAmount.EquipmentAmount; |
36 | 166 |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
167 if (amount == 0) |
36 | 168 { |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
169 if (equipItem.IsRequired) |
36 | 170 { |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
171 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); |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
172 setValue = false; |
36 | 173 } |
174 else | |
175 { | |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
176 DialogResult dr = MessageBox.Show(this, "This will remove the item from the unit. Continue?", "Confirm remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
177 |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
178 if (dr != DialogResult.Yes) |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
179 { |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
180 setValue = false; |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
181 } |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
182 } |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
183 } |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
184 |
101
3e78af88ceb3
Re #179: Make sure that translations are used throughout UI
IBBoard <dev@ibboard.co.uk>
parents:
71
diff
changeset
|
185 double oldAmount = UnitEquipmentUtil.GetEquipmentAmount(unit, equipItem); |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
186 |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
187 if (setValue && oldAmount != amount) |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
188 { |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
189 if (equipmentAmount.IsRatioEquipmentAmount) |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
190 { |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
191 commandStack.Execute(new ReplaceUnitEquipmentWithRatioAmountItemCommand(unit, oldItem, equipItem, amount)); |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
192 } |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
193 else |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
194 { |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
195 commandStack.Execute(new ReplaceUnitEquipmentWithNumericAmountItemCommand(unit, oldItem, equipItem, (int)amount)); |
36 | 196 } |
197 } | |
198 } | |
199 | |
200 private void bttnCancel_Click(object sender, System.EventArgs e) | |
201 { | |
202 this.Close(); | |
203 } | |
204 | |
205 private void listItems_SelectedIndexChanged(object sender, System.EventArgs e) | |
206 { | |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
207 equipmentAmount.SetUnitEquipmentItem((UnitEquipmentItem)listItems.SelectedItem); |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
208 SetOkayButton(); |
36 | 209 } |
210 | |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
211 private void SetOkayButton() |
36 | 212 { |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
213 double equipAmount = equipmentAmount.EquipmentAmount; |
71
74d3efaac800
Fixes #184: Unhandled exception in the unit form
IBBoard <dev@ibboard.co.uk>
parents:
70
diff
changeset
|
214 bttnOkay.Enabled = equipAmount > 0 || equipAmount == WarFoundryCore.INFINITY || (listItems.SelectedItem != null && !((UnitEquipmentItem) listItems.SelectedItem).IsRequired); |
36 | 215 } |
216 | |
217 private void numEquipAmount_ValueChanged(object sender, System.EventArgs e) | |
218 { | |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
219 SetOkayButton(); |
36 | 220 } |
221 } | |
222 } |