comparison FrmNewArmy.cs @ 200:d084446348f5 default-army-size

RRe #97: Default army size issues
author snowblizz
date Wed, 01 Dec 2010 20:00:07 +0000
parents 0e39412353c4
children ec2b73de16ba
comparison
equal deleted inserted replaced
186:00ffe6109ca5 200:d084446348f5
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
22 { 22 {
23 private static int SYSTEM_DEFAULT_ARMY_SIZE = 1000;
23 private IContainer components; 24 private IContainer components;
24 private IBBoard.Windows.Forms.IBBButton bttnCancel; 25 private IBBoard.Windows.Forms.IBBButton bttnCancel;
25 private IBBoard.Windows.Forms.IBBLabel lblRaceList; 26 private IBBoard.Windows.Forms.IBBLabel lblRaceList;
26 private IBBoard.Windows.Forms.IBBButton bttnSelectRace; 27 private IBBoard.Windows.Forms.IBBButton bttnSelectRace;
27 private System.Windows.Forms.ListBox lstRaces; 28 private System.Windows.Forms.ListBox lstRaces;
33 private System.Windows.Forms.TextBox txtArmyName; 34 private System.Windows.Forms.TextBox txtArmyName;
34 35
35 private GameSystem system; 36 private GameSystem system;
36 private Race race; 37 private Race race;
37 private string armyName; 38 private string armyName;
39 public bool isDefaultArmyName;
38 private ToolTip gameSystemToolTip; 40 private ToolTip gameSystemToolTip;
39 private int maxPoints; 41 private int maxPoints;
40 42
41 public FrmNewArmy(GameSystem system) 43 public FrmNewArmy(GameSystem system)
42 { 44 {
207 this.armySize.Name = "armySize"; 209 this.armySize.Name = "armySize";
208 this.armySize.Size = new System.Drawing.Size(99, 20); 210 this.armySize.Size = new System.Drawing.Size(99, 20);
209 this.armySize.TabIndex = 11; 211 this.armySize.TabIndex = 11;
210 this.armySize.ThousandsSeparator = true; 212 this.armySize.ThousandsSeparator = true;
211 this.armySize.Value = new decimal(new int[] { 213 this.armySize.Value = new decimal(new int[] {
212 2000, 214 SYSTEM_DEFAULT_ARMY_SIZE,
213 0, 215 0,
214 0, 216 0,
215 0}); 217 0});
216 // 218 this.armySize.ValueChanged += new System.EventHandler(this.armySize_ValueChanged);
219 //
217 // gameSystems 220 // gameSystems
218 // 221 //
219 this.gameSystems.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 222 this.gameSystems.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
220 | System.Windows.Forms.AnchorStyles.Right))); 223 | System.Windows.Forms.AnchorStyles.Right)));
221 this.gameSystems.DisplayMember = "Name"; 224 this.gameSystems.DisplayMember = "Name";
305 race = (Race) lstRaces.SelectedItem; 308 race = (Race) lstRaces.SelectedItem;
306 armyName = txtArmyName.Text; 309 armyName = txtArmyName.Text;
307 maxPoints = (int) armySize.Value; 310 maxPoints = (int) armySize.Value;
308 } 311 }
309 312
310 private GameSystem GetSelectedGameSystem() 313 private void armySize_ValueChanged(object sender, System.EventArgs e)
314 {
315 if (txtArmyName.Enabled && isDefaultArmyName)
316 {
317 setTxtArmyNameVal();
318 }
319 }
320
321 private GameSystem GetSelectedGameSystem()
311 { 322 {
312 return (GameSystem) gameSystems.SelectedItem; 323 return (GameSystem) gameSystems.SelectedItem;
313 } 324 }
314 325
315 private void txtArmyName_TextChanged(object sender, System.EventArgs e) 326 private void txtArmyName_TextChanged(object sender, System.EventArgs e)
316 { 327 {
317 setSelectRaceEnabledVal(); 328 isDefaultArmyName = false ;
329 setSelectRaceEnabledVal();
318 } 330 }
319 331
320 private void setSelectRaceEnabledVal() 332 private void setSelectRaceEnabledVal()
321 { 333 {
322 bttnSelectRace.Enabled = (lstRaces.SelectedIndex>-1 && txtArmyName.Text.Trim()!="" && armySize.Value > 0); 334 bttnSelectRace.Enabled = (lstRaces.SelectedIndex>-1 && txtArmyName.Text.Trim()!="" && armySize.Value > 0);
323 } 335 }
324 336
325 private void lstRaces_SelectedIndexChanged(object sender, System.EventArgs e) 337 private void setTxtArmyNameVal()
338 {
339 txtArmyName.Text = String.Format(race.ArmyDefaultName, Translation.GetTranslation("armySizePts", "{0}pt", armySize.Value));
340 isDefaultArmyName = true;
341 }
342
343 private void lstRaces_SelectedIndexChanged(object sender, System.EventArgs e)
326 { 344 {
327 setSelectRaceEnabledVal(); 345 setSelectRaceEnabledVal();
328 bool raceSelected = lstRaces.SelectedItem != null; 346 bool raceSelected = lstRaces.SelectedItem != null;
329 txtArmyName.Enabled = raceSelected; 347 txtArmyName.Enabled = raceSelected;
330 armySize.Enabled = raceSelected; 348 armySize.Enabled = raceSelected;
331 race = (Race)lstRaces.SelectedItem; 349 race = (Race)lstRaces.SelectedItem;
332 txtArmyName.Text = String.Format(race.ArmyDefaultName, Translation.GetTranslation("armySizePts", "{0}pt", armySize.Value)); 350 setTxtArmyNameVal();
333 } 351 }
334 352
335 private void gameSystems_SelectedValueChanged(object sender, EventArgs e) 353 private void gameSystems_SelectedValueChanged(object sender, EventArgs e)
336 { 354 {
337 GameSystem selected = GetSelectedGameSystem(); 355
338 lstRaces.Items.Clear(); 356 GameSystem selected = GetSelectedGameSystem();
339 357 txtArmyName.Text = "";
358 txtArmyName.Enabled = false;
359 lstRaces.Items.Clear();
360
361
340 if (selected != null) 362 if (selected != null)
341 { 363 {
364
365 if (selected.SystemArmyDefaultSize != 1)
366 {
367 System.Diagnostics.Debug.WriteLine("defaultSize:" + selected.SystemArmyDefaultSize);
368 System.Diagnostics.Debug.WriteLine("system:" + selected.ID);
369 armySize.Value = (decimal) selected.SystemArmyDefaultSize;//}
370 }
371
342 SetRaces(selected); 372 SetRaces(selected);
343 373
344 if (lstRaces.Items.Count == 1) 374 if (lstRaces.Items.Count == 1)
345 { 375 {
346 lstRaces.SelectedIndex = 0; 376 lstRaces.SelectedIndex = 0;
347 } 377 }
348 } 378 }
349 379
350 lstRaces.Enabled = lstRaces.Items.Count > 0; 380 lstRaces.Enabled = lstRaces.Items.Count > 0;
381
382
351 } 383 }
352 } 384 }
353 } 385 }