view FrmNewArmy.cs @ 9:ffb49ec86df7

Closes #42 - Update translations file to use Schema (WinForms) * Update WinForms GUI translations to use namespace for schema instead of DTD
author IBBoard <dev@ibboard.co.uk>
date Tue, 19 May 2009 11:10:07 +0000
parents 8935971e307c
children 7c366fe55635
line wrap: on
line source

// This file (FrmNewArmy.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard.
//
// The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using IBBoard;
using IBBoard.Lang;
using IBBoard.Windows.Forms;
using IBBoard.WarFoundry.API;
using IBBoard.WarFoundry.API.Objects;
using IBBoard.Windows.Forms.I18N;

namespace IBBoard.WarFoundry
{
	/// <summary>
	/// Summary description for FrmNewArmy.
	/// </summary>
	public class FrmNewArmy : IBBForm
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private IBBoard.Windows.Forms.IBBButton bttnCancel;
		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;

		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);
			}
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// 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);

		}
		#endregion

		public Race SelectedRace
		{
			get { return races[lstRaces.SelectedIndex]; }
		}

		public string ArmyName
		{
			get { return txtArmyName.Text; }
		}

		public int ArmySize
		{
			get { return (int)armySize.Value; }
		}

		private void bttnCancel_Click(object sender, System.EventArgs e)
		{
			DialogResult = DialogResult.Cancel;
			this.Close();
		}

		private void bttnSelectRace_Click(object sender, System.EventArgs e)
		{
			DialogResult = DialogResult.OK;
			this.Close();
		}

		private void txtArmyName_TextChanged(object sender, System.EventArgs e)
		{
			setSelectRaceEnabledVal();
		}

		private void setSelectRaceEnabledVal()
		{
			bttnSelectRace.Enabled = (lstRaces.SelectedIndex>-1 && txtArmyName.Text.Trim()!="" && armySize.Value > 0);
		}

		private void lstRaces_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			setSelectRaceEnabledVal();
		}
	}
}