view UI/EquipmentAmountControl.cs @ 40:740350673006

Re #117: Add percentage and number boxes to equipment item dialogs * Add a new EquipmentAmountControl to bundle the controls with some initial implementation * Add new control to "new equipment" dialog and remove old controls Also: * Update some namespaces
author IBBoard <dev@ibboard.co.uk>
date Sun, 06 Sep 2009 18:01:54 +0000
parents
children 4fc87d6e6119
line wrap: on
line source

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using IBBoard.Lang;
using IBBoard.WarFoundry.API;
using IBBoard.WarFoundry.API.Objects;

namespace IBBoard.WarFoundry.GUI.WinForms.UI
{
	public partial class EquipmentAmountControl : UserControl
	{
		private Unit unit;
		private UnitEquipmentItem equip;

		public EquipmentAmountControl()
		{
			InitializeComponent();
		}

		public void SetUnit(Unit equipUnit)
		{
			unit = equipUnit;
		}

		public void SetUnitEquipmentItem(UnitEquipmentItem unitEquipment)
		{
			equip = unitEquipment;
			//SetWidgetValues();
		}

		private void rbEquipAll_CheckedChanged(object sender, EventArgs e)
		{
			bool equipAll = rbEquipAll.Checked;
			numeric.Enabled = !equipAll;
			percentage.Enabled = !equipAll;

			if (equipAll)
			{
				numeric.Value = unit.Size;
				percentage.Value = 100;
			}
		}

		private void percentage_ValueChanged(object sender, EventArgs e)
		{
			double percent = (double) percentage.Value;
			numeric.Value = (decimal) IBBMath.Round(unit.Size * (percent / 100.0), equip.RoundNumberUp);
			rbEquipAll.Checked = (percentage.Value == 100);
		}

		private void numeric_ValueChanged(object sender, EventArgs e)
		{
			percentage.Value = (unit.Size / numeric.Value) * 100;
		}

		public double EquipmentAmount
		{
			get
			{
				double val = 0;

				if (rbNumeric.Checked)
				{
					val = (double) numeric.Value;
				}
				else if (rbPercentage.Enabled)
				{
					val = (double) percentage.Value / 100.0;
				}
				else
				{
					val = WarFoundryCore.INFINITY;
				}

				return val;
			}
		}

		public bool IsRatioEquipmentAmount
		{
			get
			{
				return rbPercentage.Checked;
			}
		}
	}
}