Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.WinForms
changeset 47:2f2e46cd4171
Fixes #148: "Replace equipment" dialog still uses old widgets
* Update dialog to use new widget
Also:
* Rename some methods to match naming conventions
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 13 Sep 2009 18:51:39 +0000 |
parents | 1576f669b3eb |
children | cf644b2c65e6 |
files | FrmReplaceUnitEquipment.cs FrmReplaceUnitEquipment.resx |
diffstat | 2 files changed, 82 insertions(+), 216 deletions(-) [+] |
line wrap: on
line diff
--- a/FrmReplaceUnitEquipment.cs Sun Sep 13 17:33:36 2009 +0000 +++ b/FrmReplaceUnitEquipment.cs Sun Sep 13 18:51:39 2009 +0000 @@ -21,17 +21,13 @@ { private Unit unit; private UnitEquipmentItem oldItem; - private bool required; private CommandStack commandStack; - - private System.Windows.Forms.NumericUpDown numEquipAmount; - private System.Windows.Forms.Label lblPercent; private System.Windows.Forms.Label lblAmount; private System.Windows.Forms.Button bttnCancel; private System.Windows.Forms.Button bttnOkay; - private System.Windows.Forms.CheckBox cbEquipAll; private System.Windows.Forms.Label lblItem; private System.Windows.Forms.ListBox listItems; + private IBBoard.WarFoundry.GUI.WinForms.UI.EquipmentAmountControl equipmentAmount; /// <summary> /// Required designer variable. /// </summary> @@ -46,6 +42,7 @@ this.Text = "Replace " + item.EquipmentItem.Name + " with new equipment"; object[] items = Arrays.Subtract(unit.UnitType.GetEquipmentItemsByExclusionGroup(item.MutexGroup), unit.GetEquipment()); listItems.Items.AddRange(items); + equipmentAmount.SetUnit(unit); } /// <summary> @@ -70,35 +67,14 @@ /// </summary> private void InitializeComponent() { - this.numEquipAmount = new System.Windows.Forms.NumericUpDown(); - this.lblPercent = new System.Windows.Forms.Label(); this.lblAmount = new System.Windows.Forms.Label(); this.bttnCancel = new System.Windows.Forms.Button(); this.bttnOkay = new System.Windows.Forms.Button(); - this.cbEquipAll = new System.Windows.Forms.CheckBox(); this.lblItem = new System.Windows.Forms.Label(); this.listItems = new System.Windows.Forms.ListBox(); - ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).BeginInit(); + this.equipmentAmount = new IBBoard.WarFoundry.GUI.WinForms.UI.EquipmentAmountControl(); this.SuspendLayout(); // - // numEquipAmount - // - this.numEquipAmount.Enabled = false; - this.numEquipAmount.Location = new System.Drawing.Point(88, 80); - this.numEquipAmount.Name = "numEquipAmount"; - this.numEquipAmount.Size = new System.Drawing.Size(144, 20); - this.numEquipAmount.TabIndex = 0; - this.numEquipAmount.ValueChanged += new System.EventHandler(this.numEquipAmount_ValueChanged); - // - // lblPercent - // - this.lblPercent.Location = new System.Drawing.Point(208, 80); - this.lblPercent.Name = "lblPercent"; - this.lblPercent.Size = new System.Drawing.Size(16, 16); - this.lblPercent.TabIndex = 1; - this.lblPercent.Text = "%"; - this.lblPercent.Visible = false; - // // lblAmount // this.lblAmount.Location = new System.Drawing.Point(8, 80); @@ -112,8 +88,9 @@ // this.bttnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.bttnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnCancel.Location = new System.Drawing.Point(160, 136); + this.bttnCancel.Location = new System.Drawing.Point(159, 184); this.bttnCancel.Name = "bttnCancel"; + this.bttnCancel.Size = new System.Drawing.Size(75, 23); this.bttnCancel.TabIndex = 3; this.bttnCancel.Text = "cancel"; this.bttnCancel.Click += new System.EventHandler(this.bttnCancel_Click); @@ -122,22 +99,13 @@ // this.bttnOkay.Enabled = false; this.bttnOkay.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnOkay.Location = new System.Drawing.Point(8, 136); + this.bttnOkay.Location = new System.Drawing.Point(11, 184); this.bttnOkay.Name = "bttnOkay"; + this.bttnOkay.Size = new System.Drawing.Size(75, 23); this.bttnOkay.TabIndex = 4; this.bttnOkay.Text = "okay"; this.bttnOkay.Click += new System.EventHandler(this.bttnOkay_Click); // - // cbEquipAll - // - this.cbEquipAll.Enabled = false; - this.cbEquipAll.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.cbEquipAll.Location = new System.Drawing.Point(88, 104); - this.cbEquipAll.Name = "cbEquipAll"; - this.cbEquipAll.TabIndex = 5; - this.cbEquipAll.Text = "equip all"; - this.cbEquipAll.CheckedChanged += new System.EventHandler(this.cbEquipAll_CheckedChanged); - // // lblItem // this.lblItem.Location = new System.Drawing.Point(0, 8); @@ -149,33 +117,35 @@ // // listItems // - this.listItems.Location = new System.Drawing.Point(88, 8); + this.listItems.Location = new System.Drawing.Point(86, 8); this.listItems.Name = "listItems"; this.listItems.Size = new System.Drawing.Size(144, 69); this.listItems.TabIndex = 7; this.listItems.SelectedIndexChanged += new System.EventHandler(this.listItems_SelectedIndexChanged); // + // equipmentAmount + // + this.equipmentAmount.Location = new System.Drawing.Point(86, 83); + this.equipmentAmount.Name = "equipmentAmount"; + this.equipmentAmount.Size = new System.Drawing.Size(155, 77); + this.equipmentAmount.TabIndex = 8; + // // FrmReplaceUnitEquipment // - this.AcceptButton = this.bttnOkay; this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); - this.CancelButton = this.bttnCancel; - this.ClientSize = new System.Drawing.Size(240, 164); + this.ClientSize = new System.Drawing.Size(246, 219); this.ControlBox = false; + this.Controls.Add(this.equipmentAmount); this.Controls.Add(this.listItems); this.Controls.Add(this.lblItem); - this.Controls.Add(this.cbEquipAll); this.Controls.Add(this.bttnOkay); this.Controls.Add(this.bttnCancel); this.Controls.Add(this.lblAmount); - this.Controls.Add(this.numEquipAmount); - this.Controls.Add(this.lblPercent); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.Name = "FrmReplaceUnitEquipment"; this.ShowInTaskbar = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "FrmEditUnitEquipment"; - ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).EndInit(); this.ResumeLayout(false); } @@ -183,27 +153,45 @@ private void bttnOkay_Click(object sender, System.EventArgs e) { - setValue(); + SetValue(); this.Close(); } - private void setValue() + private void SetValue() { UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem; + bool setValue = true; + double amount = equipmentAmount.EquipmentAmount; - if (cbEquipAll.Checked) + if (amount == 0) { - commandStack.Execute(new ReplaceUnitEquipmentWithNumericAmountItemCommand(unit, oldItem, equipItem, WarFoundryCore.INFINITY)); - } - else - { - if (equipItem.IsRatioLimit) + if (equipItem.IsRequired) { - commandStack.Execute(new ReplaceUnitEquipmentWithRatioAmountItemCommand(unit, oldItem, equipItem, (double)numEquipAmount.Value)); + 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); + setValue = false; } else { - commandStack.Execute(new ReplaceUnitEquipmentWithNumericAmountItemCommand(unit, oldItem, equipItem, (int)numEquipAmount.Value)); + DialogResult dr = MessageBox.Show(this, "This will remove the item from the unit. Continue?", "Confirm remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); + + if (dr != DialogResult.Yes) + { + setValue = false; + } + } + } + + double oldAmount = unit.GetEquipmentAmount(equipItem); + + if (setValue && oldAmount != amount) + { + if (equipmentAmount.IsRatioEquipmentAmount) + { + commandStack.Execute(new ReplaceUnitEquipmentWithRatioAmountItemCommand(unit, oldItem, equipItem, amount)); + } + else + { + commandStack.Execute(new ReplaceUnitEquipmentWithNumericAmountItemCommand(unit, oldItem, equipItem, (int)amount)); } } } @@ -213,61 +201,21 @@ this.Close(); } - private void cbEquipAll_CheckedChanged(object sender, System.EventArgs e) - { - numEquipAmount.Enabled = ((UnitEquipmentItem)listItems.SelectedItem).MinNumber != WarFoundryCore.INFINITY && !cbEquipAll.Checked; - setOkayButton(); - } - private void listItems_SelectedIndexChanged(object sender, System.EventArgs e) { - refreshNumber(); - setOkayButton(); + equipmentAmount.SetUnitEquipmentItem((UnitEquipmentItem)listItems.SelectedItem); + SetOkayButton(); } - private void refreshNumber() + private void SetOkayButton() { - if (listItems.SelectedIndex > -1) - { - UnitEquipmentItem equipItem = (UnitEquipmentItem)listItems.SelectedItem; - required = equipItem.IsRequired; - - if (equipItem.IsRatioLimit) - { - numEquipAmount.Minimum = (decimal)Math.Round(equipItem.MinNumber * 100.0, 2); - numEquipAmount.Maximum = (decimal)Math.Round(equipItem.MaxNumber * 100.0, 2); - numEquipAmount.Value = numEquipAmount.Minimum; - cbEquipAll.Enabled = false; - lblPercent.Visible = true; - numEquipAmount.Width = 120; - } - else - { - numEquipAmount.Minimum = (decimal)(equipItem.MinNumber != WarFoundryCore.INFINITY ? equipItem.MinNumber : unit.Size); - numEquipAmount.Maximum = (decimal)(equipItem.MaxNumber != WarFoundryCore.INFINITY ? equipItem.MaxNumber : unit.Size); - numEquipAmount.Value = numEquipAmount.Minimum; - cbEquipAll.Enabled = (equipItem.MaxNumber == WarFoundryCore.INFINITY && equipItem.MinNumber != WarFoundryCore.INFINITY); - cbEquipAll.Checked = equipItem.MinNumber == WarFoundryCore.INFINITY; - numEquipAmount.Width = 144; - } - } - else - { - numEquipAmount.Minimum = 0; - numEquipAmount.Value = 0; - numEquipAmount.Enabled = false; - cbEquipAll.Enabled = false; - } - } - - private void setOkayButton() - { - bttnOkay.Enabled = listItems.SelectedIndex > -1 && (cbEquipAll.Checked || (numEquipAmount.Enabled && numEquipAmount.Value > 0)); + double equipAmount = equipmentAmount.EquipmentAmount; + bttnOkay.Enabled = equipAmount > 0 || equipAmount == WarFoundryCore.INFINITY || !((UnitEquipmentItem)listItems.SelectedItem).IsRequired; } private void numEquipAmount_ValueChanged(object sender, System.EventArgs e) { - setOkayButton(); + SetOkayButton(); } } }
--- a/FrmReplaceUnitEquipment.resx Sun Sep 13 17:33:36 2009 +0000 +++ b/FrmReplaceUnitEquipment.resx Sun Sep 13 18:51:39 2009 +0000 @@ -3,7 +3,7 @@ <!-- Microsoft ResX Schema - Version 1.3 + Version 2.0 The primary goals of this format is to allow a simple XML format that is mostly human readable. The generation and parsing of the @@ -14,16 +14,17 @@ ... ado.net/XML headers & schema ... <resheader name="resmimetype">text/microsoft-resx</resheader> - <resheader name="version">1.3</resheader> + <resheader name="version">2.0</resheader> <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> - <data name="Name1">this is my long string</data> + <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> - [base64 mime encoded serialized .NET Framework object] + <value>[base64 mime encoded serialized .NET Framework object]</value> </data> <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> - [base64 mime encoded string representing a byte array form of the .NET Framework object] + <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> + <comment>This is a comment</comment> </data> There are any number of "resheader" rows that contain simple @@ -35,7 +36,7 @@ Classes that don't support this are serialized and stored with the mimetype set. - The mimetype is used forserialized objects, and tells the + The mimetype is used for serialized objects, and tells the ResXResourceReader how to depersist the object. This is currently not extensible. For a given mimetype the value must be set accordingly: @@ -45,7 +46,7 @@ mimetype: application/x-microsoft.net.object.binary.base64 value : The object must be serialized with - : System.Serialization.Formatters.Binary.BinaryFormatter + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.soap.base64 @@ -59,18 +60,37 @@ : and then encoded with base64 encoding. --> <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> + <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> <xsd:element name="root" msdata:IsDataSet="true"> <xsd:complexType> <xsd:choice maxOccurs="unbounded"> + <xsd:element name="metadata"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" /> + </xsd:sequence> + <xsd:attribute name="name" use="required" type="xsd:string" /> + <xsd:attribute name="type" type="xsd:string" /> + <xsd:attribute name="mimetype" type="xsd:string" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="assembly"> + <xsd:complexType> + <xsd:attribute name="alias" type="xsd:string" /> + <xsd:attribute name="name" type="xsd:string" /> + </xsd:complexType> + </xsd:element> <xsd:element name="data"> <xsd:complexType> <xsd:sequence> <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> </xsd:sequence> - <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" /> + <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> + <xsd:attribute ref="xml:space" /> </xsd:complexType> </xsd:element> <xsd:element name="resheader"> @@ -89,114 +109,12 @@ <value>text/microsoft-resx</value> </resheader> <resheader name="version"> - <value>1.3</value> + <value>2.0</value> </resheader> <resheader name="reader"> - <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> </resheader> <resheader name="writer"> - <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> </resheader> - <data name="numEquipAmount.Locked" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>False</value> - </data> - <data name="numEquipAmount.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>Private</value> - </data> - <data name="numEquipAmount.Modifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>Private</value> - </data> - <data name="lblPercent.Locked" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>False</value> - </data> - <data name="lblPercent.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>Private</value> - </data> - <data name="lblPercent.Modifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>Private</value> - </data> - <data name="lblAmount.Locked" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>False</value> - </data> - <data name="lblAmount.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>Private</value> - </data> - <data name="lblAmount.Modifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>Private</value> - </data> - <data name="bttnCancel.Locked" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>False</value> - </data> - <data name="bttnCancel.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>Private</value> - </data> - <data name="bttnCancel.Modifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>Private</value> - </data> - <data name="bttnOkay.Locked" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>False</value> - </data> - <data name="bttnOkay.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>Private</value> - </data> - <data name="bttnOkay.Modifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>Private</value> - </data> - <data name="cbEquipAll.Locked" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>False</value> - </data> - <data name="cbEquipAll.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>Private</value> - </data> - <data name="cbEquipAll.Modifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>Private</value> - </data> - <data name="lblItem.Locked" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>False</value> - </data> - <data name="lblItem.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>Private</value> - </data> - <data name="lblItem.Modifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>Private</value> - </data> - <data name="listItems.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>Private</value> - </data> - <data name="listItems.Locked" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>False</value> - </data> - <data name="listItems.Modifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>Private</value> - </data> - <data name="$this.Locked" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>False</value> - </data> - <data name="$this.Language" type="System.Globalization.CultureInfo, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>(Default)</value> - </data> - <data name="$this.TrayLargeIcon" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>False</value> - </data> - <data name="$this.Localizable" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>False</value> - </data> - <data name="$this.GridSize" type="System.Drawing.Size, System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> - <value>8, 8</value> - </data> - <data name="$this.DrawGrid" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>True</value> - </data> - <data name="$this.TrayHeight" type="System.Int32, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>80</value> - </data> - <data name="$this.SnapToGrid" type="System.Boolean, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>True</value> - </data> - <data name="$this.DefaultModifiers" type="System.CodeDom.MemberAttributes, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> - <value>Private</value> - </data> - <data name="$this.Name"> - <value>FrmReplaceUnitEquipment</value> - </data> </root> \ No newline at end of file