comparison UI/EquipmentAmountControl.cs @ 40:740350673006

Re #117: Add percentage and number boxes to equipment item dialogs * Add a new EquipmentAmountControl to bundle the controls with some initial implementation * Add new control to "new equipment" dialog and remove old controls Also: * Update some namespaces
author IBBoard <dev@ibboard.co.uk>
date Sun, 06 Sep 2009 18:01:54 +0000
parents
children 4fc87d6e6119
comparison
equal deleted inserted replaced
39:25dfeb1db285 40:740350673006
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Drawing;
5 using System.Data;
6 using System.Text;
7 using System.Windows.Forms;
8 using IBBoard.Lang;
9 using IBBoard.WarFoundry.API;
10 using IBBoard.WarFoundry.API.Objects;
11
12 namespace IBBoard.WarFoundry.GUI.WinForms.UI
13 {
14 public partial class EquipmentAmountControl : UserControl
15 {
16 private Unit unit;
17 private UnitEquipmentItem equip;
18
19 public EquipmentAmountControl()
20 {
21 InitializeComponent();
22 }
23
24 public void SetUnit(Unit equipUnit)
25 {
26 unit = equipUnit;
27 }
28
29 public void SetUnitEquipmentItem(UnitEquipmentItem unitEquipment)
30 {
31 equip = unitEquipment;
32 //SetWidgetValues();
33 }
34
35 private void rbEquipAll_CheckedChanged(object sender, EventArgs e)
36 {
37 bool equipAll = rbEquipAll.Checked;
38 numeric.Enabled = !equipAll;
39 percentage.Enabled = !equipAll;
40
41 if (equipAll)
42 {
43 numeric.Value = unit.Size;
44 percentage.Value = 100;
45 }
46 }
47
48 private void percentage_ValueChanged(object sender, EventArgs e)
49 {
50 double percent = (double) percentage.Value;
51 numeric.Value = (decimal) IBBMath.Round(unit.Size * (percent / 100.0), equip.RoundNumberUp);
52 rbEquipAll.Checked = (percentage.Value == 100);
53 }
54
55 private void numeric_ValueChanged(object sender, EventArgs e)
56 {
57 percentage.Value = (unit.Size / numeric.Value) * 100;
58 }
59
60 public double EquipmentAmount
61 {
62 get
63 {
64 double val = 0;
65
66 if (rbNumeric.Checked)
67 {
68 val = (double) numeric.Value;
69 }
70 else if (rbPercentage.Enabled)
71 {
72 val = (double) percentage.Value / 100.0;
73 }
74 else
75 {
76 val = WarFoundryCore.INFINITY;
77 }
78
79 return val;
80 }
81 }
82
83 public bool IsRatioEquipmentAmount
84 {
85 get
86 {
87 return rbPercentage.Checked;
88 }
89 }
90 }
91 }