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