comparison FrmNewArmy.cs @ 54:d6ff354a5d84

Re #166: Move game system changing to part of army creation * Initial commit - code works but naming isn't correct * Remove system selection dialog * Add game system selection to FrmNewArmy * Populate race list based on game system selected * Always enable "New Army" button/menu item
author IBBoard <dev@ibboard.co.uk>
date Sat, 19 Sep 2009 10:27:01 +0000
parents 1576f669b3eb
children 11e81ba85684
comparison
equal deleted inserted replaced
53:e6d0d9eababf 54:d6ff354a5d84
11 using IBBoard.Windows.Forms; 11 using IBBoard.Windows.Forms;
12 using IBBoard.WarFoundry.API; 12 using IBBoard.WarFoundry.API;
13 using IBBoard.WarFoundry.API.Objects; 13 using IBBoard.WarFoundry.API.Objects;
14 using IBBoard.Windows.Forms.I18N; 14 using IBBoard.Windows.Forms.I18N;
15 15
16 namespace IBBoard.WarFoundry 16 namespace IBBoard.WarFoundry.GUI.WinForms
17 { 17 {
18 /// <summary> 18 /// <summary>
19 /// Summary description for FrmNewArmy. 19 /// Summary description for FrmNewArmy.
20 /// </summary> 20 /// </summary>
21 public class FrmNewArmy : IBBForm 21 public class FrmNewArmy : IBBForm
26 private System.ComponentModel.Container components = null; 26 private System.ComponentModel.Container components = null;
27 private IBBoard.Windows.Forms.IBBButton bttnCancel; 27 private IBBoard.Windows.Forms.IBBButton bttnCancel;
28 private IBBoard.Windows.Forms.IBBLabel lblRaceList; 28 private IBBoard.Windows.Forms.IBBLabel lblRaceList;
29 private IBBoard.Windows.Forms.IBBButton bttnSelectRace; 29 private IBBoard.Windows.Forms.IBBButton bttnSelectRace;
30 private System.Windows.Forms.ListBox lstRaces; 30 private System.Windows.Forms.ListBox lstRaces;
31 private Race[] races;
32 private IBBoard.Windows.Forms.IBBLabel lblArmyName; 31 private IBBoard.Windows.Forms.IBBLabel lblArmyName;
33 private IBBoard.Windows.Forms.IBBLabel lblArmySize; 32 private IBBoard.Windows.Forms.IBBLabel lblArmySize;
34 private System.Windows.Forms.NumericUpDown armySize; 33 private System.Windows.Forms.NumericUpDown armySize;
34 private Label lblGameSystem;
35 private ComboBox gameSystems;
35 private System.Windows.Forms.TextBox txtArmyName; 36 private System.Windows.Forms.TextBox txtArmyName;
36 37
38 private GameSystem system;
39 private Race race;
40 private string armyName;
41 private int maxPoints;
42
37 public FrmNewArmy(GameSystem system) 43 public FrmNewArmy(GameSystem system)
38 { 44 {
39 InitializeComponent(); 45 InitializeComponent();
40 46
41 ControlTranslator.TranslateControl(this); 47 ControlTranslator.TranslateControl(this);
42 48
43 races = WarFoundryLoader.GetDefault().GetRaces(system); 49 foreach (GameSystem gameSystem in WarFoundryLoader.GetDefault().GetGameSystems())
44 50 {
45 for (int i = 0; i<races.Length; i++) 51 gameSystems.Items.Add(gameSystem);
46 { 52 }
47 lstRaces.Items.Add(races[i].Name); 53
54 if (WarFoundryCore.CurrentGameSystem != null)
55 {
56 gameSystems.SelectedItem = FrmMain.CurrentGameSystem;
57 }
58 }
59
60 private void SetRaces(GameSystem system)
61 {
62 foreach (Race race in WarFoundryLoader.GetDefault().GetRaces(system))
63 {
64 lstRaces.Items.Add(race);
48 } 65 }
49 } 66 }
50 67
51 /// <summary> 68 /// <summary>
52 /// Clean up any resources being used. 69 /// Clean up any resources being used.
68 /// Required method for Designer support - do not modify 85 /// Required method for Designer support - do not modify
69 /// the contents of this method with the code editor. 86 /// the contents of this method with the code editor.
70 /// </summary> 87 /// </summary>
71 private void InitializeComponent() 88 private void InitializeComponent()
72 { 89 {
73 System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FrmNewArmy)); 90 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmNewArmy));
74 this.lstRaces = new System.Windows.Forms.ListBox(); 91 this.lstRaces = new System.Windows.Forms.ListBox();
75 this.bttnCancel = new IBBoard.Windows.Forms.IBBButton(); 92 this.bttnCancel = new IBBoard.Windows.Forms.IBBButton();
76 this.lblRaceList = new IBBoard.Windows.Forms.IBBLabel(); 93 this.lblRaceList = new IBBoard.Windows.Forms.IBBLabel();
77 this.bttnSelectRace = new IBBoard.Windows.Forms.IBBButton(); 94 this.bttnSelectRace = new IBBoard.Windows.Forms.IBBButton();
78 this.lblArmyName = new IBBoard.Windows.Forms.IBBLabel(); 95 this.lblArmyName = new IBBoard.Windows.Forms.IBBLabel();
79 this.txtArmyName = new System.Windows.Forms.TextBox(); 96 this.txtArmyName = new System.Windows.Forms.TextBox();
80 this.lblArmySize = new IBBoard.Windows.Forms.IBBLabel(); 97 this.lblArmySize = new IBBoard.Windows.Forms.IBBLabel();
81 this.armySize = new System.Windows.Forms.NumericUpDown(); 98 this.armySize = new System.Windows.Forms.NumericUpDown();
82 ((System.ComponentModel.ISupportInitialize)(this.armySize)).BeginInit(); 99 this.lblGameSystem = new System.Windows.Forms.Label();
100 this.gameSystems = new System.Windows.Forms.ComboBox();
101 ((System.ComponentModel.ISupportInitialize) (this.armySize)).BeginInit();
83 this.SuspendLayout(); 102 this.SuspendLayout();
84 // 103 //
85 // lstRaces 104 // lstRaces
86 // 105 //
87 this.lstRaces.Location = new System.Drawing.Point(88, 8); 106 this.lstRaces.Location = new System.Drawing.Point(89, 33);
88 this.lstRaces.Name = "lstRaces"; 107 this.lstRaces.Name = "lstRaces";
89 this.lstRaces.Size = new System.Drawing.Size(272, 121); 108 this.lstRaces.Size = new System.Drawing.Size(269, 121);
90 this.lstRaces.TabIndex = 7; 109 this.lstRaces.TabIndex = 7;
91 this.lstRaces.SelectedIndexChanged += new System.EventHandler(this.lstRaces_SelectedIndexChanged); 110 this.lstRaces.SelectedIndexChanged += new System.EventHandler(this.lstRaces_SelectedIndexChanged);
92 // 111 //
93 // bttnCancel 112 // bttnCancel
94 // 113 //
95 this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; 114 this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
96 this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; 115 this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
97 this.bttnCancel.Location = new System.Drawing.Point(8, 200); 116 this.bttnCancel.Location = new System.Drawing.Point(12, 231);
98 this.bttnCancel.Name = "bttnCancel"; 117 this.bttnCancel.Name = "bttnCancel";
99 this.bttnCancel.Size = new System.Drawing.Size(80, 24); 118 this.bttnCancel.Size = new System.Drawing.Size(80, 24);
100 this.bttnCancel.TabIndex = 6; 119 this.bttnCancel.TabIndex = 6;
101 this.bttnCancel.Text = "Cancel"; 120 this.bttnCancel.Text = "Cancel";
102 this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click); 121 this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click);
103 // 122 //
104 // lblRaceList 123 // lblRaceList
105 // 124 //
106 this.lblRaceList.Location = new System.Drawing.Point(0, 8); 125 this.lblRaceList.Location = new System.Drawing.Point(12, 33);
107 this.lblRaceList.Name = "lblRaceList"; 126 this.lblRaceList.Name = "lblRaceList";
108 this.lblRaceList.Size = new System.Drawing.Size(88, 80); 127 this.lblRaceList.Size = new System.Drawing.Size(71, 80);
109 this.lblRaceList.TabIndex = 5; 128 this.lblRaceList.TabIndex = 5;
110 this.lblRaceList.Text = "race list"; 129 this.lblRaceList.Text = "race list";
111 this.lblRaceList.TextAlign = System.Drawing.ContentAlignment.TopRight; 130 this.lblRaceList.TextAlign = System.Drawing.ContentAlignment.TopRight;
112 // 131 //
113 // bttnSelectRace 132 // bttnSelectRace
114 // 133 //
115 this.bttnSelectRace.Enabled = false; 134 this.bttnSelectRace.Enabled = false;
116 this.bttnSelectRace.FlatStyle = System.Windows.Forms.FlatStyle.System; 135 this.bttnSelectRace.FlatStyle = System.Windows.Forms.FlatStyle.System;
117 this.bttnSelectRace.Location = new System.Drawing.Point(256, 200); 136 this.bttnSelectRace.Location = new System.Drawing.Point(254, 231);
118 this.bttnSelectRace.Name = "bttnSelectRace"; 137 this.bttnSelectRace.Name = "bttnSelectRace";
119 this.bttnSelectRace.Size = new System.Drawing.Size(104, 24); 138 this.bttnSelectRace.Size = new System.Drawing.Size(104, 24);
120 this.bttnSelectRace.TabIndex = 4; 139 this.bttnSelectRace.TabIndex = 4;
121 this.bttnSelectRace.Text = "create race"; 140 this.bttnSelectRace.Text = "create race";
122 this.bttnSelectRace.Click += new System.EventHandler(this.bttnSelectRace_Click); 141 this.bttnSelectRace.Click += new System.EventHandler(this.bttnSelectRace_Click);
123 // 142 //
124 // lblArmyName 143 // lblArmyName
125 // 144 //
126 this.lblArmyName.Location = new System.Drawing.Point(0, 136); 145 this.lblArmyName.Location = new System.Drawing.Point(12, 163);
127 this.lblArmyName.Name = "lblArmyName"; 146 this.lblArmyName.Name = "lblArmyName";
128 this.lblArmyName.Size = new System.Drawing.Size(88, 32); 147 this.lblArmyName.Size = new System.Drawing.Size(71, 17);
129 this.lblArmyName.TabIndex = 8; 148 this.lblArmyName.TabIndex = 8;
130 this.lblArmyName.Text = "army name"; 149 this.lblArmyName.Text = "army name";
131 this.lblArmyName.TextAlign = System.Drawing.ContentAlignment.TopRight; 150 this.lblArmyName.TextAlign = System.Drawing.ContentAlignment.TopRight;
132 // 151 //
133 // txtArmyName 152 // txtArmyName
134 // 153 //
135 this.txtArmyName.Location = new System.Drawing.Point(88, 136); 154 this.txtArmyName.Location = new System.Drawing.Point(89, 160);
136 this.txtArmyName.Name = "txtArmyName"; 155 this.txtArmyName.Name = "txtArmyName";
137 this.txtArmyName.Size = new System.Drawing.Size(272, 20); 156 this.txtArmyName.Size = new System.Drawing.Size(269, 20);
138 this.txtArmyName.TabIndex = 9; 157 this.txtArmyName.TabIndex = 9;
139 this.txtArmyName.Text = "";
140 this.txtArmyName.TextChanged += new System.EventHandler(this.txtArmyName_TextChanged); 158 this.txtArmyName.TextChanged += new System.EventHandler(this.txtArmyName_TextChanged);
141 // 159 //
142 // lblArmySize 160 // lblArmySize
143 // 161 //
144 this.lblArmySize.Location = new System.Drawing.Point(0, 168); 162 this.lblArmySize.Location = new System.Drawing.Point(12, 188);
145 this.lblArmySize.Name = "lblArmySize"; 163 this.lblArmySize.Name = "lblArmySize";
146 this.lblArmySize.Size = new System.Drawing.Size(88, 32); 164 this.lblArmySize.Size = new System.Drawing.Size(71, 18);
147 this.lblArmySize.TabIndex = 10; 165 this.lblArmySize.TabIndex = 10;
148 this.lblArmySize.Text = "army size"; 166 this.lblArmySize.Text = "army size";
149 this.lblArmySize.TextAlign = System.Drawing.ContentAlignment.TopRight; 167 this.lblArmySize.TextAlign = System.Drawing.ContentAlignment.TopRight;
150 // 168 //
151 // armySize 169 // armySize
152 // 170 //
153 this.armySize.Increment = new System.Decimal(new int[] { 171 this.armySize.Increment = new decimal(new int[] {
154 50, 172 50,
155 0, 173 0,
156 0, 174 0,
157 0}); 175 0});
158 this.armySize.Location = new System.Drawing.Point(88, 168); 176 this.armySize.Location = new System.Drawing.Point(89, 186);
159 this.armySize.Maximum = new System.Decimal(new int[] { 177 this.armySize.Maximum = new decimal(new int[] {
160 1000000, 178 1000000,
161 0, 179 0,
162 0, 180 0,
163 0}); 181 0});
164 this.armySize.Name = "armySize"; 182 this.armySize.Name = "armySize";
183 this.armySize.Size = new System.Drawing.Size(120, 20);
165 this.armySize.TabIndex = 11; 184 this.armySize.TabIndex = 11;
166 this.armySize.ThousandsSeparator = true; 185 this.armySize.ThousandsSeparator = true;
167 this.armySize.Value = new System.Decimal(new int[] { 186 this.armySize.Value = new decimal(new int[] {
168 2000, 187 2000,
169 0, 188 0,
170 0, 189 0,
171 0}); 190 0});
191 //
192 // lblGameSystem
193 //
194 this.lblGameSystem.Location = new System.Drawing.Point(12, 9);
195 this.lblGameSystem.Name = "lblGameSystem";
196 this.lblGameSystem.Size = new System.Drawing.Size(71, 18);
197 this.lblGameSystem.TabIndex = 12;
198 this.lblGameSystem.Text = "game system";
199 this.lblGameSystem.TextAlign = System.Drawing.ContentAlignment.TopRight;
200 //
201 // gameSystems
202 //
203 this.gameSystems.FormattingEnabled = true;
204 this.gameSystems.Location = new System.Drawing.Point(89, 6);
205 this.gameSystems.Name = "gameSystems";
206 this.gameSystems.Size = new System.Drawing.Size(269, 21);
207 this.gameSystems.TabIndex = 13;
208 this.gameSystems.SelectedValueChanged += new System.EventHandler(this.gameSystems_SelectedValueChanged);
172 // 209 //
173 // FrmNewArmy 210 // FrmNewArmy
174 // 211 //
175 this.AcceptButton = this.bttnSelectRace; 212 this.AcceptButton = this.bttnSelectRace;
176 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); 213 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
177 this.CancelButton = this.bttnCancel; 214 this.CancelButton = this.bttnCancel;
178 this.ClientSize = new System.Drawing.Size(370, 228); 215 this.ClientSize = new System.Drawing.Size(370, 267);
216 this.Controls.Add(this.gameSystems);
217 this.Controls.Add(this.lblGameSystem);
179 this.Controls.Add(this.armySize); 218 this.Controls.Add(this.armySize);
180 this.Controls.Add(this.lblArmySize); 219 this.Controls.Add(this.lblArmySize);
181 this.Controls.Add(this.txtArmyName); 220 this.Controls.Add(this.txtArmyName);
182 this.Controls.Add(this.lblArmyName); 221 this.Controls.Add(this.lblArmyName);
183 this.Controls.Add(this.bttnCancel); 222 this.Controls.Add(this.bttnCancel);
184 this.Controls.Add(this.lblRaceList); 223 this.Controls.Add(this.lblRaceList);
185 this.Controls.Add(this.bttnSelectRace); 224 this.Controls.Add(this.bttnSelectRace);
186 this.Controls.Add(this.lstRaces); 225 this.Controls.Add(this.lstRaces);
187 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; 226 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
188 this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); 227 this.Icon = ((System.Drawing.Icon) (resources.GetObject("$this.Icon")));
189 this.MaximizeBox = false; 228 this.MaximizeBox = false;
190 this.MinimizeBox = false; 229 this.MinimizeBox = false;
191 this.Name = "FrmNewArmy"; 230 this.Name = "FrmNewArmy";
192 this.ShowInTaskbar = false; 231 this.ShowInTaskbar = false;
193 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; 232 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
194 this.Text = "FrmNewArmy"; 233 this.Text = "FrmNewArmy";
195 ((System.ComponentModel.ISupportInitialize)(this.armySize)).EndInit(); 234 ((System.ComponentModel.ISupportInitialize) (this.armySize)).EndInit();
196 this.ResumeLayout(false); 235 this.ResumeLayout(false);
236 this.PerformLayout();
197 237
198 } 238 }
199 #endregion 239 #endregion
200 240
241 public GameSystem SelectedSystem
242 {
243 get { return system; }
244 }
245
201 public Race SelectedRace 246 public Race SelectedRace
202 { 247 {
203 get { return races[lstRaces.SelectedIndex]; } 248 get { return race; }
204 } 249 }
205 250
206 public string ArmyName 251 public string ArmyName
207 { 252 {
208 get { return txtArmyName.Text; } 253 get { return armyName; }
209 } 254 }
210 255
211 public int ArmySize 256 public int ArmySize
212 { 257 {
213 get { return (int)armySize.Value; } 258 get { return maxPoints; }
214 } 259 }
215 260
216 private void bttnCancel_Click(object sender, System.EventArgs e) 261 private void bttnCancel_Click(object sender, System.EventArgs e)
217 { 262 {
218 DialogResult = DialogResult.Cancel; 263 DialogResult = DialogResult.Cancel;
220 } 265 }
221 266
222 private void bttnSelectRace_Click(object sender, System.EventArgs e) 267 private void bttnSelectRace_Click(object sender, System.EventArgs e)
223 { 268 {
224 DialogResult = DialogResult.OK; 269 DialogResult = DialogResult.OK;
270 SetValues();
225 this.Close(); 271 this.Close();
226 } 272 }
227 273
274 private void SetValues()
275 {
276 system = GetSelectedGameSystem();
277 race = (Race) lstRaces.SelectedItem;
278 armyName = txtArmyName.Text;
279 maxPoints = (int) armySize.Value;
280 }
281
282 private GameSystem GetSelectedGameSystem()
283 {
284 return (GameSystem) gameSystems.SelectedItem;
285 }
286
228 private void txtArmyName_TextChanged(object sender, System.EventArgs e) 287 private void txtArmyName_TextChanged(object sender, System.EventArgs e)
229 { 288 {
230 setSelectRaceEnabledVal(); 289 setSelectRaceEnabledVal();
231 } 290 }
232 291
236 } 295 }
237 296
238 private void lstRaces_SelectedIndexChanged(object sender, System.EventArgs e) 297 private void lstRaces_SelectedIndexChanged(object sender, System.EventArgs e)
239 { 298 {
240 setSelectRaceEnabledVal(); 299 setSelectRaceEnabledVal();
300 }
301
302 private void gameSystems_SelectedValueChanged(object sender, EventArgs e)
303 {
304 GameSystem selected = GetSelectedGameSystem();
305 lstRaces.Items.Clear();
306
307 if (selected != null)
308 {
309 SetRaces(selected);
310 }
241 } 311 }
242 } 312 }
243 } 313 }