view FrmAddEquipment.cs @ 54:f9f6e9db5350

Re #60: Add UI to add/remove/edit weapons in GTK * Add selection change notification from equipment list * Make ShowControl method return a boolean to say what the user did with it * Re-implement ShowControl to use Run() instead of ShowNow() so we can get a response result
author IBBoard <dev@ibboard.co.uk>
date Wed, 25 Aug 2010 16:01:12 +0000
parents 28b242612ad7
children eb7db8495bb5
line wrap: on
line source

//  This file (FrmAddEquipment.cs) is a part of the IBBoard.WarFoundry.GUI.GTK project and is copyright 2010 IBBoard
// 
//  The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
using System;
using IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces;
using IBBoard.WarFoundry.API.Objects;
using Gtk;
using IBBoard.WarFoundry.GUI.GTK.Util;
using IBBoard.GtkSharp;
namespace IBBoard.WarFoundry.GUI.GTK
{
	public partial class FrmAddEquipment : Gtk.Dialog, IAddEquipmentUI
	{
		public event SingleArgMethodInvoker<UnitEquipmentItem> UnitEquipmentItemChoiceChanged;
		
		public FrmAddEquipment()
		{
			this.Build();
			lstEquipment.Selection.Changed += OnSelectionChanged;
			TreeViewColumn equipColumn = new TreeViewColumn();
			equipColumn.Title = "Equipment";
			CellRendererText equipCell = new CellRendererText();
			equipColumn.PackStart(equipCell, true);
			equipColumn.SetCellDataFunc(equipCell, GtkWarFoundryUtil.RenderWarFoundryObjectName);
			lstEquipment.AppendColumn(equipColumn);
		}
		
		protected virtual void OnSelectionChanged(object o, EventArgs e)
		{
			if (UnitEquipmentItemChoiceChanged!=null)
			{
				UnitEquipmentItemChoiceChanged((UnitEquipmentItem)TreeUtils.GetSelectedItem(lstEquipment));
			}
		}

		public void SetUnitEquipmentItems(UnitEquipmentItem[] items)
		{
			ListStore store = new ListStore(typeof(UnitEquipmentItem));
			
			foreach (UnitEquipmentItem equipItem in items)
			{
				store.AppendValues(equipItem);
			}
			
			lstEquipment.Model = store;
		}

		public void SetUnitEquipmentLimits(bool isRatioLimit, double minPercent, double maxPercent, int minNumber, int maxNumber)
		{
			
		}

		public void SetUnitEquipmentLimitsEnabled(bool isEnabled)
		{
			
		}

		public bool ShowControl()
		{
			return Run() == (int)ResponseType.Ok;
		}
		
		protected virtual void CancelButtonClicked (object sender, System.EventArgs e)
		{
			Respond(ResponseType.Cancel);
		}		
	}
}