113
|
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.
|
|
4
|
|
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;
|
|
11
|
|
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 }
|
|
20
|
|
21 //TODO Make abstract
|
|
22
|
|
23 protected override IAddEquipmentUI CreateEquipmentUI()
|
|
24 {
|
|
25 return new FrmAddEquipment();
|
|
26 }
|
|
27
|
|
28 protected override void CompleteUISetup()
|
|
29 {
|
|
30 ui.SetUnitEquipmentItems(GetEquipmentItems(unit));
|
|
31 ui.UnitEquipmentItemChoiceChanged += HandleUiUnitEquipmentItemChoiceChanged;
|
|
32 }
|
|
33
|
|
34 public static UnitEquipmentItem[] GetEquipmentItems(Unit unit)
|
|
35 {
|
|
36 return Arrays.Subtract(UnitEquipmentUtil.GetAllowedEquipmentItems(unit), unit.GetEquipment());
|
|
37 }
|
|
38
|
|
39 public static bool HasEquipmentToAdd(Unit unit)
|
|
40 {
|
|
41 return GetEquipmentItems(unit).Length > 0;
|
|
42 }
|
|
43
|
|
44 private void HandleUiUnitEquipmentItemChoiceChanged(UnitEquipmentItem equip)
|
|
45 {
|
|
46 equipItem = equip;
|
|
47 SetUnitEquipmentLimits(equip);
|
|
48 }
|
|
49
|
|
50 protected override void DoProcessing()
|
|
51 {
|
|
52 if (isRatioAmount)
|
|
53 {
|
|
54 commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, equipmentAmount));
|
|
55 }
|
|
56 else
|
|
57 {
|
|
58 commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int)equipmentAmount));
|
|
59 }
|
|
60 }
|
|
61 }
|
|
62 }
|
|
63
|