Mercurial > repos > 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 diff
1.1 --- a/FrmEditUnitEquipment.cs Sun Sep 06 19:58:39 2009 +0000 1.2 +++ b/FrmEditUnitEquipment.cs Mon Sep 07 20:10:40 2009 +0000 1.3 @@ -134,53 +134,50 @@ 1.4 1.5 private void bttnOkay_Click(object sender, System.EventArgs e) 1.6 { 1.7 - if (setValue()) 1.8 + if (SetValue()) 1.9 { 1.10 this.Close(); 1.11 } 1.12 } 1.13 1.14 - private bool setValue() 1.15 + private bool SetValue() 1.16 { 1.17 - return false; 1.18 - //if (!bttnOkay.Enabled) 1.19 - //{ 1.20 - // if (equipItem.IsRequired) 1.21 - // { 1.22 - // 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); 1.23 - // return false; 1.24 - // } 1.25 - // else 1.26 - // { 1.27 - // DialogResult dr = MessageBox.Show(this, "This will remove the item from the unit. Continue?", "Confirm remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); 1.28 + bool setValue = true; 1.29 + double amount = equipmentAmount.EquipmentAmount; 1.30 1.31 - // if (dr!=DialogResult.Yes) 1.32 - // { 1.33 - // return false; 1.34 - // } 1.35 - // } 1.36 - //} 1.37 + if (amount == 0) 1.38 + { 1.39 + if (equipItem.IsRequired) 1.40 + { 1.41 + 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); 1.42 + setValue = false; 1.43 + } 1.44 + else 1.45 + { 1.46 + DialogResult dr = MessageBox.Show(this, "This will remove the item from the unit. Continue?", "Confirm remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); 1.47 1.48 - //if (cbEquipAll.Checked) 1.49 - //{ 1.50 - // if (equipAmount != WarFoundryCore.INFINITY) 1.51 - // { 1.52 - // commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, WarFoundryCore.INFINITY)); 1.53 - // } 1.54 - //} 1.55 - //else if (numEquipAmount.Value != (decimal)equipAmount) 1.56 - //{ 1.57 - // if (equipItem.IsRatioLimit) 1.58 - // { 1.59 - // commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, (double)numEquipAmount.Value)); 1.60 - // } 1.61 - // else 1.62 - // { 1.63 - // commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int)numEquipAmount.Value)); 1.64 - // } 1.65 - //} 1.66 + if (dr != DialogResult.Yes) 1.67 + { 1.68 + setValue = false; 1.69 + } 1.70 + } 1.71 + } 1.72 1.73 - //return true; 1.74 + double oldAmount = unit.GetEquipmentAmount(equipItem); 1.75 + 1.76 + if (setValue && oldAmount != amount) 1.77 + { 1.78 + if (equipmentAmount.IsRatioEquipmentAmount) 1.79 + { 1.80 + commandStack.Execute(new SetUnitEquipmentRatioAmountCommand(unit, equipItem, amount)); 1.81 + } 1.82 + else 1.83 + { 1.84 + commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, equipItem, (int)amount)); 1.85 + } 1.86 + } 1.87 + 1.88 + return setValue; 1.89 } 1.90 1.91 private void bttnCancel_Click(object sender, System.EventArgs e) 1.92 @@ -190,7 +187,7 @@ 1.93 1.94 private void setOkayButton() 1.95 { 1.96 - double equipAmount = 0;// equipmentAmount.EquipmentAmount; 1.97 + double equipAmount = equipmentAmount.EquipmentAmount; 1.98 bttnOkay.Enabled = equipAmount > 0 || equipAmount == WarFoundryCore.INFINITY || !equipItem.IsRequired; 1.99 } 1.100
2.1 --- a/UI/EquipmentAmountControl.Designer.cs Sun Sep 06 19:58:39 2009 +0000 2.2 +++ b/UI/EquipmentAmountControl.Designer.cs Mon Sep 07 20:10:40 2009 +0000 2.3 @@ -34,8 +34,8 @@ 2.4 this.numeric = new System.Windows.Forms.NumericUpDown(); 2.5 this.percentage = new System.Windows.Forms.NumericUpDown(); 2.6 this.lblPercentSign = new System.Windows.Forms.Label(); 2.7 - ((System.ComponentModel.ISupportInitialize) (this.numeric)).BeginInit(); 2.8 - ((System.ComponentModel.ISupportInitialize) (this.percentage)).BeginInit(); 2.9 + ((System.ComponentModel.ISupportInitialize)(this.numeric)).BeginInit(); 2.10 + ((System.ComponentModel.ISupportInitialize)(this.percentage)).BeginInit(); 2.11 this.SuspendLayout(); 2.12 // 2.13 // rbNumeric 2.14 @@ -48,6 +48,7 @@ 2.15 this.rbNumeric.TabIndex = 0; 2.16 this.rbNumeric.TabStop = true; 2.17 this.rbNumeric.UseVisualStyleBackColor = true; 2.18 + this.rbNumeric.CheckedChanged += new System.EventHandler(this.radioCheckedChanged); 2.19 // 2.20 // rbPercentage 2.21 // 2.22 @@ -59,6 +60,7 @@ 2.23 this.rbPercentage.TabIndex = 1; 2.24 this.rbPercentage.TabStop = true; 2.25 this.rbPercentage.UseVisualStyleBackColor = true; 2.26 + this.rbPercentage.CheckedChanged += new System.EventHandler(this.radioCheckedChanged); 2.27 // 2.28 // rbEquipAll 2.29 // 2.30 @@ -113,8 +115,8 @@ 2.31 this.Controls.Add(this.rbNumeric); 2.32 this.Name = "EquipmentAmountControl"; 2.33 this.Size = new System.Drawing.Size(155, 77); 2.34 - ((System.ComponentModel.ISupportInitialize) (this.numeric)).EndInit(); 2.35 - ((System.ComponentModel.ISupportInitialize) (this.percentage)).EndInit(); 2.36 + ((System.ComponentModel.ISupportInitialize)(this.numeric)).EndInit(); 2.37 + ((System.ComponentModel.ISupportInitialize)(this.percentage)).EndInit(); 2.38 this.ResumeLayout(false); 2.39 this.PerformLayout(); 2.40
3.1 --- a/UI/EquipmentAmountControl.cs Sun Sep 06 19:58:39 2009 +0000 3.2 +++ b/UI/EquipmentAmountControl.cs Mon Sep 07 20:10:40 2009 +0000 3.3 @@ -125,13 +125,13 @@ 3.4 percentage.Value = 100; 3.5 } 3.6 3.7 - OnValueChanged(); 3.8 + radioCheckedChanged(sender, e); 3.9 } 3.10 3.11 private void percentage_ValueChanged(object sender, EventArgs e) 3.12 { 3.13 SetNumericValueFromPercentage(); 3.14 - rbEquipAll.Checked = (percentage.Value == 100); 3.15 + rbEquipAll.Checked = (percentage.Value == 100 && !rbNumeric.Checked); 3.16 OnValueChanged(); 3.17 } 3.18 3.19 @@ -184,9 +184,9 @@ 3.20 { 3.21 val = (double) numeric.Value; 3.22 } 3.23 - else if (rbPercentage.Enabled) 3.24 + else if (rbPercentage.Checked) 3.25 { 3.26 - val = (double) percentage.Value / 100.0; 3.27 + val = (double) percentage.Value; 3.28 } 3.29 else if (rbEquipAll.Checked) 3.30 { 3.31 @@ -224,5 +224,10 @@ 3.32 numeric.Value = (int)equipAmountNum; 3.33 } 3.34 } 3.35 + 3.36 + private void radioCheckedChanged(object sender, EventArgs e) 3.37 + { 3.38 + OnValueChanged(); 3.39 + } 3.40 } 3.41 }