Mercurial > repos > IBBoard.WarFoundry.GUI.WinForms
changeset 60:c283545d2d0b
Re #168: Combine "required" and "optional" equipment boxes
* Alter "Unit" form to have a single weapon section
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 19 Sep 2009 13:57:35 +0000 |
parents | 039b02006a8a |
children | a0ec03c24cd9 |
files | FrmUnit.cs IBBoard.WarFoundry.GUI.WinForms.csproj |
diffstat | 2 files changed, 89 insertions(+), 123 deletions(-) [+] |
line wrap: on
line diff
--- a/FrmUnit.cs Sat Sep 19 13:56:55 2009 +0000 +++ b/FrmUnit.cs Sat Sep 19 13:57:35 2009 +0000 @@ -33,13 +33,10 @@ private System.Windows.Forms.Label lblUnitSize; private System.Windows.Forms.Button bttnAddWeapon; private System.Windows.Forms.Button bttnRemoveWeapon; + private System.Windows.Forms.Label lblEquip; + private System.Windows.Forms.ListBox equipmentList; + private System.Windows.Forms.Button bttnReplaceWeapon; private System.Windows.Forms.Button bttnEditWeapon; - private System.Windows.Forms.Label lblRequiredEquip; - private System.Windows.Forms.ListBox reqdList; - private System.Windows.Forms.ListBox optList; - private System.Windows.Forms.Label lblOptionalEquip; - private System.Windows.Forms.Button bttnReplaceWeapon; - private System.Windows.Forms.Button bttnEditReqdWeapon; private Label lblPoints; /// <summary> /// Required designer variable. @@ -137,14 +134,7 @@ { foreach (UnitEquipmentItem item in unit.GetEquipment()) { - if (item.IsRequired) - { - reqdList.Items.Add(GetEquipmentChoice(item)); - } - else - { - optList.Items.Add(GetEquipmentChoice(item)); - } + equipmentList.Items.Add(GetEquipmentChoice(item)); } } @@ -192,15 +182,12 @@ this.tbUnitName = new System.Windows.Forms.TextBox(); this.unitSize = new System.Windows.Forms.NumericUpDown(); this.lblUnitSize = new System.Windows.Forms.Label(); - this.lblRequiredEquip = new System.Windows.Forms.Label(); + this.lblEquip = new System.Windows.Forms.Label(); this.bttnAddWeapon = new System.Windows.Forms.Button(); this.bttnRemoveWeapon = new System.Windows.Forms.Button(); - this.reqdList = new System.Windows.Forms.ListBox(); + this.equipmentList = new System.Windows.Forms.ListBox(); + this.bttnReplaceWeapon = new System.Windows.Forms.Button(); this.bttnEditWeapon = new System.Windows.Forms.Button(); - this.optList = new System.Windows.Forms.ListBox(); - this.lblOptionalEquip = new System.Windows.Forms.Label(); - this.bttnReplaceWeapon = new System.Windows.Forms.Button(); - this.bttnEditReqdWeapon = new System.Windows.Forms.Button(); this.lblPoints = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize) (this.statsGrid)).BeginInit(); ((System.ComponentModel.ISupportInitialize) (this.unitSize)).BeginInit(); @@ -265,20 +252,20 @@ this.lblUnitSize.Text = "unit size"; this.lblUnitSize.TextAlign = System.Drawing.ContentAlignment.TopRight; // - // lblRequiredEquip + // lblEquip // - this.lblRequiredEquip.Location = new System.Drawing.Point(8, 128); - this.lblRequiredEquip.Name = "lblRequiredEquip"; - this.lblRequiredEquip.Size = new System.Drawing.Size(88, 32); - this.lblRequiredEquip.TabIndex = 3; - this.lblRequiredEquip.Text = "reqd equipment"; - this.lblRequiredEquip.TextAlign = System.Drawing.ContentAlignment.TopRight; + this.lblEquip.Location = new System.Drawing.Point(8, 123); + this.lblEquip.Name = "lblEquip"; + this.lblEquip.Size = new System.Drawing.Size(88, 32); + this.lblEquip.TabIndex = 3; + this.lblEquip.Text = "equipment"; + this.lblEquip.TextAlign = System.Drawing.ContentAlignment.TopRight; // // bttnAddWeapon // this.bttnAddWeapon.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.bttnAddWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnAddWeapon.Location = new System.Drawing.Point(520, 200); + this.bttnAddWeapon.Location = new System.Drawing.Point(516, 126); this.bttnAddWeapon.Name = "bttnAddWeapon"; this.bttnAddWeapon.Size = new System.Drawing.Size(88, 22); this.bttnAddWeapon.TabIndex = 4; @@ -290,101 +277,67 @@ this.bttnRemoveWeapon.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.bttnRemoveWeapon.Enabled = false; this.bttnRemoveWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnRemoveWeapon.Location = new System.Drawing.Point(520, 248); + this.bttnRemoveWeapon.Location = new System.Drawing.Point(516, 210); this.bttnRemoveWeapon.Name = "bttnRemoveWeapon"; this.bttnRemoveWeapon.Size = new System.Drawing.Size(88, 22); this.bttnRemoveWeapon.TabIndex = 5; this.bttnRemoveWeapon.Text = "remove"; this.bttnRemoveWeapon.Click += new System.EventHandler(this.bttnRemoveWeapon_Click); // - // reqdList + // equipmentList // - this.reqdList.Anchor = ((System.Windows.Forms.AnchorStyles) (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + this.equipmentList.Anchor = ((System.Windows.Forms.AnchorStyles) (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.reqdList.Location = new System.Drawing.Point(104, 128); - this.reqdList.Name = "reqdList"; - this.reqdList.Size = new System.Drawing.Size(408, 69); - this.reqdList.TabIndex = 6; - this.reqdList.DoubleClick += new System.EventHandler(this.reqdList_DoubleClick); - this.reqdList.SelectedIndexChanged += new System.EventHandler(this.reqdList_SelectedIndexChanged); + this.equipmentList.Location = new System.Drawing.Point(102, 126); + this.equipmentList.Name = "equipmentList"; + this.equipmentList.Size = new System.Drawing.Size(408, 108); + this.equipmentList.TabIndex = 6; + this.equipmentList.DoubleClick += new System.EventHandler(this.equipmentList_DoubleClick); + this.equipmentList.SelectedIndexChanged += new System.EventHandler(this.equipmentList_SelectedIndexChanged); + // + // bttnReplaceWeapon + // + this.bttnReplaceWeapon.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.bttnReplaceWeapon.Enabled = false; + this.bttnReplaceWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.bttnReplaceWeapon.Location = new System.Drawing.Point(516, 182); + this.bttnReplaceWeapon.Name = "bttnReplaceWeapon"; + this.bttnReplaceWeapon.Size = new System.Drawing.Size(88, 22); + this.bttnReplaceWeapon.TabIndex = 10; + this.bttnReplaceWeapon.Text = "replace"; + this.bttnReplaceWeapon.Click += new System.EventHandler(this.bttnReplaceWeapon_Click); // // bttnEditWeapon // this.bttnEditWeapon.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.bttnEditWeapon.Enabled = false; this.bttnEditWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnEditWeapon.Location = new System.Drawing.Point(520, 224); + this.bttnEditWeapon.Location = new System.Drawing.Point(516, 154); this.bttnEditWeapon.Name = "bttnEditWeapon"; this.bttnEditWeapon.Size = new System.Drawing.Size(88, 22); - this.bttnEditWeapon.TabIndex = 7; + this.bttnEditWeapon.TabIndex = 11; this.bttnEditWeapon.Text = "edit"; this.bttnEditWeapon.Click += new System.EventHandler(this.bttnEditWeapon_Click); // - // optList - // - this.optList.Anchor = ((System.Windows.Forms.AnchorStyles) (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.optList.Location = new System.Drawing.Point(104, 200); - this.optList.Name = "optList"; - this.optList.Size = new System.Drawing.Size(408, 69); - this.optList.TabIndex = 9; - this.optList.DoubleClick += new System.EventHandler(this.optList_DoubleClick); - this.optList.SelectedIndexChanged += new System.EventHandler(this.optList_SelectedIndexChanged); - // - // lblOptionalEquip - // - this.lblOptionalEquip.Location = new System.Drawing.Point(8, 200); - this.lblOptionalEquip.Name = "lblOptionalEquip"; - this.lblOptionalEquip.Size = new System.Drawing.Size(88, 32); - this.lblOptionalEquip.TabIndex = 8; - this.lblOptionalEquip.Text = "opt equipment"; - this.lblOptionalEquip.TextAlign = System.Drawing.ContentAlignment.TopRight; - // - // bttnReplaceWeapon - // - this.bttnReplaceWeapon.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.bttnReplaceWeapon.Enabled = false; - this.bttnReplaceWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnReplaceWeapon.Location = new System.Drawing.Point(520, 128); - this.bttnReplaceWeapon.Name = "bttnReplaceWeapon"; - this.bttnReplaceWeapon.Size = new System.Drawing.Size(88, 22); - this.bttnReplaceWeapon.TabIndex = 10; - this.bttnReplaceWeapon.Text = "replace"; - this.bttnReplaceWeapon.Click += new System.EventHandler(this.bttnReplaceWeapon_Click); - // - // bttnEditReqdWeapon - // - this.bttnEditReqdWeapon.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.bttnEditReqdWeapon.Enabled = false; - this.bttnEditReqdWeapon.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.bttnEditReqdWeapon.Location = new System.Drawing.Point(520, 152); - this.bttnEditReqdWeapon.Name = "bttnEditReqdWeapon"; - this.bttnEditReqdWeapon.Size = new System.Drawing.Size(88, 22); - this.bttnEditReqdWeapon.TabIndex = 11; - this.bttnEditReqdWeapon.Text = "edit"; - this.bttnEditReqdWeapon.Click += new System.EventHandler(this.bttnEditReqdWeapon_Click); - // // lblPoints // this.lblPoints.Location = new System.Drawing.Point(358, 8); this.lblPoints.Name = "lblPoints"; this.lblPoints.Size = new System.Drawing.Size(88, 21); this.lblPoints.TabIndex = 12; + this.lblPoints.Text = "(points)"; // // FrmUnit // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(616, 314); this.Controls.Add(this.lblPoints); - this.Controls.Add(this.bttnEditReqdWeapon); + this.Controls.Add(this.bttnEditWeapon); this.Controls.Add(this.bttnReplaceWeapon); - this.Controls.Add(this.optList); - this.Controls.Add(this.lblOptionalEquip); - this.Controls.Add(this.bttnEditWeapon); - this.Controls.Add(this.reqdList); + this.Controls.Add(this.equipmentList); this.Controls.Add(this.bttnRemoveWeapon); this.Controls.Add(this.bttnAddWeapon); - this.Controls.Add(this.lblRequiredEquip); + this.Controls.Add(this.lblEquip); this.Controls.Add(this.lblUnitSize); this.Controls.Add(this.unitSize); this.Controls.Add(this.tbUnitName); @@ -466,16 +419,18 @@ } } - private void reqdList_SelectedIndexChanged(object sender, System.EventArgs e) + private void equipmentList_SelectedIndexChanged(object sender, System.EventArgs e) { - bttnReplaceWeapon.Enabled = (reqdList.SelectedIndex > -1 && ((UnitEquipmentChoice) reqdList.SelectedItem).Item.HasAlternatives()); - bttnEditReqdWeapon.Enabled = (reqdList.SelectedIndex > -1); + SetButtonsEnabledState(); } - private void optList_SelectedIndexChanged(object sender, System.EventArgs e) + private void SetButtonsEnabledState() { - bttnEditWeapon.Enabled = optList.SelectedIndex > -1; - bttnRemoveWeapon.Enabled = bttnEditWeapon.Enabled; + + UnitEquipmentItem equipItem = GetSelectedUnitEquipmentItem(); + bttnReplaceWeapon.Enabled = (equipItem != null && equipItem.HasAlternatives()); + bttnEditWeapon.Enabled = (equipItem != null); + bttnRemoveWeapon.Enabled = (equipItem != null && !equipItem.IsRequired); } private void unit_UnitEquipmentAmountChanged(WarFoundryObject obj, double oldValue, double newValue) @@ -483,51 +438,63 @@ if (obj is UnitEquipmentItem) { UnitEquipmentItem equip = (UnitEquipmentItem) obj; - ListBox weaponList = (equip.IsRequired ? reqdList : optList); + UnitEquipmentChoice equipChoice = GetEquipmentChoice(equip); if (newValue == 0) { - weaponList.Items.Remove(GetEquipmentChoice(equip)); + equipmentList.Items.Remove(equipChoice); } else { - UnitEquipmentChoice equipObj = GetEquipmentChoice(equip); - int idx = weaponList.Items.IndexOf(equipObj); + int idx = equipmentList.Items.IndexOf(equipChoice); if (idx > -1) { - weaponList.Items[idx] = equipObj; + equipmentList.Items[idx] = equipChoice; } else { - weaponList.Items.Add(equipObj); + equipmentList.Items.Add(equipChoice); } } } } - private void editWeapon(ListBox list) + private void EditWeapon() + { + FrmEditUnitEquipment editEquip = new FrmEditUnitEquipment(Unit, GetSelectedUnitEquipmentItem(), commandStack); + editEquip.ShowDialog(this); + } + + private UnitEquipmentItem GetSelectedUnitEquipmentItem() { - FrmEditUnitEquipment editEquip = new FrmEditUnitEquipment(Unit, ((UnitEquipmentChoice) list.SelectedItem).Item, commandStack); - editEquip.ShowDialog(this); + UnitEquipmentChoice selectedItem = GetSelectedUnitEquipmentChoice(); + UnitEquipmentItem equipItem = null; + + if (selectedItem!=null) + { + equipItem = selectedItem.Item; + } + + return equipItem; + } + + private UnitEquipmentChoice GetSelectedUnitEquipmentChoice() + { + return (UnitEquipmentChoice) equipmentList.SelectedItem; } private void bttnEditWeapon_Click(object sender, System.EventArgs e) { - editWeapon(optList); + EditWeapon(); } - private void optList_DoubleClick(object sender, System.EventArgs e) + private void equipmentList_DoubleClick(object sender, System.EventArgs e) { - editWeapon(optList); + EditWeapon(); } - private void reqdList_DoubleClick(object sender, System.EventArgs e) - { - editWeapon(reqdList); - } - - private void addWeapon() + private void AddWeapon() { FrmNewUnitEquipment newEquip = new FrmNewUnitEquipment(Unit, commandStack); newEquip.ShowDialog(this); @@ -535,27 +502,22 @@ private void bttnAddWeapon_Click(object sender, System.EventArgs e) { - addWeapon(); + AddWeapon(); } - private void removeWeapon() + private void RemoveWeapon() { - commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, ((UnitEquipmentChoice) optList.SelectedItem).Item, 0)); + commandStack.Execute(new SetUnitEquipmentNumericAmountCommand(unit, GetSelectedUnitEquipmentItem(), 0)); } private void bttnRemoveWeapon_Click(object sender, System.EventArgs e) { - removeWeapon(); - } - - private void bttnEditReqdWeapon_Click(object sender, System.EventArgs e) - { - editWeapon(reqdList); + RemoveWeapon(); } private void bttnReplaceWeapon_Click(object sender, System.EventArgs e) { - FrmReplaceUnitEquipment replace = new FrmReplaceUnitEquipment(unit, ((UnitEquipmentChoice) reqdList.SelectedItem).Item, commandStack); + FrmReplaceUnitEquipment replace = new FrmReplaceUnitEquipment(unit, GetSelectedUnitEquipmentItem(), commandStack); replace.ShowDialog(this); }
--- a/IBBoard.WarFoundry.GUI.WinForms.csproj Sat Sep 19 13:56:55 2009 +0000 +++ b/IBBoard.WarFoundry.GUI.WinForms.csproj Sat Sep 19 13:57:35 2009 +0000 @@ -151,6 +151,7 @@ <Compile Include="Util\UnitEquipmentChoice.cs" /> <EmbeddedResource Include="FrmArmyTree.resx"> <DependentUpon>FrmArmyTree.cs</DependentUpon> + <SubType>Designer</SubType> </EmbeddedResource> <EmbeddedResource Include="FrmEditUnitEquipment.resx"> <DependentUpon>FrmEditUnitEquipment.cs</DependentUpon> @@ -161,18 +162,21 @@ </EmbeddedResource> <EmbeddedResource Include="FrmNewArmy.resx"> <DependentUpon>FrmNewArmy.cs</DependentUpon> + <SubType>Designer</SubType> </EmbeddedResource> <EmbeddedResource Include="FrmNewUnit.resx"> <DependentUpon>FrmNewUnit.cs</DependentUpon> </EmbeddedResource> <EmbeddedResource Include="FrmNewUnitEquipment.resx"> <DependentUpon>FrmNewUnitEquipment.cs</DependentUpon> + <SubType>Designer</SubType> </EmbeddedResource> <EmbeddedResource Include="FrmReplaceUnitEquipment.resx"> <DependentUpon>FrmReplaceUnitEquipment.cs</DependentUpon> </EmbeddedResource> <EmbeddedResource Include="FrmUnit.resx"> <DependentUpon>FrmUnit.cs</DependentUpon> + <SubType>Designer</SubType> </EmbeddedResource> <EmbeddedResource Include="UI\EquipmentAmountControl.resx"> <SubType>Designer</SubType>