Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.WinForms
changeset 43:7ace7d2249ac
Fixes #117: Add percentage and number boxes to equipment item dialogs
* Add value changing when changing radio button selection
* Add logic to equipment amount editing control to perform value setting (but see #146)
Also, fixes #114 by rebuilding everything in to a single control
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 07 Sep 2009 20:10:40 +0000 |
parents | d06c2e390a14 |
children | 1486ccd744dc |
files | FrmEditUnitEquipment.cs UI/EquipmentAmountControl.Designer.cs UI/EquipmentAmountControl.cs |
diffstat | 3 files changed, 51 insertions(+), 47 deletions(-) [+] |
line wrap: on
line diff
--- a/FrmEditUnitEquipment.cs Sun Sep 06 19:58:39 2009 +0000 +++ b/FrmEditUnitEquipment.cs Mon Sep 07 20:10:40 2009 +0000 @@ -134,53 +134,50 @@ private void bttnOkay_Click(object sender, System.EventArgs e) { - if (setValue()) + if (SetValue()) { this.Close(); } } - private bool setValue() + private bool SetValue() { - 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); + bool setValue = true; + double amount = equipmentAmount.EquipmentAmount; - // if (dr!=DialogResult.Yes) - // { - // return false; - // } - // } - //} + if (amount == 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); + setValue = 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 (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 (dr != DialogResult.Yes) + { + setValue = false; + } + } + } + + double oldAmount = unit.GetEquipmentAmount(equipItem); - //return true; + if (setValue && oldAmount != amount) + { + if (equipmentAmount.IsRatioEquipmentAmount) + { + commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, amount)); + } + else + { + commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int)amount)); + } + } + + return setValue; } private void bttnCancel_Click(object sender, System.EventArgs e) @@ -190,7 +187,7 @@ private void setOkayButton() { - double equipAmount = 0;// equipmentAmount.EquipmentAmount; + double equipAmount = equipmentAmount.EquipmentAmount; bttnOkay.Enabled = equipAmount > 0 || equipAmount == WarFoundryCore.INFINITY || !equipItem.IsRequired; }
--- a/UI/EquipmentAmountControl.Designer.cs Sun Sep 06 19:58:39 2009 +0000 +++ b/UI/EquipmentAmountControl.Designer.cs Mon Sep 07 20:10:40 2009 +0000 @@ -34,8 +34,8 @@ this.numeric = new System.Windows.Forms.NumericUpDown(); this.percentage = new System.Windows.Forms.NumericUpDown(); this.lblPercentSign = new System.Windows.Forms.Label(); - ((System.ComponentModel.ISupportInitialize) (this.numeric)).BeginInit(); - ((System.ComponentModel.ISupportInitialize) (this.percentage)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numeric)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.percentage)).BeginInit(); this.SuspendLayout(); // // rbNumeric @@ -48,6 +48,7 @@ this.rbNumeric.TabIndex = 0; this.rbNumeric.TabStop = true; this.rbNumeric.UseVisualStyleBackColor = true; + this.rbNumeric.CheckedChanged += new System.EventHandler(this.radioCheckedChanged); // // rbPercentage // @@ -59,6 +60,7 @@ this.rbPercentage.TabIndex = 1; this.rbPercentage.TabStop = true; this.rbPercentage.UseVisualStyleBackColor = true; + this.rbPercentage.CheckedChanged += new System.EventHandler(this.radioCheckedChanged); // // rbEquipAll // @@ -113,8 +115,8 @@ this.Controls.Add(this.rbNumeric); this.Name = "EquipmentAmountControl"; this.Size = new System.Drawing.Size(155, 77); - ((System.ComponentModel.ISupportInitialize) (this.numeric)).EndInit(); - ((System.ComponentModel.ISupportInitialize) (this.percentage)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numeric)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.percentage)).EndInit(); this.ResumeLayout(false); this.PerformLayout();
--- a/UI/EquipmentAmountControl.cs Sun Sep 06 19:58:39 2009 +0000 +++ b/UI/EquipmentAmountControl.cs Mon Sep 07 20:10:40 2009 +0000 @@ -125,13 +125,13 @@ percentage.Value = 100; } - OnValueChanged(); + radioCheckedChanged(sender, e); } private void percentage_ValueChanged(object sender, EventArgs e) { SetNumericValueFromPercentage(); - rbEquipAll.Checked = (percentage.Value == 100); + rbEquipAll.Checked = (percentage.Value == 100 && !rbNumeric.Checked); OnValueChanged(); } @@ -184,9 +184,9 @@ { val = (double) numeric.Value; } - else if (rbPercentage.Enabled) + else if (rbPercentage.Checked) { - val = (double) percentage.Value / 100.0; + val = (double) percentage.Value; } else if (rbEquipAll.Checked) { @@ -224,5 +224,10 @@ numeric.Value = (int)equipAmountNum; } } + + private void radioCheckedChanged(object sender, EventArgs e) + { + OnValueChanged(); + } } }