annotate FrmEditUnitEquipment.cs @ 61:a0ec03c24cd9

Fixes #171: Open unit form when unit is created * Move unit form opening code to parent window (i.e. FrmMain) * Add code to open form on first create (but not on re-add - e.g. undo create and redo - because we don't know if it was open before or not)
author IBBoard <dev@ibboard.co.uk>
date Sat, 19 Sep 2009 16:01:43 +0000
parents 1576f669b3eb
children 712915de47fd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
1 // This file (FrmEditUnitEquipment.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2009 IBBoard.
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
2 //
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
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.
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
4
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
5 using System;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
6 using System.Drawing;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
7 using System.ComponentModel;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
8 using System.Windows.Forms;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
9 using IBBoard.Commands;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
10 using IBBoard.WarFoundry.API;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
11 using IBBoard.WarFoundry.API.Commands;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
12 using IBBoard.WarFoundry.API.Objects;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
13
42
d06c2e390a14 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
14 namespace IBBoard.WarFoundry.GUI.WinForms
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
15 {
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
16 /// <summary>
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
17 /// Summary description for FrmEditUnitEquipment.
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
18 /// </summary>
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
19 public class FrmEditUnitEquipment : System.Windows.Forms.Form
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
20 {
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
21 private Unit unit;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
22 private UnitEquipmentItem equipItem;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
23 private CommandStack commandStack;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
24 private System.Windows.Forms.Label lblAmount;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
25 private System.Windows.Forms.Button bttnCancel;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
26 private System.Windows.Forms.Button bttnOkay;
42
d06c2e390a14 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
27 private IBBoard.WarFoundry.GUI.WinForms.UI.EquipmentAmountControl equipmentAmount;
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
28 /// <summary>
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
29 /// Required designer variable.
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
30 /// </summary>
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
31 private System.ComponentModel.Container components = null;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
32
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
33 public FrmEditUnitEquipment(Unit unit, UnitEquipmentItem equipItem, CommandStack stack)
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
34 {
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
35 commandStack = stack;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
36 this.unit = unit;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
37 this.equipItem = equipItem;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
38 InitializeComponent();
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
39 this.Text = equipItem.Name + " for " + unit.Name;
42
d06c2e390a14 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
40 equipmentAmount.SetUnit(unit);
d06c2e390a14 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
41 equipmentAmount.SetUnitEquipmentItem(equipItem);
d06c2e390a14 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
42 equipmentAmount.SetUnitEquipmentItemAmount(unit.GetEquipmentAmount(equipItem), unit.GetEquipmentAmountIsRatio(equipItem));
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
43 bttnOkay.Enabled = false;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
44 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
45
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
46 /// <summary>
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
47 /// Clean up any resources being used.
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
48 /// </summary>
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
49 protected override void Dispose( bool disposing )
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
50 {
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
51 if( disposing )
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
52 {
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
53 if(components != null)
34
3ceb0efd261f Re #118: Allow equipment amounts of "ratio" equipment to be define as absolute or ratio amounts
IBBoard <dev@ibboard.co.uk>
parents: 24
diff changeset
54 {
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
55 components.Dispose();
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
56 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
57 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
58 base.Dispose( disposing );
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
59 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
60
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
61 #region Windows Form Designer generated code
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
62 /// <summary>
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
63 /// Required method for Designer support - do not modify
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
64 /// the contents of this method with the code editor.
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
65 /// </summary>
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
66 private void InitializeComponent()
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
67 {
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
68 this.lblAmount = new System.Windows.Forms.Label();
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
69 this.bttnCancel = new System.Windows.Forms.Button();
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
70 this.bttnOkay = new System.Windows.Forms.Button();
42
d06c2e390a14 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
71 this.equipmentAmount = new IBBoard.WarFoundry.GUI.WinForms.UI.EquipmentAmountControl();
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
72 this.SuspendLayout();
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
73 //
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
74 // lblAmount
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
75 //
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
76 this.lblAmount.Location = new System.Drawing.Point(8, 8);
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
77 this.lblAmount.Name = "lblAmount";
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
78 this.lblAmount.Size = new System.Drawing.Size(72, 23);
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
79 this.lblAmount.TabIndex = 2;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
80 this.lblAmount.Text = "amount";
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
81 this.lblAmount.TextAlign = System.Drawing.ContentAlignment.TopRight;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
82 //
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
83 // bttnCancel
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
84 //
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
85 this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
86 this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
42
d06c2e390a14 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
87 this.bttnCancel.Location = new System.Drawing.Point(153, 95);
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
88 this.bttnCancel.Name = "bttnCancel";
42
d06c2e390a14 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
89 this.bttnCancel.Size = new System.Drawing.Size(75, 23);
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
90 this.bttnCancel.TabIndex = 3;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
91 this.bttnCancel.Text = "cancel";
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
92 this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click);
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
93 //
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
94 // bttnOkay
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
95 //
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
96 this.bttnOkay.Enabled = false;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
97 this.bttnOkay.FlatStyle = System.Windows.Forms.FlatStyle.System;
42
d06c2e390a14 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
98 this.bttnOkay.Location = new System.Drawing.Point(12, 95);
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
99 this.bttnOkay.Name = "bttnOkay";
42
d06c2e390a14 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
100 this.bttnOkay.Size = new System.Drawing.Size(75, 23);
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
101 this.bttnOkay.TabIndex = 4;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
102 this.bttnOkay.Text = "okay";
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
103 this.bttnOkay.Click += new System.EventHandler(this.bttnOkay_Click);
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
104 //
42
d06c2e390a14 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
105 // equipmentAmount
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
106 //
42
d06c2e390a14 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
107 this.equipmentAmount.Location = new System.Drawing.Point(88, 5);
d06c2e390a14 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
108 this.equipmentAmount.Name = "equipmentAmount";
d06c2e390a14 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
109 this.equipmentAmount.Size = new System.Drawing.Size(155, 77);
d06c2e390a14 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
110 this.equipmentAmount.TabIndex = 5;
d06c2e390a14 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
111 this.equipmentAmount.ValueChanged += new System.EventHandler(this.equipmentAmount_ValueChanged);
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
112 //
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
113 // FrmEditUnitEquipment
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
114 //
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
115 this.AcceptButton = this.bttnOkay;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
116 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
117 this.CancelButton = this.bttnCancel;
42
d06c2e390a14 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
118 this.ClientSize = new System.Drawing.Size(240, 130);
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
119 this.ControlBox = false;
42
d06c2e390a14 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
120 this.Controls.Add(this.equipmentAmount);
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
121 this.Controls.Add(this.bttnOkay);
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
122 this.Controls.Add(this.bttnCancel);
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
123 this.Controls.Add(this.lblAmount);
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
124 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
125 this.Name = "FrmEditUnitEquipment";
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
126 this.ShowInTaskbar = false;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
127 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
128 this.Text = "FrmEditUnitEquipment";
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
129 this.ResumeLayout(false);
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
130
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
131 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
132 #endregion
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
133
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
134 private void bttnOkay_Click(object sender, System.EventArgs e)
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
135 {
43
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
136 if (SetValue())
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
137 {
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
138 this.Close();
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
139 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
140 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
141
43
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
142 private bool SetValue()
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
143 {
43
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
144 bool setValue = true;
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
145 double amount = equipmentAmount.EquipmentAmount;
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
146
43
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
147 if (amount == 0)
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
148 {
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
149 if (equipItem.IsRequired)
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
150 {
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
151 MessageBox.Show(this, "This item is required and cannot be removed. It must have a quantity of at least one or be replaced by an alternative.", "Required item", MessageBoxButtons.OK, MessageBoxIcon.Warning);
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
152 setValue = false;
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
153 }
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
154 else
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
155 {
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
156 DialogResult dr = MessageBox.Show(this, "This will remove the item from the unit. Continue?", "Confirm remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
157
43
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
158 if (dr != DialogResult.Yes)
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
159 {
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
160 setValue = false;
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
161 }
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
162 }
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
163 }
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
164
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
165 double oldAmount = unit.GetEquipmentAmount(equipItem);
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
166
43
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
167 if (setValue && oldAmount != amount)
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
168 {
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
169 if (equipmentAmount.IsRatioEquipmentAmount)
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
170 {
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
171 commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, amount));
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
172 }
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
173 else
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
174 {
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
175 commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int)amount));
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
176 }
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
177 }
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
178
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
179 return setValue;
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
180 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
181
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
182 private void bttnCancel_Click(object sender, System.EventArgs e)
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
183 {
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
184 this.Close();
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
185 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
186
42
d06c2e390a14 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
187 private void setOkayButton()
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
188 {
43
7ace7d2249ac Fixes #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 42
diff changeset
189 double equipAmount = equipmentAmount.EquipmentAmount;
42
d06c2e390a14 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
190 bttnOkay.Enabled = equipAmount > 0 || equipAmount == WarFoundryCore.INFINITY || !equipItem.IsRequired;
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
191 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
192
42
d06c2e390a14 Re #117: Add percentage and number boxes to equipment item dialogs
IBBoard <dev@ibboard.co.uk>
parents: 36
diff changeset
193 private void equipmentAmount_ValueChanged(object sender, EventArgs e)
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
194 {
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
195 setOkayButton();
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
196 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
197 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
198 }