Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.WinForms
changeset 42:d06c2e390a14
Re #117: Add percentage and number boxes to equipment item dialogs
* Add new widget to "Edit equipment" dialog
* Still needs "OK" button functionality re-implementing
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 06 Sep 2009 19:58:39 +0000 |
parents | 4fc87d6e6119 |
children | 7ace7d2249ac |
files | FrmEditUnitEquipment.cs FrmEditUnitEquipment.resx UI/EquipmentAmountControl.cs |
diffstat | 3 files changed, 105 insertions(+), 203 deletions(-) [+] |
line wrap: on
line diff
--- a/FrmEditUnitEquipment.cs Sun Sep 06 19:31:49 2009 +0000 +++ b/FrmEditUnitEquipment.cs Sun Sep 06 19:58:39 2009 +0000 @@ -12,7 +12,7 @@ using IBBoard.WarFoundry.API.Commands; using IBBoard.WarFoundry.API.Objects; -namespace IBBoard.WarFoundry +namespace IBBoard.WarFoundry.GUI.WinForms { /// <summary> /// Summary description for FrmEditUnitEquipment. @@ -21,15 +21,11 @@ { private Unit unit; private UnitEquipmentItem equipItem; - private double equipAmount; 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 IBBoard.WarFoundry.GUI.WinForms.UI.EquipmentAmountControl equipmentAmount; /// <summary> /// Required designer variable. /// </summary> @@ -42,28 +38,9 @@ this.equipItem = equipItem; InitializeComponent(); this.Text = equipItem.Name + " for " + unit.Name; - equipAmount = unit.GetEquipmentAmount(equipItem); - - if (equipItem.IsRatioLimit) - { - numEquipAmount.Minimum = (decimal)Math.Round(equipItem.MinPercentage, 2); - numEquipAmount.Maximum = (decimal)Math.Round(equipItem.MaxPercentage, 2); - numEquipAmount.Value = (decimal)Math.Round(equipAmount, 2); - 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 = (decimal)(equipAmount == WarFoundryCore.INFINITY ? unit.Size : equipAmount); - cbEquipAll.Checked = (equipAmount == WarFoundryCore.INFINITY); - cbEquipAll.Enabled = (equipItem.MaxNumber == WarFoundryCore.INFINITY && equipItem.MinNumber != WarFoundryCore.INFINITY); - numEquipAmount.Enabled = !cbEquipAll.Checked && equipItem.MinNumber != WarFoundryCore.INFINITY; - numEquipAmount.Width = 144; - } - + equipmentAmount.SetUnit(unit); + equipmentAmount.SetUnitEquipmentItem(equipItem); + equipmentAmount.SetUnitEquipmentItemAmount(unit.GetEquipmentAmount(equipItem), unit.GetEquipmentAmountIsRatio(equipItem)); bttnOkay.Enabled = false; } @@ -89,32 +66,12 @@ /// </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(); - ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).BeginInit(); + this.equipmentAmount = new IBBoard.WarFoundry.GUI.WinForms.UI.EquipmentAmountControl(); this.SuspendLayout(); // - // numEquipAmount - // - this.numEquipAmount.Location = new System.Drawing.Point(88, 8); - 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, 8); - 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, 8); @@ -128,8 +85,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, 64); + this.bttnCancel.Location = new System.Drawing.Point(153, 95); 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); @@ -138,41 +96,37 @@ // this.bttnOkay.Enabled = false; this.bttnOkay.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnOkay.Location = new System.Drawing.Point(8, 64); + this.bttnOkay.Location = new System.Drawing.Point(12, 95); 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 + // equipmentAmount // - this.cbEquipAll.Enabled = false; - this.cbEquipAll.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.cbEquipAll.Location = new System.Drawing.Point(88, 32); - this.cbEquipAll.Name = "cbEquipAll"; - this.cbEquipAll.TabIndex = 5; - this.cbEquipAll.Text = "equip all"; - this.cbEquipAll.CheckedChanged += new System.EventHandler(this.cbEquipAll_CheckedChanged); + this.equipmentAmount.Location = new System.Drawing.Point(88, 5); + this.equipmentAmount.Name = "equipmentAmount"; + this.equipmentAmount.Size = new System.Drawing.Size(155, 77); + this.equipmentAmount.TabIndex = 5; + this.equipmentAmount.ValueChanged += new System.EventHandler(this.equipmentAmount_ValueChanged); // // FrmEditUnitEquipment // this.AcceptButton = this.bttnOkay; this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.CancelButton = this.bttnCancel; - this.ClientSize = new System.Drawing.Size(240, 92); + this.ClientSize = new System.Drawing.Size(240, 130); this.ControlBox = false; - this.Controls.Add(this.cbEquipAll); + this.Controls.Add(this.equipmentAmount); 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 = "FrmEditUnitEquipment"; this.ShowInTaskbar = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "FrmEditUnitEquipment"; - ((System.ComponentModel.ISupportInitialize)(this.numEquipAmount)).EndInit(); this.ResumeLayout(false); } @@ -188,44 +142,45 @@ private bool setValue() { - if ((!numEquipAmount.Enabled || numEquipAmount.Value == 0) && !cbEquipAll.Checked && unit.GetEquipmentAmount(equipItem) != 0) - { - if (equipItem.IsRequired) - { - 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); - return false; - } - else - { - DialogResult dr = MessageBox.Show(this, "This will remove the item from the unit. Continue?", "Confirm remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); + return false; + //if (!bttnOkay.Enabled) + //{ + // if (equipItem.IsRequired) + // { + // 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); + // return false; + // } + // else + // { + // 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) - { - return false; - } - } - } + // if (dr!=DialogResult.Yes) + // { + // return false; + // } + // } + //} - if (cbEquipAll.Checked) - { - if (equipAmount != WarFoundryCore.INFINITY) - { - commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, WarFoundryCore.INFINITY)); - } - } - else if (numEquipAmount.Value != (decimal)equipAmount) - { - if (equipItem.IsRatioLimit) - { - commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, (double)numEquipAmount.Value)); - } - else - { - commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int)numEquipAmount.Value)); - } - } + //if (cbEquipAll.Checked) + //{ + // if (equipAmount != WarFoundryCore.INFINITY) + // { + // commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, WarFoundryCore.INFINITY)); + // } + //} + //else if (numEquipAmount.Value != (decimal)equipAmount) + //{ + // if (equipItem.IsRatioLimit) + // { + // commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, (double)numEquipAmount.Value)); + // } + // else + // { + // commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int)numEquipAmount.Value)); + // } + //} - return true; + //return true; } private void bttnCancel_Click(object sender, System.EventArgs e) @@ -233,18 +188,13 @@ this.Close(); } - private void cbEquipAll_CheckedChanged(object sender, System.EventArgs e) + private void setOkayButton() { - numEquipAmount.Enabled = !cbEquipAll.Checked && equipItem.MinNumber != WarFoundryCore.INFINITY; - setOkayButton(); + double equipAmount = 0;// equipmentAmount.EquipmentAmount; + bttnOkay.Enabled = equipAmount > 0 || equipAmount == WarFoundryCore.INFINITY || !equipItem.IsRequired; } - private void setOkayButton() - { - bttnOkay.Enabled = (cbEquipAll.Checked || (numEquipAmount.Enabled && (numEquipAmount.Value > 0 || !equipItem.IsRequired))); - } - - private void numEquipAmount_ValueChanged(object sender, System.EventArgs e) + private void equipmentAmount_ValueChanged(object sender, EventArgs e) { setOkayButton(); }
--- a/FrmEditUnitEquipment.resx Sun Sep 06 19:31:49 2009 +0000 +++ b/FrmEditUnitEquipment.resx Sun Sep 06 19:58: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,96 +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="$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>FrmEditUnitEquipment</value> - </data> </root> \ No newline at end of file
--- a/UI/EquipmentAmountControl.cs Sun Sep 06 19:31:49 2009 +0000 +++ b/UI/EquipmentAmountControl.cs Sun Sep 06 19:58:39 2009 +0000 @@ -208,5 +208,21 @@ return rbPercentage.Checked; } } + + public void SetUnitEquipmentItemAmount(double equipAmountNum, bool isRatio) + { + if (isRatio) + { + percentage.Value = (decimal)equipAmountNum; + } + else if (equipAmountNum == WarFoundryCore.INFINITY) + { + rbEquipAll.Checked = true; + } + else + { + numeric.Value = (int)equipAmountNum; + } + } } }