view UIControl/AddEquipmentUIControl.cs @ 68:7028e24b67ec

Re #60: Add UI to add/remove/edit weapons in GTK * Add "Replace" dialog Note: Dialog null refs because of a bad assumption in the base class - base constructor calls SetupUI before Replace constructor has set all of its values
author IBBoard <dev@ibboard.co.uk>
date Wed, 03 Nov 2010 21:02:54 +0000
parents 100626381159
children 4b82515586ac
line source
1 // This file (AddEquipmentUIControl.cs) is a part of the IBBoard.WarFoundry.GUI.GTK project and is copyright 2010 IBBoard
2 //
3 // 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.
5 using IBBoard.Commands;
6 using IBBoard.WarFoundry.API.Commands;
7 using IBBoard.WarFoundry.API.Objects;
8 using IBBoard.WarFoundry.API.Util;
9 using IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces;
10 using CustomMath = IBBoard.CustomMath;
12 namespace IBBoard.WarFoundry.GUI.GTK.UIControl
13 {
14 public class AddEquipmentUIControl : AbstractBaseEquipmentUIControl<IAddEquipmentUI>
15 {
16 public AddEquipmentUIControl(Unit unit, CommandStack commandStack) : base(unit, commandStack)
17 {
18 //Do nothing extra
19 }
21 //TODO Make abstract
22 protected override IAddEquipmentUI CreateEquipmentUI()
23 {
24 return new FrmAddEquipment();
25 }
27 protected override void CompleteUISetup()
28 {
29 UnitEquipmentItem[] items = Arrays.Subtract(UnitEquipmentUtil.GetAllowedEquipmentItems(unit), unit.GetEquipment());
30 ui.SetUnitEquipmentItems(items);
31 ui.UnitEquipmentItemChoiceChanged += HandleUiUnitEquipmentItemChoiceChanged;
32 }
34 private void HandleUiUnitEquipmentItemChoiceChanged(UnitEquipmentItem equip)
35 {
36 equipItem = equip;
38 if (equip != null)
39 {
40 bool equipIsRatioLimit = UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip);
41 maxPercentage = GetMaxPercentageLimit(equip);
42 minPercentage = GetMinPercentageLimit(equip);
43 maxNumber = GetMaxNumericLimit(equip);
44 minNumber = GetMinNumericLimit(equip);
46 ui.SetUnitEquipmentLimits(equipIsRatioLimit, minPercentage, maxPercentage, minNumber, maxNumber);
47 ui.SetUnitEquipmentLimitsEnabled(true);
48 ui.SetOkayEnabledState(HasNonZeroEquipmentAmount());
49 SetEquipmentAmountControlEnabledStates();
50 }
51 else
52 {
53 maxPercentage = minPercentage = 0;
54 maxNumber = minNumber = 0;
55 ui.SetUnitEquipmentLimits(false, minPercentage, maxPercentage, minNumber, maxNumber);
56 ui.SetUnitEquipmentLimitsEnabled(false);
57 ui.SetOkayEnabledState(false);
58 }
59 }
61 protected override void DoProcessing()
62 {
63 if (isRatioAmount)
64 {
65 commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, equipmentAmount));
66 }
67 else
68 {
69 commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int)equipmentAmount));
70 }
71 }
72 }
73 }