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