diff FrmNewArmy.cs @ 0:1bb28f84d567

Initial commit of WarFoundry code
author IBBoard <dev@ibboard.co.uk>
date Fri, 19 Dec 2008 15:57:51 +0000
parents
children 65279b85446f
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FrmNewArmy.cs	Fri Dec 19 15:57:51 2008 +0000
@@ -0,0 +1,129 @@
+// FrmNewArmy.cs
+//
+//  Copyright (C) 2007 IBBoard
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License version 2.1 of the License as published by the Free
+// Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
+//
+//
+
+using System;
+using Gtk;
+using IBBoard.Lang;
+using IBBoard.WarFoundry.API;
+using IBBoard.WarFoundry.API.Objects;
+using log4net;
+
+namespace IBBoard.WarFoundry
+{	
+	public partial class FrmNewArmy : Dialog, ITranslatable
+	{
+		private ILog logger = LogManager.GetLogger(typeof(FrmNewArmy));
+		private GameSystem system;
+		private Race race;
+		private string armyName;
+		private int pointsValue;
+		
+		public FrmNewArmy(GameSystem gameSystem)
+		{
+			this.Build();
+			
+			system = gameSystem;
+			lstRaces.Selection.Changed+= new EventHandler(OnSelectionChanged);
+			TreeViewColumn raceColumn = new TreeViewColumn ();
+			raceColumn.Title = "Race";
+			CellRendererText raceCell = new CellRendererText ();
+			raceColumn.PackStart (raceCell, true);
+			lstRaces.AppendColumn(raceColumn);
+			raceColumn.SetCellDataFunc(raceCell, new TreeCellDataFunc(RenderRaceName));
+			ListStore store = new ListStore(typeof(Race));
+			
+			foreach (Race r in WarFoundryLoader.GetDefault().GetRaces(system))
+			{
+				store.AppendValues(r);
+			}
+			
+			lstRaces.Model = store;
+		}
+		
+		public string Text
+		{
+			get { return Title; }
+			set { Title = value; }
+		}
+		
+		private void RenderRaceName(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
+		{
+			Race r = (Race)model.GetValue(iter, 0);
+			(cell as CellRendererText).Text = r.Name;
+		}
+
+		protected virtual void OnSelectionChanged(object o, EventArgs e)
+		{
+			logger.Debug("Selection changed");
+			setOkayButtonState();
+		}
+		
+		private void setOkayButtonState()
+		{
+			bttnCreate.Sensitive = (lstRaces.Selection.CountSelectedRows() > 0 && txtArmyName.Text!="" && sbPointsValue.Value > 0);
+		}
+
+		protected virtual void OnCreateClicked (object sender, System.EventArgs e)
+		{
+			TreeModel model;
+			TreeIter iter;
+			lstRaces.Selection.GetSelected (out model, out iter);
+			race = (Race) model.GetValue(iter, 0);
+			armyName = txtArmyName.Text;
+			pointsValue = (int)sbPointsValue.Value;
+			Respond(ResponseType.Ok);
+		}
+
+		protected virtual void OnCancelClicked (object sender, System.EventArgs e)
+		{
+			Respond(ResponseType.Cancel);
+		}
+
+		protected virtual void OnTextChanged (object sender, System.EventArgs e)
+		{
+			setOkayButtonState();
+		}
+
+		protected virtual void OnSpinChangeValue (object o, Gtk.ChangeValueArgs args)
+		{
+			setOkayButtonState();
+		}
+
+		protected virtual void OnSpinValueChanged (object sender, System.EventArgs e)
+		{
+			setOkayButtonState();
+		}
+		
+		public Race SelectedRace
+		{
+			get { return race; }
+		}
+		
+		public string ArmyName
+		{
+			get { return armyName; }
+		}
+		
+		public int ArmySize 
+		{
+			get { return pointsValue; }
+		}
+	}
+}