Mercurial > repos > IBBoard.WarFoundry.GUI.WinForms
diff 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 |
line wrap: on
line diff
--- a/FrmNewArmy.cs Wed Sep 16 19:50:39 2009 +0000 +++ b/FrmNewArmy.cs Sat Sep 19 10:27:01 2009 +0000 @@ -11,9 +11,9 @@ using IBBoard.Windows.Forms; using IBBoard.WarFoundry.API; using IBBoard.WarFoundry.API.Objects; -using IBBoard.Windows.Forms.I18N; - -namespace IBBoard.WarFoundry +using IBBoard.Windows.Forms.I18N; + +namespace IBBoard.WarFoundry.GUI.WinForms { /// <summary> /// Summary description for FrmNewArmy. @@ -28,24 +28,41 @@ private IBBoard.Windows.Forms.IBBLabel lblRaceList; private IBBoard.Windows.Forms.IBBButton bttnSelectRace; private System.Windows.Forms.ListBox lstRaces; - private Race[] races; private IBBoard.Windows.Forms.IBBLabel lblArmyName; private IBBoard.Windows.Forms.IBBLabel lblArmySize; - private System.Windows.Forms.NumericUpDown armySize; - private System.Windows.Forms.TextBox txtArmyName; + private System.Windows.Forms.NumericUpDown armySize; + private Label lblGameSystem; + private ComboBox gameSystems; + private System.Windows.Forms.TextBox txtArmyName; + + private GameSystem system; + private Race race; + private string armyName; + private int maxPoints; public FrmNewArmy(GameSystem system) { InitializeComponent(); - ControlTranslator.TranslateControl(this); - - races = WarFoundryLoader.GetDefault().GetRaces(system); - - for (int i = 0; i<races.Length; i++) - { - lstRaces.Items.Add(races[i].Name); + ControlTranslator.TranslateControl(this); + + foreach (GameSystem gameSystem in WarFoundryLoader.GetDefault().GetGameSystems()) + { + gameSystems.Items.Add(gameSystem); + } + + if (WarFoundryCore.CurrentGameSystem != null) + { + gameSystems.SelectedItem = FrmMain.CurrentGameSystem; } + } + + private void SetRaces(GameSystem system) + { + foreach (Race race in WarFoundryLoader.GetDefault().GetRaces(system)) + { + lstRaces.Items.Add(race); + } } /// <summary> @@ -69,148 +86,176 @@ /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() - { - System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FrmNewArmy)); - this.lstRaces = new System.Windows.Forms.ListBox(); - this.bttnCancel = new IBBoard.Windows.Forms.IBBButton(); - this.lblRaceList = new IBBoard.Windows.Forms.IBBLabel(); - this.bttnSelectRace = new IBBoard.Windows.Forms.IBBButton(); - this.lblArmyName = new IBBoard.Windows.Forms.IBBLabel(); - this.txtArmyName = new System.Windows.Forms.TextBox(); - this.lblArmySize = new IBBoard.Windows.Forms.IBBLabel(); - this.armySize = new System.Windows.Forms.NumericUpDown(); - ((System.ComponentModel.ISupportInitialize)(this.armySize)).BeginInit(); - this.SuspendLayout(); - // - // lstRaces - // - this.lstRaces.Location = new System.Drawing.Point(88, 8); - this.lstRaces.Name = "lstRaces"; - this.lstRaces.Size = new System.Drawing.Size(272, 121); - this.lstRaces.TabIndex = 7; - this.lstRaces.SelectedIndexChanged += new System.EventHandler(this.lstRaces_SelectedIndexChanged); - // - // bttnCancel - // - this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnCancel.Location = new System.Drawing.Point(8, 200); - this.bttnCancel.Name = "bttnCancel"; - this.bttnCancel.Size = new System.Drawing.Size(80, 24); - this.bttnCancel.TabIndex = 6; - this.bttnCancel.Text = "Cancel"; - this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click); - // - // lblRaceList - // - this.lblRaceList.Location = new System.Drawing.Point(0, 8); - this.lblRaceList.Name = "lblRaceList"; - this.lblRaceList.Size = new System.Drawing.Size(88, 80); - this.lblRaceList.TabIndex = 5; - this.lblRaceList.Text = "race list"; - this.lblRaceList.TextAlign = System.Drawing.ContentAlignment.TopRight; - // - // bttnSelectRace - // - this.bttnSelectRace.Enabled = false; - this.bttnSelectRace.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnSelectRace.Location = new System.Drawing.Point(256, 200); - this.bttnSelectRace.Name = "bttnSelectRace"; - this.bttnSelectRace.Size = new System.Drawing.Size(104, 24); - this.bttnSelectRace.TabIndex = 4; - this.bttnSelectRace.Text = "create race"; - this.bttnSelectRace.Click += new System.EventHandler(this.bttnSelectRace_Click); - // - // lblArmyName - // - this.lblArmyName.Location = new System.Drawing.Point(0, 136); - this.lblArmyName.Name = "lblArmyName"; - this.lblArmyName.Size = new System.Drawing.Size(88, 32); - this.lblArmyName.TabIndex = 8; - this.lblArmyName.Text = "army name"; - this.lblArmyName.TextAlign = System.Drawing.ContentAlignment.TopRight; - // - // txtArmyName - // - this.txtArmyName.Location = new System.Drawing.Point(88, 136); - this.txtArmyName.Name = "txtArmyName"; - this.txtArmyName.Size = new System.Drawing.Size(272, 20); - this.txtArmyName.TabIndex = 9; - this.txtArmyName.Text = ""; - this.txtArmyName.TextChanged += new System.EventHandler(this.txtArmyName_TextChanged); - // - // lblArmySize - // - this.lblArmySize.Location = new System.Drawing.Point(0, 168); - this.lblArmySize.Name = "lblArmySize"; - this.lblArmySize.Size = new System.Drawing.Size(88, 32); - this.lblArmySize.TabIndex = 10; - this.lblArmySize.Text = "army size"; - this.lblArmySize.TextAlign = System.Drawing.ContentAlignment.TopRight; - // - // armySize - // - this.armySize.Increment = new System.Decimal(new int[] { - 50, - 0, - 0, - 0}); - this.armySize.Location = new System.Drawing.Point(88, 168); - this.armySize.Maximum = new System.Decimal(new int[] { - 1000000, - 0, - 0, - 0}); - this.armySize.Name = "armySize"; - this.armySize.TabIndex = 11; - this.armySize.ThousandsSeparator = true; - this.armySize.Value = new System.Decimal(new int[] { - 2000, - 0, - 0, - 0}); - // - // FrmNewArmy - // - this.AcceptButton = this.bttnSelectRace; - this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); - this.CancelButton = this.bttnCancel; - this.ClientSize = new System.Drawing.Size(370, 228); - this.Controls.Add(this.armySize); - this.Controls.Add(this.lblArmySize); - this.Controls.Add(this.txtArmyName); - this.Controls.Add(this.lblArmyName); - this.Controls.Add(this.bttnCancel); - this.Controls.Add(this.lblRaceList); - this.Controls.Add(this.bttnSelectRace); - this.Controls.Add(this.lstRaces); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; - this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "FrmNewArmy"; - this.ShowInTaskbar = false; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "FrmNewArmy"; - ((System.ComponentModel.ISupportInitialize)(this.armySize)).EndInit(); - this.ResumeLayout(false); - + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmNewArmy)); + this.lstRaces = new System.Windows.Forms.ListBox(); + this.bttnCancel = new IBBoard.Windows.Forms.IBBButton(); + this.lblRaceList = new IBBoard.Windows.Forms.IBBLabel(); + this.bttnSelectRace = new IBBoard.Windows.Forms.IBBButton(); + this.lblArmyName = new IBBoard.Windows.Forms.IBBLabel(); + this.txtArmyName = new System.Windows.Forms.TextBox(); + this.lblArmySize = new IBBoard.Windows.Forms.IBBLabel(); + this.armySize = new System.Windows.Forms.NumericUpDown(); + this.lblGameSystem = new System.Windows.Forms.Label(); + this.gameSystems = new System.Windows.Forms.ComboBox(); + ((System.ComponentModel.ISupportInitialize) (this.armySize)).BeginInit(); + this.SuspendLayout(); + // + // lstRaces + // + this.lstRaces.Location = new System.Drawing.Point(89, 33); + this.lstRaces.Name = "lstRaces"; + this.lstRaces.Size = new System.Drawing.Size(269, 121); + this.lstRaces.TabIndex = 7; + this.lstRaces.SelectedIndexChanged += new System.EventHandler(this.lstRaces_SelectedIndexChanged); + // + // bttnCancel + // + this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.bttnCancel.Location = new System.Drawing.Point(12, 231); + this.bttnCancel.Name = "bttnCancel"; + this.bttnCancel.Size = new System.Drawing.Size(80, 24); + this.bttnCancel.TabIndex = 6; + this.bttnCancel.Text = "Cancel"; + this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click); + // + // lblRaceList + // + this.lblRaceList.Location = new System.Drawing.Point(12, 33); + this.lblRaceList.Name = "lblRaceList"; + this.lblRaceList.Size = new System.Drawing.Size(71, 80); + this.lblRaceList.TabIndex = 5; + this.lblRaceList.Text = "race list"; + this.lblRaceList.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // bttnSelectRace + // + this.bttnSelectRace.Enabled = false; + this.bttnSelectRace.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.bttnSelectRace.Location = new System.Drawing.Point(254, 231); + this.bttnSelectRace.Name = "bttnSelectRace"; + this.bttnSelectRace.Size = new System.Drawing.Size(104, 24); + this.bttnSelectRace.TabIndex = 4; + this.bttnSelectRace.Text = "create race"; + this.bttnSelectRace.Click += new System.EventHandler(this.bttnSelectRace_Click); + // + // lblArmyName + // + this.lblArmyName.Location = new System.Drawing.Point(12, 163); + this.lblArmyName.Name = "lblArmyName"; + this.lblArmyName.Size = new System.Drawing.Size(71, 17); + this.lblArmyName.TabIndex = 8; + this.lblArmyName.Text = "army name"; + this.lblArmyName.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // txtArmyName + // + this.txtArmyName.Location = new System.Drawing.Point(89, 160); + this.txtArmyName.Name = "txtArmyName"; + this.txtArmyName.Size = new System.Drawing.Size(269, 20); + this.txtArmyName.TabIndex = 9; + this.txtArmyName.TextChanged += new System.EventHandler(this.txtArmyName_TextChanged); + // + // lblArmySize + // + this.lblArmySize.Location = new System.Drawing.Point(12, 188); + this.lblArmySize.Name = "lblArmySize"; + this.lblArmySize.Size = new System.Drawing.Size(71, 18); + this.lblArmySize.TabIndex = 10; + this.lblArmySize.Text = "army size"; + this.lblArmySize.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // armySize + // + this.armySize.Increment = new decimal(new int[] { + 50, + 0, + 0, + 0}); + this.armySize.Location = new System.Drawing.Point(89, 186); + this.armySize.Maximum = new decimal(new int[] { + 1000000, + 0, + 0, + 0}); + this.armySize.Name = "armySize"; + this.armySize.Size = new System.Drawing.Size(120, 20); + this.armySize.TabIndex = 11; + this.armySize.ThousandsSeparator = true; + this.armySize.Value = new decimal(new int[] { + 2000, + 0, + 0, + 0}); + // + // lblGameSystem + // + this.lblGameSystem.Location = new System.Drawing.Point(12, 9); + this.lblGameSystem.Name = "lblGameSystem"; + this.lblGameSystem.Size = new System.Drawing.Size(71, 18); + this.lblGameSystem.TabIndex = 12; + this.lblGameSystem.Text = "game system"; + this.lblGameSystem.TextAlign = System.Drawing.ContentAlignment.TopRight; + // + // gameSystems + // + this.gameSystems.FormattingEnabled = true; + this.gameSystems.Location = new System.Drawing.Point(89, 6); + this.gameSystems.Name = "gameSystems"; + this.gameSystems.Size = new System.Drawing.Size(269, 21); + this.gameSystems.TabIndex = 13; + this.gameSystems.SelectedValueChanged += new System.EventHandler(this.gameSystems_SelectedValueChanged); + // + // FrmNewArmy + // + this.AcceptButton = this.bttnSelectRace; + this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); + this.CancelButton = this.bttnCancel; + this.ClientSize = new System.Drawing.Size(370, 267); + this.Controls.Add(this.gameSystems); + this.Controls.Add(this.lblGameSystem); + this.Controls.Add(this.armySize); + this.Controls.Add(this.lblArmySize); + this.Controls.Add(this.txtArmyName); + this.Controls.Add(this.lblArmyName); + this.Controls.Add(this.bttnCancel); + this.Controls.Add(this.lblRaceList); + this.Controls.Add(this.bttnSelectRace); + this.Controls.Add(this.lstRaces); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Icon = ((System.Drawing.Icon) (resources.GetObject("$this.Icon"))); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "FrmNewArmy"; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "FrmNewArmy"; + ((System.ComponentModel.ISupportInitialize) (this.armySize)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + } - #endregion + #endregion + + public GameSystem SelectedSystem + { + get { return system; } + } public Race SelectedRace { - get { return races[lstRaces.SelectedIndex]; } + get { return race; } } public string ArmyName { - get { return txtArmyName.Text; } + get { return armyName; } } public int ArmySize { - get { return (int)armySize.Value; } + get { return maxPoints; } } private void bttnCancel_Click(object sender, System.EventArgs e) @@ -221,8 +266,22 @@ private void bttnSelectRace_Click(object sender, System.EventArgs e) { - DialogResult = DialogResult.OK; + DialogResult = DialogResult.OK; + SetValues(); this.Close(); + } + + private void SetValues() + { + system = GetSelectedGameSystem(); + race = (Race) lstRaces.SelectedItem; + armyName = txtArmyName.Text; + maxPoints = (int) armySize.Value; + } + + private GameSystem GetSelectedGameSystem() + { + return (GameSystem) gameSystems.SelectedItem; } private void txtArmyName_TextChanged(object sender, System.EventArgs e) @@ -238,6 +297,17 @@ private void lstRaces_SelectedIndexChanged(object sender, System.EventArgs e) { setSelectRaceEnabledVal(); + } + + private void gameSystems_SelectedValueChanged(object sender, EventArgs e) + { + GameSystem selected = GetSelectedGameSystem(); + lstRaces.Items.Clear(); + + if (selected != null) + { + SetRaces(selected); + } } } }