annotate FrmReplaceUnitEquipment.cs @ 83:6d5cb8c7b6ed

Fixes #204: Use new limits in WinForms UI * Set initial amounts correctly * Disable percentage option when all that can be done is "equip all" * Remove unused references to "INFINITY"
author IBBoard <dev@ibboard.co.uk>
date Fri, 30 Oct 2009 21:00:04 +0000
parents 74d3efaac800
children 3e78af88ceb3
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 (FrmReplaceUnitEquipment.cs) is a part of the IBBoard.WarFoundry.GUI.WinForms project and is copyright 2008, 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;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
10 using IBBoard.Commands;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
11 using IBBoard.WarFoundry.API;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
12 using IBBoard.WarFoundry.API.Commands;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
13 using IBBoard.WarFoundry.API.Objects;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
14
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
15 namespace IBBoard.WarFoundry
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
16 {
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
17 /// <summary>
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
18 /// Summary description for FrmNewUnitEquipment.
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
19 /// </summary>
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
20 public class FrmReplaceUnitEquipment : System.Windows.Forms.Form
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
21 {
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
22 private Unit unit;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
23 private UnitEquipmentItem oldItem;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
24 private CommandStack commandStack;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
25 private System.Windows.Forms.Label lblAmount;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
26 private System.Windows.Forms.Button bttnCancel;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
27 private System.Windows.Forms.Button bttnOkay;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
28 private System.Windows.Forms.Label lblItem;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
29 private System.Windows.Forms.ListBox listItems;
47
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
30 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
31 /// <summary>
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
32 /// Required designer variable.
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
33 /// </summary>
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
34 private System.ComponentModel.Container components = null;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
35
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
36 public FrmReplaceUnitEquipment(Unit unit, UnitEquipmentItem item, CommandStack stack)
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
37 {
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
38 commandStack = stack;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
39 this.unit = unit;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
40 oldItem = item;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
41 InitializeComponent();
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
42 this.Text = "Replace " + item.EquipmentItem.Name + " with new equipment";
70
a8667ab60362 Re #180: Add multiple mutex groups
IBBoard <dev@ibboard.co.uk>
parents: 69
diff changeset
43 object[] items = Arrays.Subtract(unit.UnitType.GetEquipmentItemsByExclusionGroups(item.MutexGroups), unit.GetEquipment());
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
44 listItems.Items.AddRange(items);
47
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
45 equipmentAmount.SetUnit(unit);
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
46 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
47
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 /// Clean up any resources being used.
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
50 /// </summary>
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
51 protected override void Dispose( bool 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( disposing )
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
54 {
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
55 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
56 {
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
57 components.Dispose();
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
58 }
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 base.Dispose( disposing );
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
61 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
62
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
63 #region Windows Form Designer generated code
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
64 /// <summary>
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
65 /// 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
66 /// 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
67 /// </summary>
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
68 private void InitializeComponent()
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
69 {
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
70 this.lblAmount = new System.Windows.Forms.Label();
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
71 this.bttnCancel = new System.Windows.Forms.Button();
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
72 this.bttnOkay = new System.Windows.Forms.Button();
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
73 this.lblItem = new System.Windows.Forms.Label();
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
74 this.listItems = new System.Windows.Forms.ListBox();
47
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
75 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
76 this.SuspendLayout();
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
77 //
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
78 // lblAmount
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
79 //
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
80 this.lblAmount.Location = new System.Drawing.Point(8, 80);
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
81 this.lblAmount.Name = "lblAmount";
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
82 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
83 this.lblAmount.TabIndex = 2;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
84 this.lblAmount.Text = "amount";
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
85 this.lblAmount.TextAlign = System.Drawing.ContentAlignment.TopRight;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
86 //
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
87 // bttnCancel
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
88 //
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
89 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
90 this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
47
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
91 this.bttnCancel.Location = new System.Drawing.Point(159, 184);
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
92 this.bttnCancel.Name = "bttnCancel";
47
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
93 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
94 this.bttnCancel.TabIndex = 3;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
95 this.bttnCancel.Text = "cancel";
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
96 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
97 //
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
98 // bttnOkay
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
99 //
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
100 this.bttnOkay.Enabled = false;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
101 this.bttnOkay.FlatStyle = System.Windows.Forms.FlatStyle.System;
47
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
102 this.bttnOkay.Location = new System.Drawing.Point(11, 184);
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
103 this.bttnOkay.Name = "bttnOkay";
47
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
104 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
105 this.bttnOkay.TabIndex = 4;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
106 this.bttnOkay.Text = "okay";
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
107 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
108 //
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
109 // lblItem
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
110 //
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
111 this.lblItem.Location = new System.Drawing.Point(0, 8);
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
112 this.lblItem.Name = "lblItem";
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
113 this.lblItem.Size = new System.Drawing.Size(80, 23);
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
114 this.lblItem.TabIndex = 6;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
115 this.lblItem.Text = "item";
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
116 this.lblItem.TextAlign = System.Drawing.ContentAlignment.TopRight;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
117 //
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
118 // listItems
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
119 //
47
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
120 this.listItems.Location = new System.Drawing.Point(86, 8);
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
121 this.listItems.Name = "listItems";
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
122 this.listItems.Size = new System.Drawing.Size(144, 69);
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
123 this.listItems.TabIndex = 7;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
124 this.listItems.SelectedIndexChanged += new System.EventHandler(this.listItems_SelectedIndexChanged);
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
125 //
47
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
126 // equipmentAmount
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
127 //
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
128 this.equipmentAmount.Location = new System.Drawing.Point(86, 83);
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
129 this.equipmentAmount.Name = "equipmentAmount";
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
130 this.equipmentAmount.Size = new System.Drawing.Size(155, 77);
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
131 this.equipmentAmount.TabIndex = 8;
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
132 //
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
133 // FrmReplaceUnitEquipment
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
134 //
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
135 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
47
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
136 this.ClientSize = new System.Drawing.Size(246, 219);
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
137 this.ControlBox = false;
47
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
138 this.Controls.Add(this.equipmentAmount);
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
139 this.Controls.Add(this.listItems);
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
140 this.Controls.Add(this.lblItem);
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
141 this.Controls.Add(this.bttnOkay);
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
142 this.Controls.Add(this.bttnCancel);
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
143 this.Controls.Add(this.lblAmount);
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
144 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
145 this.Name = "FrmReplaceUnitEquipment";
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
146 this.ShowInTaskbar = false;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
147 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
148 this.Text = "FrmEditUnitEquipment";
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
149 this.ResumeLayout(false);
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
150
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
151 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
152 #endregion
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
153
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
154 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
155 {
47
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
156 SetValue();
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
157 this.Close();
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
158 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
159
47
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
160 private void SetValue()
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
161 {
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
162 UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem;
47
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
163 bool setValue = true;
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
164 double amount = equipmentAmount.EquipmentAmount;
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
165
47
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
166 if (amount == 0)
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
167 {
47
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
168 if (equipItem.IsRequired)
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
169 {
47
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
170 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);
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
171 setValue = false;
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
172 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
173 else
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
174 {
47
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
175 DialogResult dr = MessageBox.Show(this, "This will remove the item from the unit. Continue?", "Confirm remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
176
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
177 if (dr != DialogResult.Yes)
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
178 {
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
179 setValue = false;
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
180 }
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
181 }
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
182 }
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
183
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
184 double oldAmount = unit.GetEquipmentAmount(equipItem);
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
185
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
186 if (setValue && oldAmount != amount)
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
187 {
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
188 if (equipmentAmount.IsRatioEquipmentAmount)
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
189 {
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
190 commandStack.Execute(new ReplaceUnitEquipmentWithRatioAmountItemCommand(unit, oldItem, equipItem, amount));
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
191 }
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
192 else
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
193 {
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
194 commandStack.Execute(new ReplaceUnitEquipmentWithNumericAmountItemCommand(unit, oldItem, equipItem, (int)amount));
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
195 }
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
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
199 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
200 {
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
201 this.Close();
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
202 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
203
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
204 private void listItems_SelectedIndexChanged(object sender, System.EventArgs e)
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
205 {
47
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
206 equipmentAmount.SetUnitEquipmentItem((UnitEquipmentItem)listItems.SelectedItem);
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
207 SetOkayButton();
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
208 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
209
47
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
210 private void SetOkayButton()
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
211 {
47
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
212 double equipAmount = equipmentAmount.EquipmentAmount;
71
74d3efaac800 Fixes #184: Unhandled exception in the unit form
IBBoard <dev@ibboard.co.uk>
parents: 70
diff changeset
213 bttnOkay.Enabled = equipAmount > 0 || equipAmount == WarFoundryCore.INFINITY || (listItems.SelectedItem != null && !((UnitEquipmentItem) listItems.SelectedItem).IsRequired);
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
214 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
215
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
216 private void numEquipAmount_ValueChanged(object sender, System.EventArgs e)
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
217 {
47
2f2e46cd4171 Fixes #148: "Replace equipment" dialog still uses old widgets
IBBoard <dev@ibboard.co.uk>
parents: 46
diff changeset
218 SetOkayButton();
36
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
219 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
220 }
6ab7ddc038f9 Re #121: Move all code to AGPL
IBBoard <dev@ibboard.co.uk>
parents: 34
diff changeset
221 }