Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.WinForms
annotate FrmReplaceUnitEquipment.cs @ 53:e6d0d9eababf
Fixes #163: Show unit cost on unit dialog
* Add a quick label with the points cost of the unit - can be moved and repositioned based on user feedback
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 16 Sep 2009 19:50:39 +0000 |
parents | 2f2e46cd4171 |
children | ff80ed9ac50f |
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; | |
14 | |
15 namespace IBBoard.WarFoundry | |
16 { | |
17 /// <summary> | |
18 /// Summary description for FrmNewUnitEquipment. | |
19 /// </summary> | |
20 public class FrmReplaceUnitEquipment : System.Windows.Forms.Form | |
21 { | |
22 private Unit unit; | |
23 private UnitEquipmentItem oldItem; | |
24 private CommandStack commandStack; | |
25 private System.Windows.Forms.Label lblAmount; | |
26 private System.Windows.Forms.Button bttnCancel; | |
27 private System.Windows.Forms.Button bttnOkay; | |
28 private System.Windows.Forms.Label lblItem; | |
29 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
|
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 FrmReplaceUnitEquipment(Unit unit, UnitEquipmentItem item, CommandStack stack) | |
37 { | |
38 commandStack = stack; | |
39 this.unit = unit; | |
40 oldItem = item; | |
41 InitializeComponent(); | |
42 this.Text = "Replace " + item.EquipmentItem.Name + " with new equipment"; | |
43 object[] items = Arrays.Subtract(unit.UnitType.GetEquipmentItemsByExclusionGroup(item.MutexGroup), unit.GetEquipment()); | |
44 listItems.Items.AddRange(items); | |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
45 equipmentAmount.SetUnit(unit); |
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 { | |
70 this.lblAmount = new System.Windows.Forms.Label(); | |
71 this.bttnCancel = new System.Windows.Forms.Button(); | |
72 this.bttnOkay = new System.Windows.Forms.Button(); | |
73 this.lblItem = new System.Windows.Forms.Label(); | |
74 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
|
75 this.equipmentAmount = new IBBoard.WarFoundry.GUI.WinForms.UI.EquipmentAmountControl(); |
36 | 76 this.SuspendLayout(); |
77 // | |
78 // lblAmount | |
79 // | |
80 this.lblAmount.Location = new System.Drawing.Point(8, 80); | |
81 this.lblAmount.Name = "lblAmount"; | |
82 this.lblAmount.Size = new System.Drawing.Size(72, 23); | |
83 this.lblAmount.TabIndex = 2; | |
84 this.lblAmount.Text = "amount"; | |
85 this.lblAmount.TextAlign = System.Drawing.ContentAlignment.TopRight; | |
86 // | |
87 // bttnCancel | |
88 // | |
89 this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; | |
90 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
|
91 this.bttnCancel.Location = new System.Drawing.Point(159, 184); |
36 | 92 this.bttnCancel.Name = "bttnCancel"; |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
93 this.bttnCancel.Size = new System.Drawing.Size(75, 23); |
36 | 94 this.bttnCancel.TabIndex = 3; |
95 this.bttnCancel.Text = "cancel"; | |
96 this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click); | |
97 // | |
98 // bttnOkay | |
99 // | |
100 this.bttnOkay.Enabled = false; | |
101 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
|
102 this.bttnOkay.Location = new System.Drawing.Point(11, 184); |
36 | 103 this.bttnOkay.Name = "bttnOkay"; |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
104 this.bttnOkay.Size = new System.Drawing.Size(75, 23); |
36 | 105 this.bttnOkay.TabIndex = 4; |
106 this.bttnOkay.Text = "okay"; | |
107 this.bttnOkay.Click += new System.EventHandler(this.bttnOkay_Click); | |
108 // | |
109 // lblItem | |
110 // | |
111 this.lblItem.Location = new System.Drawing.Point(0, 8); | |
112 this.lblItem.Name = "lblItem"; | |
113 this.lblItem.Size = new System.Drawing.Size(80, 23); | |
114 this.lblItem.TabIndex = 6; | |
115 this.lblItem.Text = "item"; | |
116 this.lblItem.TextAlign = System.Drawing.ContentAlignment.TopRight; | |
117 // | |
118 // listItems | |
119 // | |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
120 this.listItems.Location = new System.Drawing.Point(86, 8); |
36 | 121 this.listItems.Name = "listItems"; |
122 this.listItems.Size = new System.Drawing.Size(144, 69); | |
123 this.listItems.TabIndex = 7; | |
124 this.listItems.SelectedIndexChanged += new System.EventHandler(this.listItems_SelectedIndexChanged); | |
125 // | |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
126 // equipmentAmount |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
127 // |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
128 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
|
129 this.equipmentAmount.Name = "equipmentAmount"; |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
130 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
|
131 this.equipmentAmount.TabIndex = 8; |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
132 // |
36 | 133 // FrmReplaceUnitEquipment |
134 // | |
135 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
|
136 this.ClientSize = new System.Drawing.Size(246, 219); |
36 | 137 this.ControlBox = false; |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
138 this.Controls.Add(this.equipmentAmount); |
36 | 139 this.Controls.Add(this.listItems); |
140 this.Controls.Add(this.lblItem); | |
141 this.Controls.Add(this.bttnOkay); | |
142 this.Controls.Add(this.bttnCancel); | |
143 this.Controls.Add(this.lblAmount); | |
144 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; | |
145 this.Name = "FrmReplaceUnitEquipment"; | |
146 this.ShowInTaskbar = false; | |
147 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; | |
148 this.Text = "FrmEditUnitEquipment"; | |
149 this.ResumeLayout(false); | |
150 | |
151 } | |
152 #endregion | |
153 | |
154 private void bttnOkay_Click(object sender, System.EventArgs e) | |
155 { | |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
156 SetValue(); |
36 | 157 this.Close(); |
158 } | |
159 | |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
160 private void SetValue() |
36 | 161 { |
162 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
|
163 bool setValue = true; |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
164 double amount = equipmentAmount.EquipmentAmount; |
36 | 165 |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
166 if (amount == 0) |
36 | 167 { |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
168 if (equipItem.IsRequired) |
36 | 169 { |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
170 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
|
171 setValue = false; |
36 | 172 } |
173 else | |
174 { | |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
175 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
|
176 |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
177 if (dr != DialogResult.Yes) |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
178 { |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
179 setValue = false; |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
180 } |
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 double oldAmount = unit.GetEquipmentAmount(equipItem); |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
185 |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
186 if (setValue && oldAmount != amount) |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
187 { |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
188 if (equipmentAmount.IsRatioEquipmentAmount) |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
189 { |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
190 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
|
191 } |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
192 else |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
193 { |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
194 commandStack.Execute(new ReplaceUnitEquipmentWithNumericAmountItemCommand(unit, oldItem, equipItem, (int)amount)); |
36 | 195 } |
196 } | |
197 } | |
198 | |
199 private void bttnCancel_Click(object sender, System.EventArgs e) | |
200 { | |
201 this.Close(); | |
202 } | |
203 | |
204 private void listItems_SelectedIndexChanged(object sender, System.EventArgs e) | |
205 { | |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
206 equipmentAmount.SetUnitEquipmentItem((UnitEquipmentItem)listItems.SelectedItem); |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
207 SetOkayButton(); |
36 | 208 } |
209 | |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
210 private void SetOkayButton() |
36 | 211 { |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
212 double equipAmount = equipmentAmount.EquipmentAmount; |
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
213 bttnOkay.Enabled = equipAmount > 0 || equipAmount == WarFoundryCore.INFINITY || !((UnitEquipmentItem)listItems.SelectedItem).IsRequired; |
36 | 214 } |
215 | |
216 private void numEquipAmount_ValueChanged(object sender, System.EventArgs e) | |
217 { | |
47
2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents:
46
diff
changeset
|
218 SetOkayButton(); |
36 | 219 } |
220 } | |
221 } |