36
|
1 // This file (FrmNewUnit.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2007, 2008, 2009 IBBoard.
|
24
|
2 //
|
36
|
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.
|
24
|
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.Lang;
|
|
12 using IBBoard.Windows.Forms;
|
|
13 using IBBoard.WarFoundry.API;
|
|
14 using IBBoard.WarFoundry.API.Objects;
|
|
15 using IBBoard.Windows.Forms.I18N;
|
|
16
|
|
17 namespace IBBoard.WarFoundry
|
|
18 {
|
|
19 /// <summary>
|
|
20 /// Summary description for FrmNewUnit.
|
|
21 /// </summary>
|
|
22 public class FrmNewUnit : IBBForm
|
|
23 {
|
|
24 private System.ComponentModel.IContainer components;
|
|
25 private IBBoard.Windows.Forms.IBBButton bttnCancel;
|
|
26 private IBBoard.Windows.Forms.IBBLabel lblUnitList;
|
|
27 private IBBoard.Windows.Forms.IBBButton bttnSelectUnit;
|
|
28 private System.Windows.Forms.ListBox lstUnits;
|
|
29 private UnitType[] units;
|
|
30 private Army army;
|
|
31 private System.Windows.Forms.ImageList imageList;
|
|
32 private System.Windows.Forms.Label lblNewUnitWarning;
|
|
33 private System.Windows.Forms.Label lblWarningIcon;
|
|
34 private bool[] allowed;
|
|
35
|
|
36 public FrmNewUnit(Race race, Category cat, Army army)
|
|
37 {
|
|
38 InitializeComponent();
|
|
39
|
|
40 ControlTranslator.TranslateControl(this, cat.Name);
|
|
41 units = race.GetUnitTypes(cat);
|
|
42 allowed = new bool[units.Length];
|
|
43 this.army = army;
|
|
44
|
|
45 for (int i = 0; i<units.Length; i++)
|
|
46 {
|
|
47 allowed[i] = army.CanAddUnitType(units[i]).Count == 0;
|
|
48 lstUnits.Items.Add(units[i].Name);
|
|
49 }
|
|
50 }
|
|
51
|
|
52 /// <summary>
|
|
53 /// Clean up any resources being used.
|
|
54 /// </summary>
|
|
55 protected override void Dispose( bool disposing )
|
|
56 {
|
|
57 if( disposing )
|
|
58 {
|
|
59 if(components != null)
|
|
60 {
|
|
61 components.Dispose();
|
|
62 }
|
|
63 }
|
|
64 base.Dispose( disposing );
|
|
65 }
|
|
66
|
|
67 #region Windows Form Designer generated code
|
|
68 /// <summary>
|
|
69 /// Required method for Designer support - do not modify
|
|
70 /// the contents of this method with the code editor.
|
|
71 /// </summary>
|
|
72 private void InitializeComponent()
|
|
73 {
|
|
74 this.components = new System.ComponentModel.Container();
|
|
75 System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FrmNewUnit));
|
|
76 this.lstUnits = new System.Windows.Forms.ListBox();
|
|
77 this.bttnCancel = new IBBoard.Windows.Forms.IBBButton();
|
|
78 this.lblUnitList = new IBBoard.Windows.Forms.IBBLabel();
|
|
79 this.bttnSelectUnit = new IBBoard.Windows.Forms.IBBButton();
|
|
80 this.lblNewUnitWarning = new System.Windows.Forms.Label();
|
|
81 this.imageList = new System.Windows.Forms.ImageList(this.components);
|
|
82 this.lblWarningIcon = new System.Windows.Forms.Label();
|
|
83 this.SuspendLayout();
|
|
84 //
|
|
85 // lstUnits
|
|
86 //
|
|
87 this.lstUnits.Location = new System.Drawing.Point(88, 8);
|
|
88 this.lstUnits.Name = "lstUnits";
|
|
89 this.lstUnits.Size = new System.Drawing.Size(272, 121);
|
|
90 this.lstUnits.TabIndex = 7;
|
|
91 this.lstUnits.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lstUnits_MouseDown);
|
|
92 this.lstUnits.DoubleClick += new System.EventHandler(this.lstUnits_DoubleClick);
|
|
93 this.lstUnits.SelectedIndexChanged += new System.EventHandler(this.lstUnits_SelectedIndexChanged);
|
|
94 //
|
|
95 // bttnCancel
|
|
96 //
|
|
97 this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
|
98 this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
|
|
99 this.bttnCancel.Location = new System.Drawing.Point(8, 168);
|
|
100 this.bttnCancel.Name = "bttnCancel";
|
|
101 this.bttnCancel.Size = new System.Drawing.Size(80, 24);
|
|
102 this.bttnCancel.TabIndex = 6;
|
|
103 this.bttnCancel.Text = "Cancel";
|
|
104 this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click);
|
|
105 //
|
|
106 // lblUnitList
|
|
107 //
|
|
108 this.lblUnitList.Location = new System.Drawing.Point(0, 8);
|
|
109 this.lblUnitList.Name = "lblUnitList";
|
|
110 this.lblUnitList.Size = new System.Drawing.Size(88, 80);
|
|
111 this.lblUnitList.TabIndex = 5;
|
|
112 this.lblUnitList.Text = "unit list";
|
|
113 this.lblUnitList.TextAlign = System.Drawing.ContentAlignment.TopRight;
|
|
114 //
|
|
115 // bttnSelectUnit
|
|
116 //
|
|
117 this.bttnSelectUnit.Enabled = false;
|
|
118 this.bttnSelectUnit.FlatStyle = System.Windows.Forms.FlatStyle.System;
|
|
119 this.bttnSelectUnit.Location = new System.Drawing.Point(256, 168);
|
|
120 this.bttnSelectUnit.Name = "bttnSelectUnit";
|
|
121 this.bttnSelectUnit.Size = new System.Drawing.Size(104, 24);
|
|
122 this.bttnSelectUnit.TabIndex = 4;
|
|
123 this.bttnSelectUnit.Text = "create unit";
|
|
124 this.bttnSelectUnit.Click += new System.EventHandler(this.bttnSelectUnit_Click);
|
|
125 //
|
|
126 // lblNewUnitWarning
|
|
127 //
|
|
128 this.lblNewUnitWarning.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
|
|
129 this.lblNewUnitWarning.ImageList = this.imageList;
|
|
130 this.lblNewUnitWarning.Location = new System.Drawing.Point(48, 136);
|
|
131 this.lblNewUnitWarning.Name = "lblNewUnitWarning";
|
|
132 this.lblNewUnitWarning.Size = new System.Drawing.Size(312, 32);
|
|
133 this.lblNewUnitWarning.TabIndex = 9;
|
|
134 this.lblNewUnitWarning.Text = "label1";
|
|
135 this.lblNewUnitWarning.TextAlign = System.Drawing.ContentAlignment.TopRight;
|
|
136 this.lblNewUnitWarning.Visible = false;
|
|
137 //
|
|
138 // imageList
|
|
139 //
|
|
140 this.imageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
|
|
141 this.imageList.ImageSize = new System.Drawing.Size(32, 32);
|
|
142 this.imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList.ImageStream")));
|
|
143 this.imageList.TransparentColor = System.Drawing.Color.Transparent;
|
|
144 //
|
|
145 // lblWarningIcon
|
|
146 //
|
|
147 this.lblWarningIcon.ImageIndex = 0;
|
|
148 this.lblWarningIcon.ImageList = this.imageList;
|
|
149 this.lblWarningIcon.Location = new System.Drawing.Point(8, 136);
|
|
150 this.lblWarningIcon.Name = "lblWarningIcon";
|
|
151 this.lblWarningIcon.Size = new System.Drawing.Size(40, 32);
|
|
152 this.lblWarningIcon.TabIndex = 10;
|
|
153 this.lblWarningIcon.Visible = false;
|
|
154 //
|
|
155 // FrmNewUnit
|
|
156 //
|
|
157 this.AcceptButton = this.bttnSelectUnit;
|
|
158 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
|
|
159 this.CancelButton = this.bttnCancel;
|
|
160 this.ClientSize = new System.Drawing.Size(370, 196);
|
|
161 this.Controls.Add(this.lblWarningIcon);
|
|
162 this.Controls.Add(this.lblNewUnitWarning);
|
|
163 this.Controls.Add(this.bttnCancel);
|
|
164 this.Controls.Add(this.lblUnitList);
|
|
165 this.Controls.Add(this.bttnSelectUnit);
|
|
166 this.Controls.Add(this.lstUnits);
|
|
167 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
|
168 this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
|
169 this.MaximizeBox = false;
|
|
170 this.MinimizeBox = false;
|
|
171 this.Name = "FrmNewUnit";
|
|
172 this.ShowInTaskbar = false;
|
|
173 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
|
174 this.Text = "FrmNewUni";
|
|
175 this.ResumeLayout(false);
|
|
176
|
|
177 }
|
|
178 #endregion
|
|
179
|
|
180 public UnitType SelectedUnit
|
|
181 {
|
|
182 get { return units[lstUnits.SelectedIndex]; }
|
|
183 }
|
|
184
|
|
185 private void bttnCancel_Click(object sender, System.EventArgs e)
|
|
186 {
|
|
187 DialogResult = DialogResult.Cancel;
|
|
188 this.Close();
|
|
189 }
|
|
190
|
|
191 private void bttnSelectUnit_Click(object sender, System.EventArgs e)
|
|
192 {
|
|
193 selectUnit();
|
|
194 }
|
|
195
|
|
196 private void selectUnit()
|
|
197 {
|
|
198 DialogResult = DialogResult.OK;
|
|
199 this.Close();
|
|
200 }
|
|
201
|
|
202 private void setSelectUnitEnabledVal()
|
|
203 {
|
|
204 if (lstUnits.SelectedIndex>-1)
|
|
205 {
|
|
206 bttnSelectUnit.Enabled = true;
|
|
207 lblNewUnitWarning.Visible = !allowed[lstUnits.SelectedIndex];
|
|
208 lblWarningIcon.Visible = lblNewUnitWarning.Visible;
|
|
209
|
|
210 if (lblNewUnitWarning.Visible)
|
|
211 {
|
|
212 //lblNewUnitWarning.Text = army.GetFailedAddRequirement(units[lstUnits.SelectedIndex]).Description;
|
|
213 //FIXME: Add failed requirement text
|
|
214 }
|
|
215 }
|
|
216 else
|
|
217 {
|
|
218 bttnSelectUnit.Enabled = false;
|
|
219 }
|
|
220 }
|
|
221
|
|
222 private void lstUnits_SelectedIndexChanged(object sender, System.EventArgs e)
|
|
223 {
|
|
224 setSelectUnitEnabledVal();
|
|
225 }
|
|
226
|
|
227 private void lstUnits_DoubleClick(object sender, EventArgs e)
|
|
228 {
|
|
229 if (lstUnits.SelectedIndex>-1)
|
|
230 {
|
|
231 selectUnit();
|
|
232 }
|
|
233 }
|
|
234
|
|
235 private void lstUnits_MouseDown(object sender, MouseEventArgs e)
|
|
236 {
|
|
237 //make sure no item is selected when a click is made outside a unit
|
|
238 int index = lstUnits.IndexFromPoint(e.X, e.Y);
|
|
239 lstUnits.SelectedIndex = index;
|
|
240 }
|
|
241 }
|
|
242 }
|