comparison UIControl/AddEquipmentUIControl.cs @ 51:dafbd432ca23

Re #60: Add UI to add/remove/edit weapons in GTK * Start to implement Add functionality using a new abstraction concept that keeps the UI dumb and keeps the logic in a cross-toolkit controller
author IBBoard <dev@ibboard.co.uk>
date Sat, 21 Aug 2010 20:00:03 +0000
parents
children 28b242612ad7
comparison
equal deleted inserted replaced
50:d2f4fcc28254 51:dafbd432ca23
1 // This file (AddEquipmentUI.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 using System;
5 using IBBoard.Commands;
6 using IBBoard.WarFoundry.API.Objects;
7 using IBBoard.WarFoundry.API.Util;
8 using IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces;
9 namespace IBBoard.WarFoundry.GUI.GTK.UIControl
10 {
11 public class AddEquipmentUIControl
12 {
13 private Unit unit;
14 private CommandStack commandStack;
15 private IAddEquipmentUI ui;
16
17 public AddEquipmentUIControl(Unit unit, CommandStack commandStack)
18 {
19 this.unit = unit;
20 this.commandStack = commandStack;
21 SetupUI();
22 }
23
24 private void SetupUI()
25 {
26 CreateEquipmentUI();
27 UnitEquipmentItem[] items = Arrays.Subtract(UnitEquipmentUtil.GetAllowedEquipmentItems(unit), unit.GetEquipment());
28 ui.SetUnitEquipmentItems(items);
29 ui.UnitEquipmentItemChoiceChanged += HandleUiUnitEquipmentItemChoiceChanged;
30 }
31
32 //TODO Make abstract
33 protected void CreateEquipmentUI()
34 {
35 ui = new FrmAddEquipment();
36 }
37
38 private void HandleUiUnitEquipmentItemChoiceChanged(UnitEquipmentItem equip)
39 {
40 bool equipIsRatioLimit = UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip);
41 double maxPercent = RoundPercentage(UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
42 maxPercent = Math.Max(0, maxPercent);
43 double minPercent = RoundPercentage(UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
44 minPercent = Math.Max(0, minPercent);
45 int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip);
46 maxNumber = Math.Max(0, maxNumber);
47 int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip);
48 minNumber = Math.Max(0, minNumber);
49
50 }
51
52 private double RoundPercentage(double percent)
53 {
54 return Math.Round(percent, 1);
55 }
56
57 //TODO Make abstract
58 public void Show()
59 {
60 ((FrmAddEquipment)ui).ShowNow();
61 }
62 }
63 }
64