24
|
1 // This file (FrmNewUnitEquipment.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 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.
|
|
4
|
|
5 using System;
|
|
6 using System.Drawing;
|
|
7 using System.Collections;
|
|
8 using System.ComponentModel;
|
|
9 using System.Windows.Forms;
|
|
10 using IBBoard;
|
|
11 using IBBoard.Commands;
|
|
12 using IBBoard.WarFoundry.API;
|
|
13 using IBBoard.WarFoundry.API.Commands;
|
|
14 using IBBoard.WarFoundry.API.Objects;
|
|
15
|
|
16 namespace IBBoard.WarFoundry
|
|
17 {
|
|
18 /// <summary>
|
|
19 /// Summary description for FrmNewUnitEquipment.
|
|
20 /// </summary>
|
|
21 public class FrmNewUnitEquipment : System.Windows.Forms.Form
|
|
22 {
|
|
23 private Unit unit;
|
|
24 private bool required;
|
|
25 private CommandStack commandStack;
|
|
26
|
|
27 private System.Windows.Forms.NumericUpDown numEquipAmount;
|
|
28 private System.Windows.Forms.Label lblPercent;
|
|
29 private System.Windows.Forms.Label lblAmount;
|
|
30 private System.Windows.Forms.Button bttnCancel;
|
|
31 private System.Windows.Forms.Button bttnOkay;
|
|
32 private System.Windows.Forms.CheckBox cbEquipAll;
|
|
33 private System.Windows.Forms.Label lblItem;
|
|
34 private System.Windows.Forms.ListBox listItems;
|
|
35 /// <summary>
|
|
36 /// Required designer variable.
|
|
37 /// </summary>
|
|
38 private System.ComponentModel.Container components = null;
|
|
39
|
|
40 public FrmNewUnitEquipment(Unit unit, CommandStack stack)
|
|
41 {
|
|
42 commandStack = stack;
|
|
43 this.unit = unit;
|
|
44 InitializeComponent();
|
|
45 this.Text = "New equipment for " + unit.Name;
|
|
46 object[] items = Arrays.Subtract(unit.GetAllowedOptionalEquipment(), unit.GetEquipment());
|
|
47 listItems.Items.AddRange(items);
|
|
48 }
|
|
49
|
|
50 /// <summary>
|
|
51 /// Clean up any resources being used.
|
|
52 /// </summary>
|
|
53 protected override void Dispose( bool disposing )
|
|
54 {
|
|
55 if( disposing )
|
|
56 {
|
|
57 if(components != null)
|
|
58 {
|
|
59 components.Dispose();
|
|
60 }
|
|
61 }
|
|
62 base.Dispose( disposing );
|
|
63 }
|
|
64
|
|
65 #region Windows Form Designer generated code
|
|
66 /// <summary>
|
|
67 /// Required method for Designer support - do not modify
|
|
68 /// the contents of this method with the code editor.
|
|
69 /// </summary>
|
|
70 private void InitializeComponent()
|
|
71 {
|
|
72 this.numEquipAmount = new System.Windows.Forms.NumericUpDown();
|
|
73 this.lblPercent = new System.Windows.Forms.Label();
|
|
74 this.lblAmount = new System.Windows.Forms.Label();
|
|
75 this.bttnCancel = new System.Windows.Forms.Button();
|
|
76 this.bttnOkay = new System.Windows.Forms.Button();
|
|
77 this.cbEquipAll = new System.Windows.Forms.CheckBox();
|
|
78 this.lblItem = new System.Windows.Forms.Label();
|
|
79 this.listItems = new System.Windows.Forms.ListBox();
|
|
80 ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).BeginInit();
|
|
81 this.SuspendLayout();
|
|
82 //
|
|
83 // numEquipAmount
|
|
84 //
|
|
85 this.numEquipAmount.Enabled = false;
|
|
86 this.numEquipAmount.Location = new System.Drawing.Point(88, 80);
|
|
87 this.numEquipAmount.Name = "numEquipAmount";
|
|
88 this.numEquipAmount.Size = new System.Drawing.Size(144, 20);
|
|
89 this.numEquipAmount.TabIndex = 0;
|
|
90 this.numEquipAmount.ValueChanged += new System.EventHandler(this.numEquipAmount_ValueChanged);
|
|
91 //
|
|
92 // lblPercent
|
|
93 //
|
|
94 this.lblPercent.Location = new System.Drawing.Point(208, 80);
|
|
95 this.lblPercent.Name = "lblPercent";
|
|
96 this.lblPercent.Size = new System.Drawing.Size(16, 16);
|
|
97 this.lblPercent.TabIndex = 1;
|
|
98 this.lblPercent.Text = "%";
|
|
99 this.lblPercent.Visible = false;
|
|
100 //
|
|
101 // lblAmount
|
|
102 //
|
|
103 this.lblAmount.Location = new System.Drawing.Point(8, 80);
|
|
104 this.lblAmount.Name = "lblAmount";
|
|
105 this.lblAmount.Size = new System.Drawing.Size(72, 23);
|
|
106 this.lblAmount.TabIndex = 2;
|
|
107 this.lblAmount.Text = "amount";
|
|
108 this.lblAmount.TextAlign = System.Drawing.ContentAlignment.TopRight;
|
|
109 //
|
|
110 // bttnCancel
|
|
111 //
|
|
112 this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
|
113 this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
|
|
114 this.bttnCancel.Location = new System.Drawing.Point(160, 136);
|
|
115 this.bttnCancel.Name = "bttnCancel";
|
|
116 this.bttnCancel.TabIndex = 3;
|
|
117 this.bttnCancel.Text = "cancel";
|
|
118 this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click);
|
|
119 //
|
|
120 // bttnOkay
|
|
121 //
|
|
122 this.bttnOkay.Enabled = false;
|
|
123 this.bttnOkay.FlatStyle = System.Windows.Forms.FlatStyle.System;
|
|
124 this.bttnOkay.Location = new System.Drawing.Point(8, 136);
|
|
125 this.bttnOkay.Name = "bttnOkay";
|
|
126 this.bttnOkay.TabIndex = 4;
|
|
127 this.bttnOkay.Text = "okay";
|
|
128 this.bttnOkay.Click += new System.EventHandler(this.bttnOkay_Click);
|
|
129 //
|
|
130 // cbEquipAll
|
|
131 //
|
|
132 this.cbEquipAll.Enabled = false;
|
|
133 this.cbEquipAll.FlatStyle = System.Windows.Forms.FlatStyle.System;
|
|
134 this.cbEquipAll.Location = new System.Drawing.Point(88, 104);
|
|
135 this.cbEquipAll.Name = "cbEquipAll";
|
|
136 this.cbEquipAll.TabIndex = 5;
|
|
137 this.cbEquipAll.Text = "equip all";
|
|
138 this.cbEquipAll.CheckedChanged += new System.EventHandler(this.cbEquipAll_CheckedChanged);
|
|
139 //
|
|
140 // lblItem
|
|
141 //
|
|
142 this.lblItem.Location = new System.Drawing.Point(0, 8);
|
|
143 this.lblItem.Name = "lblItem";
|
|
144 this.lblItem.Size = new System.Drawing.Size(80, 23);
|
|
145 this.lblItem.TabIndex = 6;
|
|
146 this.lblItem.Text = "item";
|
|
147 this.lblItem.TextAlign = System.Drawing.ContentAlignment.TopRight;
|
|
148 //
|
|
149 // listItems
|
|
150 //
|
|
151 this.listItems.Location = new System.Drawing.Point(88, 8);
|
|
152 this.listItems.Name = "listItems";
|
|
153 this.listItems.Size = new System.Drawing.Size(144, 69);
|
|
154 this.listItems.TabIndex = 7;
|
|
155 this.listItems.SelectedIndexChanged += new System.EventHandler(this.listItems_SelectedIndexChanged);
|
|
156 //
|
|
157 // FrmNewUnitEquipment
|
|
158 //
|
|
159 this.AcceptButton = this.bttnOkay;
|
|
160 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
|
|
161 this.CancelButton = this.bttnCancel;
|
|
162 this.ClientSize = new System.Drawing.Size(240, 164);
|
|
163 this.ControlBox = false;
|
|
164 this.Controls.Add(this.listItems);
|
|
165 this.Controls.Add(this.lblItem);
|
|
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 = "FrmNewUnitEquipment";
|
|
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 setValue();
|
|
186 this.Close();
|
|
187 }
|
|
188
|
|
189 private void setValue()
|
|
190 {
|
|
191 UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem;
|
|
192
|
|
193 if (cbEquipAll.Checked)
|
|
194 {
|
|
195 commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, WarFoundryCore.INFINITY));
|
|
196 }
|
|
197 else
|
|
198 {
|
|
199 if (equipItem.IsRatioLimit)
|
|
200 {
|
|
201 commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, (double)numEquipAmount.Value / 100.0));
|
|
202 }
|
|
203 else
|
|
204 {
|
|
205 commandStack.Execute(new SetUnitEquipmentAmountCommand(unit, equipItem, (double)numEquipAmount.Value));
|
|
206 }
|
|
207 }
|
|
208 }
|
|
209
|
|
210 private void bttnCancel_Click(object sender, System.EventArgs e)
|
|
211 {
|
|
212 this.Close();
|
|
213 }
|
|
214
|
|
215 private void cbEquipAll_CheckedChanged(object sender, System.EventArgs e)
|
|
216 {
|
|
217 numEquipAmount.Enabled = ((UnitEquipmentItem)listItems.SelectedItem).MinNumber != WarFoundryCore.INFINITY && !cbEquipAll.Checked;
|
|
218 setOkayButton();
|
|
219 }
|
|
220
|
|
221 private void listItems_SelectedIndexChanged(object sender, System.EventArgs e)
|
|
222 {
|
|
223 refreshNumber();
|
|
224 setOkayButton();
|
|
225 }
|
|
226
|
|
227 private void refreshNumber()
|
|
228 {
|
|
229 if (listItems.SelectedIndex > -1)
|
|
230 {
|
|
231 UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem;
|
|
232 required = equipItem.IsRequired;
|
|
233
|
|
234 if (equipItem.IsRatioLimit)
|
|
235 {
|
|
236 numEquipAmount.Minimum = (decimal)Math.Round(equipItem.MinNumber * 100.0, 2);
|
|
237 numEquipAmount.Maximum = (decimal)Math.Round(equipItem.MaxNumber * 100.0, 2);
|
|
238 numEquipAmount.Value = numEquipAmount.Minimum;
|
|
239 cbEquipAll.Enabled = false;
|
|
240 lblPercent.Visible = true;
|
|
241 numEquipAmount.Width = 120;
|
|
242 }
|
|
243 else
|
|
244 {
|
|
245 numEquipAmount.Minimum = (decimal)(equipItem.MinNumber != WarFoundryCore.INFINITY ? equipItem.MinNumber : unit.Size);
|
|
246 numEquipAmount.Maximum = (decimal)(equipItem.MaxNumber != WarFoundryCore.INFINITY ? equipItem.MaxNumber : unit.Size);
|
|
247 numEquipAmount.Value = numEquipAmount.Minimum;
|
|
248 cbEquipAll.Enabled = equipItem.MinNumber != WarFoundryCore.INFINITY;
|
|
249 cbEquipAll.Checked = equipItem.MinNumber == WarFoundryCore.INFINITY;
|
|
250 numEquipAmount.Width = 144;
|
|
251 }
|
|
252 }
|
|
253 else
|
|
254 {
|
|
255 numEquipAmount.Minimum = 0;
|
|
256 numEquipAmount.Value = 0;
|
|
257 numEquipAmount.Enabled = false;
|
|
258 cbEquipAll.Enabled = false;
|
|
259 }
|
|
260 }
|
|
261
|
|
262 private void setOkayButton()
|
|
263 {
|
|
264 bttnOkay.Enabled = listItems.SelectedIndex > -1 && (cbEquipAll.Checked || (numEquipAmount.Enabled && numEquipAmount.Value > 0));
|
|
265 }
|
|
266
|
|
267 private void numEquipAmount_ValueChanged(object sender, System.EventArgs e)
|
|
268 {
|
|
269 setOkayButton();
|
|
270 }
|
|
271 }
|
|
272 }
|