view Util/UnitEquipmentChoice.cs @ 66:68d4f7499212

Re #176: Bug when saving recently edited army * Make save button available whether army has previously been saved or not (partly for usability and partly to try to trigger bug) Bug seems to occur when opening an army as the first action, adding a unit and saving it, but not when creating a new army as the first action, then loading an old army as the second action, then adding a unit and saving it
author IBBoard <dev@ibboard.co.uk>
date Sat, 26 Sep 2009 09:51:53 +0000
parents 1576f669b3eb
children acaea18ac0a1
line wrap: on
line source

// This file (UnitEquipmentChoice.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 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.API.Objects;



namespace IBBoard.WarFoundry.GUI.WinForms.Util
{
    /// <summary>
    /// A helper object that holds an equipment choice for a unit.
    /// </summary>

    public class UnitEquipmentChoice
    {
        private Unit unit;
		private UnitEquipmentItem item;

        public UnitEquipmentChoice(Unit unit, UnitEquipmentItem unitItem)
        {
            this.unit = unit;
            item = unitItem;
        }

        public override string ToString()
        {
            return String.Format("{0} (For {1} at {2}pts each)", item.Name, GetAmountString(), item.Cost);
        }

		private string GetAmountString()
		{
			if (unit.GetEquipmentAmountIsRatio(item))
			{
				return UnitEquipmentRatioSelection.GetEquipmentAmountString(unit.GetEquipmentAmount(item));
			}
			else
			{
				return UnitEquipmentNumericSelection.GetEquipmentAmountString(unit.GetEquipmentAmount(item));
			}
		}

        public UnitEquipmentItem Item
        {
            get { return item; }
        }
    }
}