Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.WinForms
annotate FrmEditUnitEquipment.cs @ 48:cf644b2c65e6 WarFoundry_v0.1beta_Winforms
* Change assembly number to 0.0.1.* because we've not reached 0.1 yet, never mind 1.0!
* Add "COPYING" to the copied files so that we have a license
no-open-ticket
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 13 Sep 2009 19:03:37 +0000 |
parents | 1576f669b3eb |
children | 712915de47fd |
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; | |
10 using IBBoard.WarFoundry.API; | |
11 using IBBoard.WarFoundry.API.Commands; | |
12 using IBBoard.WarFoundry.API.Objects; | |
13 | |
42
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
14 namespace IBBoard.WarFoundry.GUI.WinForms |
36 | 15 { |
16 /// <summary> | |
17 /// Summary description for FrmEditUnitEquipment. | |
18 /// </summary> | |
19 public class FrmEditUnitEquipment : System.Windows.Forms.Form | |
20 { | |
21 private Unit unit; | |
22 private UnitEquipmentItem equipItem; | |
23 private CommandStack commandStack; | |
24 private System.Windows.Forms.Label lblAmount; | |
25 private System.Windows.Forms.Button bttnCancel; | |
26 private System.Windows.Forms.Button bttnOkay; | |
42
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
27 private IBBoard.WarFoundry.GUI.WinForms.UI.EquipmentAmountControl equipmentAmount; |
36 | 28 /// <summary> |
29 /// Required designer variable. | |
30 /// </summary> | |
31 private System.ComponentModel.Container components = null; | |
32 | |
33 public FrmEditUnitEquipment(Unit unit, UnitEquipmentItem equipItem, CommandStack stack) | |
34 { | |
35 commandStack = stack; | |
36 this.unit = unit; | |
37 this.equipItem = equipItem; | |
38 InitializeComponent(); | |
39 this.Text = equipItem.Name + " for " + unit.Name; | |
42
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
40 equipmentAmount.SetUnit(unit); |
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
41 equipmentAmount.SetUnitEquipmentItem(equipItem); |
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
42 equipmentAmount.SetUnitEquipmentItemAmount(unit.GetEquipmentAmount(equipItem), unit.GetEquipmentAmountIsRatio(equipItem)); |
36 | 43 bttnOkay.Enabled = false; |
44 } | |
45 | |
46 /// <summary> | |
47 /// Clean up any resources being used. | |
48 /// </summary> | |
49 protected override void Dispose( bool disposing ) | |
50 { | |
51 if( disposing ) | |
52 { | |
53 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
|
54 { |
36 | 55 components.Dispose(); |
56 } | |
57 } | |
58 base.Dispose( disposing ); | |
59 } | |
60 | |
61 #region Windows Form Designer generated code | |
62 /// <summary> | |
63 /// Required method for Designer support - do not modify | |
64 /// the contents of this method with the code editor. | |
65 /// </summary> | |
66 private void InitializeComponent() | |
67 { | |
68 this.lblAmount = new System.Windows.Forms.Label(); | |
69 this.bttnCancel = new System.Windows.Forms.Button(); | |
70 this.bttnOkay = new System.Windows.Forms.Button(); | |
42
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
71 this.equipmentAmount = new IBBoard.WarFoundry.GUI.WinForms.UI.EquipmentAmountControl(); |
36 | 72 this.SuspendLayout(); |
73 // | |
74 // lblAmount | |
75 // | |
76 this.lblAmount.Location = new System.Drawing.Point(8, 8); | |
77 this.lblAmount.Name = "lblAmount"; | |
78 this.lblAmount.Size = new System.Drawing.Size(72, 23); | |
79 this.lblAmount.TabIndex = 2; | |
80 this.lblAmount.Text = "amount"; | |
81 this.lblAmount.TextAlign = System.Drawing.ContentAlignment.TopRight; | |
82 // | |
83 // bttnCancel | |
84 // | |
85 this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; | |
86 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
|
87 this.bttnCancel.Location = new System.Drawing.Point(153, 95); |
36 | 88 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
|
89 this.bttnCancel.Size = new System.Drawing.Size(75, 23); |
36 | 90 this.bttnCancel.TabIndex = 3; |
91 this.bttnCancel.Text = "cancel"; | |
92 this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click); | |
93 // | |
94 // bttnOkay | |
95 // | |
96 this.bttnOkay.Enabled = false; | |
97 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
|
98 this.bttnOkay.Location = new System.Drawing.Point(12, 95); |
36 | 99 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
|
100 this.bttnOkay.Size = new System.Drawing.Size(75, 23); |
36 | 101 this.bttnOkay.TabIndex = 4; |
102 this.bttnOkay.Text = "okay"; | |
103 this.bttnOkay.Click += new System.EventHandler(this.bttnOkay_Click); | |
104 // | |
42
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
105 // equipmentAmount |
36 | 106 // |
42
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
107 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
|
108 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
|
109 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
|
110 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
|
111 this.equipmentAmount.ValueChanged += new System.EventHandler(this.equipmentAmount_ValueChanged); |
36 | 112 // |
113 // FrmEditUnitEquipment | |
114 // | |
115 this.AcceptButton = this.bttnOkay; | |
116 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); | |
117 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
|
118 this.ClientSize = new System.Drawing.Size(240, 130); |
36 | 119 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
|
120 this.Controls.Add(this.equipmentAmount); |
36 | 121 this.Controls.Add(this.bttnOkay); |
122 this.Controls.Add(this.bttnCancel); | |
123 this.Controls.Add(this.lblAmount); | |
124 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; | |
125 this.Name = "FrmEditUnitEquipment"; | |
126 this.ShowInTaskbar = false; | |
127 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; | |
128 this.Text = "FrmEditUnitEquipment"; | |
129 this.ResumeLayout(false); | |
130 | |
131 } | |
132 #endregion | |
133 | |
134 private void bttnOkay_Click(object sender, System.EventArgs e) | |
135 { | |
43
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
136 if (SetValue()) |
36 | 137 { |
138 this.Close(); | |
139 } | |
140 } | |
141 | |
43
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
142 private bool SetValue() |
36 | 143 { |
43
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
144 bool setValue = true; |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
145 double amount = equipmentAmount.EquipmentAmount; |
36 | 146 |
43
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
147 if (amount == 0) |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
148 { |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
149 if (equipItem.IsRequired) |
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 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
|
152 setValue = false; |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
153 } |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
154 else |
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 DialogResult dr = MessageBox.Show(this, "This will remove the item from the unit. Continue?", "Confirm remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); |
36 | 157 |
43
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
158 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
|
159 { |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
160 setValue = false; |
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 } |
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 double oldAmount = unit.GetEquipmentAmount(equipItem); |
36 | 166 |
43
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
167 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
|
168 { |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
169 if (equipmentAmount.IsRatioEquipmentAmount) |
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 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
|
172 } |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
173 else |
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 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
|
176 } |
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
177 } |
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 return setValue; |
36 | 180 } |
181 | |
182 private void bttnCancel_Click(object sender, System.EventArgs e) | |
183 { | |
184 this.Close(); | |
185 } | |
186 | |
42
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
187 private void setOkayButton() |
36 | 188 { |
43
7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
42
diff
changeset
|
189 double equipAmount = equipmentAmount.EquipmentAmount; |
42
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
190 bttnOkay.Enabled = equipAmount > 0 || equipAmount == WarFoundryCore.INFINITY || !equipItem.IsRequired; |
36 | 191 } |
192 | |
42
d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents:
36
diff
changeset
|
193 private void equipmentAmount_ValueChanged(object sender, EventArgs e) |
36 | 194 { |
195 setOkayButton(); | |
196 } | |
197 } | |
198 } |