view FrmAddEquipment.cs @ 55:eb7db8495bb5

Re #60: Add UI to add/remove/edit weapons in GTK * Make some manual changes to the Steic-generated file until MonoDevelop bug 634447 is resolved * Add logging to UI * Make control close once we're done with it * Set values for equipment controls
author IBBoard <dev@ibboard.co.uk>
date Wed, 25 Aug 2010 19:51:23 +0000
parents f9f6e9db5350
children 0c5fbb54bfb0
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;
using log4net.Repository.Hierarchy;
using log4net;
namespace IBBoard.WarFoundry.GUI.GTK
{
	public partial class FrmAddEquipment : Dialog, IAddEquipmentUI
	{
		private static ILog log = LogManager.GetLogger(typeof(FrmAddEquipment));
		
		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)
		{
			log.DebugFormat("IsRatio? {0}. Limits: {1}->{2}, {3}%->{4}%", isRatioLimit, minNumber, maxNumber, minPercent, maxPercent);
			rbEquipNumeric.Sensitive = isRatioLimit;
			numericAmount.Sensitive = isRatioLimit;
			numericAmount.SetRange(minNumber, maxNumber);
			percentageAmount.SetRange(minPercent, maxPercent);
		}

		public void SetUnitEquipmentLimitsEnabled(bool isEnabled)
		{
		}

		public bool ShowControl()
		{
			int result = Run();
			bool okayClicked = (result == (int)ResponseType.Ok);
			this.Hide();
			this.Dispose();
			return okayClicked;
		}
		
		protected virtual void CancelButtonClicked(object sender, System.EventArgs e)
		{
			log.Debug("Cancel clicked");
			Respond(ResponseType.Cancel);
		}		
	}
}