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