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 ReplaceEquipmentUIControl : AbstractBaseEquipmentUIControl<IReplaceEquipmentUI>
|
|
15 {
|
|
16 private UnitEquipmentItem origItem;
|
|
17
|
|
18 public ReplaceEquipmentUIControl(Unit unit, UnitEquipmentItem equipmentItem, CommandStack commandStack) : base(unit, commandStack)
|
|
19 {
|
|
20 origItem = equipmentItem;
|
|
21 }
|
|
22
|
|
23 //TODO Make abstract
|
|
24
|
|
25 protected override IReplaceEquipmentUI CreateEquipmentUI()
|
|
26 {
|
|
27 return new FrmReplaceEquipment();
|
|
28 }
|
|
29
|
|
30 protected override void CompleteUISetup()
|
|
31 {
|
|
32 UnitType unitType = unit.UnitType;
|
|
33 string[] mutexGroups = origItem.MutexGroups;
|
|
34 UnitEquipmentItem[] mutexItems = unitType.GetEquipmentItemsByExclusionGroups(mutexGroups);
|
|
35 UnitEquipmentItem[] currentEquipment = unit.GetEquipment();
|
|
36 UnitEquipmentItem[] allowedItems = Arrays.Subtract(mutexItems, currentEquipment);
|
|
37 ui.SetUnitEquipmentItems(allowedItems);
|
|
38 ui.UnitEquipmentItemChoiceChanged += HandleUiUnitEquipmentItemChoiceChanged;
|
|
39 }
|
|
40
|
|
41 private void HandleUiUnitEquipmentItemChoiceChanged(UnitEquipmentItem equip)
|
|
42 {
|
|
43 equipItem = equip;
|
|
44 SetUnitEquipmentLimits(equip);
|
|
45 }
|
|
46
|
|
47 protected override void DoProcessing()
|
|
48 {
|
|
49 if (isRatioAmount)
|
|
50 {
|
|
51 commandStack.Execute(new ReplaceUnitEquipmentWithRatioAmountItemCommand(unit, origItem, equipItem, equipmentAmount));
|
|
52 }
|
|
53 else
|
|
54 {
|
|
55 commandStack.Execute(new ReplaceUnitEquipmentWithRatioAmountItemCommand(unit, origItem, equipItem, (int)equipmentAmount));
|
|
56 }
|
|
57 }
|
|
58 }
|
|
59 }
|
|
60
|