Mercurial > repos > IBBoard.WarFoundry.GUI.WinForms
annotate FrmEditUnitEquipment.cs @ 7:9828ba4f3f36
Closes #43 - Test Ticket for checking into SVN
* First Check-in!
* Did some code changes to allow the app to load default race and system files from the "data" directory.
* Also changed select system dialog so you can actually select a game system.
author | gregmita |
---|---|
date | Sat, 07 Mar 2009 21:08:31 +0000 |
parents | 8935971e307c |
children | 755e60be28be |
rev | line source |
---|---|
3
8935971e307c
Fixes #1 - Correctly license code
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
1 // This file (FrmEditUnitEquipment.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard. |
8935971e307c
Fixes #1 - Correctly license code
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
2 // |
8935971e307c
Fixes #1 - Correctly license code
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license. |
8935971e307c
Fixes #1 - Correctly license code
IBBoard <dev@ibboard.co.uk>
parents:
1
diff
changeset
|
4 |
0 | 5 using System; |
6 using System.Drawing; | |
7 using System.Collections; | |
8 using System.ComponentModel; | |
9 using System.Windows.Forms; | |
10 using IBBoard.Commands; | |
11 using IBBoard.WarFoundry.API; | |
12 using IBBoard.WarFoundry.API.Commands; | |
1
42cf06b8f897
Re #8 - Get a working Windows WarFoundry
IBBoard <dev@ibboard.co.uk>
parents:
0
diff
changeset
|
13 using IBBoard.WarFoundry.API.Objects; |
0 | 14 |
15 namespace IBBoard.WarFoundry | |
16 { | |
17 /// <summary> | |
18 /// Summary description for FrmEditUnitEquipment. | |
19 /// </summary> | |
20 public class FrmEditUnitEquipment : System.Windows.Forms.Form | |
21 { | |
22 private Unit unit; | |
23 private UnitEquipmentItem equipItem; | |
24 private EquipmentItem equip; | |
25 private float equipAmount; | |
26 private CommandStack commandStack; | |
27 | |
28 private System.Windows.Forms.NumericUpDown numEquipAmount; | |
29 private System.Windows.Forms.Label lblPercent; | |
30 private System.Windows.Forms.Label lblAmount; | |
31 private System.Windows.Forms.Button bttnCancel; | |
32 private System.Windows.Forms.Button bttnOkay; | |
33 private System.Windows.Forms.CheckBox cbEquipAll; | |
34 /// <summary> | |
35 /// Required designer variable. | |
36 /// </summary> | |
37 private System.ComponentModel.Container components = null; | |
38 | |
39 public FrmEditUnitEquipment(Unit unit, UnitEquipmentItem equipItem, CommandStack stack) | |
40 { | |
41 commandStack = stack; | |
42 this.unit = unit; | |
43 this.equipItem = equipItem; | |
44 equip = equipItem.EquipmentItem; | |
45 InitializeComponent(); | |
46 this.Text = equip.Name + " for " + unit.Name; | |
47 equipAmount = unit.GetEquipmentAmount(equip.ID); | |
48 | |
49 if (equip.IsRatioLimit) | |
50 { | |
51 numEquipAmount.Minimum = (decimal)Math.Round(equip.MinNumber * 100, 2); | |
52 numEquipAmount.Maximum = (decimal)Math.Round(equip.MaxNumber * 100, 2); | |
53 numEquipAmount.Value = (decimal)Math.Round(equipAmount * 100, 2); | |
54 cbEquipAll.Enabled = false; | |
55 lblPercent.Visible = true; | |
56 numEquipAmount.Width = 120; | |
57 } | |
58 else | |
59 { | |
60 numEquipAmount.Minimum = (decimal)(equip.MinNumber != -1 ? equip.MinNumber : unit.Size); | |
61 numEquipAmount.Maximum = (decimal)(equip.MaxNumber != -1 ? equip.MaxNumber : unit.Size); | |
62 numEquipAmount.Value = (decimal)(equipAmount == -1 ? unit.Size : equipAmount); | |
63 cbEquipAll.Checked = (equipAmount == -1); | |
64 cbEquipAll.Enabled = (equip.MaxNumber == -1 && equip.MinNumber != -1); | |
65 numEquipAmount.Enabled = !cbEquipAll.Checked && equip.MinNumber != -1; | |
66 numEquipAmount.Width = 144; | |
67 } | |
68 | |
69 bttnOkay.Enabled = false; | |
70 } | |
71 | |
72 /// <summary> | |
73 /// Clean up any resources being used. | |
74 /// </summary> | |
75 protected override void Dispose( bool disposing ) | |
76 { | |
77 if( disposing ) | |
78 { | |
79 if(components != null) | |
80 { | |
81 components.Dispose(); | |
82 } | |
83 } | |
84 base.Dispose( disposing ); | |
85 } | |
86 | |
87 #region Windows Form Designer generated code | |
88 /// <summary> | |
89 /// Required method for Designer support - do not modify | |
90 /// the contents of this method with the code editor. | |
91 /// </summary> | |
92 private void InitializeComponent() | |
93 { | |
94 this.numEquipAmount = new System.Windows.Forms.NumericUpDown(); | |
95 this.lblPercent = new System.Windows.Forms.Label(); | |
96 this.lblAmount = new System.Windows.Forms.Label(); | |
97 this.bttnCancel = new System.Windows.Forms.Button(); | |
98 this.bttnOkay = new System.Windows.Forms.Button(); | |
99 this.cbEquipAll = new System.Windows.Forms.CheckBox(); | |
100 ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).BeginInit(); | |
101 this.SuspendLayout(); | |
102 // | |
103 // numEquipAmount | |
104 // | |
105 this.numEquipAmount.Location = new System.Drawing.Point(88, 8); | |
106 this.numEquipAmount.Name = "numEquipAmount"; | |
107 this.numEquipAmount.Size = new System.Drawing.Size(144, 20); | |
108 this.numEquipAmount.TabIndex = 0; | |
109 this.numEquipAmount.ValueChanged += new System.EventHandler(this.numEquipAmount_ValueChanged); | |
110 // | |
111 // lblPercent | |
112 // | |
113 this.lblPercent.Location = new System.Drawing.Point(208, 8); | |
114 this.lblPercent.Name = "lblPercent"; | |
115 this.lblPercent.Size = new System.Drawing.Size(16, 16); | |
116 this.lblPercent.TabIndex = 1; | |
117 this.lblPercent.Text = "%"; | |
118 this.lblPercent.Visible = false; | |
119 // | |
120 // lblAmount | |
121 // | |
122 this.lblAmount.Location = new System.Drawing.Point(8, 8); | |
123 this.lblAmount.Name = "lblAmount"; | |
124 this.lblAmount.Size = new System.Drawing.Size(72, 23); | |
125 this.lblAmount.TabIndex = 2; | |
126 this.lblAmount.Text = "amount"; | |
127 this.lblAmount.TextAlign = System.Drawing.ContentAlignment.TopRight; | |
128 // | |
129 // bttnCancel | |
130 // | |
131 this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; | |
132 this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; | |
133 this.bttnCancel.Location = new System.Drawing.Point(160, 64); | |
134 this.bttnCancel.Name = "bttnCancel"; | |
135 this.bttnCancel.TabIndex = 3; | |
136 this.bttnCancel.Text = "cancel"; | |
137 this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click); | |
138 // | |
139 // bttnOkay | |
140 // | |
141 this.bttnOkay.Enabled = false; | |
142 this.bttnOkay.FlatStyle = System.Windows.Forms.FlatStyle.System; | |
143 this.bttnOkay.Location = new System.Drawing.Point(8, 64); | |
144 this.bttnOkay.Name = "bttnOkay"; | |
145 this.bttnOkay.TabIndex = 4; | |
146 this.bttnOkay.Text = "okay"; | |
147 this.bttnOkay.Click += new System.EventHandler(this.bttnOkay_Click); | |
148 // | |
149 // cbEquipAll | |
150 // | |
151 this.cbEquipAll.Enabled = false; | |
152 this.cbEquipAll.FlatStyle = System.Windows.Forms.FlatStyle.System; | |
153 this.cbEquipAll.Location = new System.Drawing.Point(88, 32); | |
154 this.cbEquipAll.Name = "cbEquipAll"; | |
155 this.cbEquipAll.TabIndex = 5; | |
156 this.cbEquipAll.Text = "equip all"; | |
157 this.cbEquipAll.CheckedChanged += new System.EventHandler(this.cbEquipAll_CheckedChanged); | |
158 // | |
159 // FrmEditUnitEquipment | |
160 // | |
161 this.AcceptButton = this.bttnOkay; | |
162 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); | |
163 this.CancelButton = this.bttnCancel; | |
164 this.ClientSize = new System.Drawing.Size(240, 92); | |
165 this.ControlBox = false; | |
166 this.Controls.Add(this.cbEquipAll); | |
167 this.Controls.Add(this.bttnOkay); | |
168 this.Controls.Add(this.bttnCancel); | |
169 this.Controls.Add(this.lblAmount); | |
170 this.Controls.Add(this.numEquipAmount); | |
171 this.Controls.Add(this.lblPercent); | |
172 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; | |
173 this.Name = "FrmEditUnitEquipment"; | |
174 this.ShowInTaskbar = false; | |
175 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; | |
176 this.Text = "FrmEditUnitEquipment"; | |
177 ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).EndInit(); | |
178 this.ResumeLayout(false); | |
179 | |
180 } | |
181 #endregion | |
182 | |
183 private void bttnOkay_Click(object sender, System.EventArgs e) | |
184 { | |
185 if (setValue()) | |
186 { | |
187 this.Close(); | |
188 } | |
189 } | |
190 | |
191 private bool setValue() | |
192 { | |
193 if ((!numEquipAmount.Enabled || numEquipAmount.Value == 0) && !cbEquipAll.Checked && unit.GetEquipmentAmount(equip.ID) != 0) | |
194 { | |
195 if (equipItem.IsRequired) | |
196 { | |
197 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); | |
198 return false; | |
199 } | |
200 else | |
201 { | |
202 DialogResult dr = MessageBox.Show(this, "This will remove the item from the unit. Continue?", "Confirm remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); | |
203 | |
204 if (dr!=DialogResult.Yes) | |
205 { | |
206 return false; | |
207 } | |
208 } | |
209 } | |
210 | |
211 if (cbEquipAll.Checked) | |
212 { | |
213 if (equipAmount!=-1) | |
214 { | |
215 commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equip, -1)); | |
216 } | |
217 } | |
218 else if (numEquipAmount.Value != (decimal)equipAmount) | |
219 { | |
220 if (equip.IsRatioLimit) | |
221 { | |
222 commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equip, (float)((double)numEquipAmount.Value / 100.0))); | |
223 } | |
224 else | |
225 { | |
226 commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equip, (float)numEquipAmount.Value)); | |
227 } | |
228 } | |
229 | |
230 return true; | |
231 } | |
232 | |
233 private void bttnCancel_Click(object sender, System.EventArgs e) | |
234 { | |
235 this.Close(); | |
236 } | |
237 | |
238 private void cbEquipAll_CheckedChanged(object sender, System.EventArgs e) | |
239 { | |
240 numEquipAmount.Enabled = !cbEquipAll.Checked && equip.MinNumber != -1; | |
241 setOkayButton(); | |
242 } | |
243 | |
244 private void setOkayButton() | |
245 { | |
246 bttnOkay.Enabled = (cbEquipAll.Checked || (numEquipAmount.Enabled && (numEquipAmount.Value > 0 || !equipItem.IsRequired))); | |
247 } | |
248 | |
249 private void numEquipAmount_ValueChanged(object sender, System.EventArgs e) | |
250 { | |
251 setOkayButton(); | |
252 } | |
253 } | |
254 } |