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