From cd38eed36e75a33a563cc5b9a71dd4469973b3f6 Mon Sep 17 00:00:00 2001 From: Sour Date: Thu, 28 Dec 2017 18:15:25 -0500 Subject: [PATCH] Input: Fixed input config window issues --- .../Forms/Config/frmInputConfig.Designer.cs | 13 -- GUI.NET/Forms/Config/frmInputConfig.cs | 138 ++++++++++-------- 2 files changed, 79 insertions(+), 72 deletions(-) diff --git a/GUI.NET/Forms/Config/frmInputConfig.Designer.cs b/GUI.NET/Forms/Config/frmInputConfig.Designer.cs index 05a31235..a21ea0f2 100644 --- a/GUI.NET/Forms/Config/frmInputConfig.Designer.cs +++ b/GUI.NET/Forms/Config/frmInputConfig.Designer.cs @@ -167,7 +167,6 @@ this.btnSetupP4.Text = "Setup"; this.btnSetupP4.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; this.btnSetupP4.UseVisualStyleBackColor = true; - this.btnSetupP4.Click += new System.EventHandler(this.btnSetup_Click); // // btnSetupP3 // @@ -179,7 +178,6 @@ this.btnSetupP3.Text = "Setup"; this.btnSetupP3.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; this.btnSetupP3.UseVisualStyleBackColor = true; - this.btnSetupP3.Click += new System.EventHandler(this.btnSetup_Click); // // lblPlayer1 // @@ -210,7 +208,6 @@ this.cboPlayer4.Name = "cboPlayer4"; this.cboPlayer4.Size = new System.Drawing.Size(201, 21); this.cboPlayer4.TabIndex = 8; - this.cboPlayer4.SelectedIndexChanged += new System.EventHandler(this.cboPlayerController_SelectedIndexChanged); // // cboPlayer3 // @@ -221,7 +218,6 @@ this.cboPlayer3.Name = "cboPlayer3"; this.cboPlayer3.Size = new System.Drawing.Size(201, 21); this.cboPlayer3.TabIndex = 7; - this.cboPlayer3.SelectedIndexChanged += new System.EventHandler(this.cboPlayerController_SelectedIndexChanged); // // cboPlayer1 // @@ -232,7 +228,6 @@ this.cboPlayer1.Name = "cboPlayer1"; this.cboPlayer1.Size = new System.Drawing.Size(201, 21); this.cboPlayer1.TabIndex = 4; - this.cboPlayer1.SelectedIndexChanged += new System.EventHandler(this.cboPlayerController_SelectedIndexChanged); // // lblPlayer4 // @@ -253,7 +248,6 @@ this.cboPlayer2.Name = "cboPlayer2"; this.cboPlayer2.Size = new System.Drawing.Size(201, 21); this.cboPlayer2.TabIndex = 6; - this.cboPlayer2.SelectedIndexChanged += new System.EventHandler(this.cboPlayerController_SelectedIndexChanged); // // lblPlayer3 // @@ -275,7 +269,6 @@ this.btnSetupP1.Text = "Setup"; this.btnSetupP1.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; this.btnSetupP1.UseVisualStyleBackColor = true; - this.btnSetupP1.Click += new System.EventHandler(this.btnSetup_Click); // // btnSetupP2 // @@ -287,7 +280,6 @@ this.btnSetupP2.Text = "Setup"; this.btnSetupP2.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; this.btnSetupP2.UseVisualStyleBackColor = true; - this.btnSetupP2.Click += new System.EventHandler(this.btnSetup_Click); // // lblNesType // @@ -310,7 +302,6 @@ this.cboConsoleType.Name = "cboConsoleType"; this.cboConsoleType.Size = new System.Drawing.Size(109, 21); this.cboConsoleType.TabIndex = 14; - this.cboConsoleType.SelectedIndexChanged += new System.EventHandler(this.cboNesType_SelectedIndexChanged); // // lblExpansionPort // @@ -331,7 +322,6 @@ this.cboExpansionPort.Name = "cboExpansionPort"; this.cboExpansionPort.Size = new System.Drawing.Size(201, 21); this.cboExpansionPort.TabIndex = 17; - this.cboExpansionPort.SelectedIndexChanged += new System.EventHandler(this.cboExpansionPort_SelectedIndexChanged); // // chkFourScore // @@ -344,7 +334,6 @@ this.chkFourScore.TabIndex = 15; this.chkFourScore.Text = "Use Four Score accessory"; this.chkFourScore.UseVisualStyleBackColor = true; - this.chkFourScore.CheckedChanged += new System.EventHandler(this.chkFourScore_CheckedChanged); // // chkAutoConfigureInput // @@ -416,7 +405,6 @@ this.btnSetupExp.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; this.btnSetupExp.UseVisualStyleBackColor = true; this.btnSetupExp.Visible = false; - this.btnSetupExp.Click += new System.EventHandler(this.btnSetup_Click); // // lblCartridge // @@ -448,7 +436,6 @@ this.btnSetupCartridge.Text = "Setup"; this.btnSetupCartridge.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; this.btnSetupCartridge.UseVisualStyleBackColor = true; - this.btnSetupCartridge.Click += new System.EventHandler(this.btnSetupCartridge_Click); // // tpgAdvanced // diff --git a/GUI.NET/Forms/Config/frmInputConfig.cs b/GUI.NET/Forms/Config/frmInputConfig.cs index c2581760..54d88dd4 100644 --- a/GUI.NET/Forms/Config/frmInputConfig.cs +++ b/GUI.NET/Forms/Config/frmInputConfig.cs @@ -51,6 +51,22 @@ namespace Mesen.GUI.Forms.Config UpdateConflictWarning(); } + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + + btnSetupP1.Click += btnSetup_Click; + btnSetupP2.Click += btnSetup_Click; + btnSetupP3.Click += btnSetup_Click; + btnSetupP4.Click += btnSetup_Click; + + cboConsoleType.SelectedIndexChanged += cboNesType_SelectedIndexChanged; + cboExpansionPort.SelectedIndexChanged += cboExpansionPort_SelectedIndexChanged; + chkFourScore.CheckedChanged += chkFourScore_CheckedChanged; + btnSetupExp.Click += btnSetup_Click; + btnSetupCartridge.Click += btnSetupCartridge_Click; + } + private void UpdateCartridgeInputUi() { ConsoleFeatures features = InteropEmu.GetAvailableFeatures(); @@ -102,23 +118,28 @@ namespace Mesen.GUI.Forms.Config private void UpdateAvailableControllerTypes() { + cboPlayer1.SelectedIndexChanged -= cboPlayerController_SelectedIndexChanged; + cboPlayer2.SelectedIndexChanged -= cboPlayerController_SelectedIndexChanged; + cboPlayer3.SelectedIndexChanged -= cboPlayerController_SelectedIndexChanged; + cboPlayer4.SelectedIndexChanged -= cboPlayerController_SelectedIndexChanged; + bool isNes = ((InputInfo)Entity).ConsoleType == ConsoleType.Nes; bool p3and4visible = (isNes && chkFourScore.Checked) || (!isNes && ((InputInfo)Entity).ExpansionPortDevice == InteropEmu.ExpansionPortDevice.FourPlayerAdapter); bool isOriginalFamicom = !isNes && !ConfigManager.Config.EmulationInfo.UseNes101Hvc101Behavior; - List controllerTypes = new List() { InteropEmu.ControllerType.StandardController }; - if(!isOriginalFamicom) { - controllerTypes.Add(InteropEmu.ControllerType.None); - controllerTypes.Add(InteropEmu.ControllerType.SnesMouse); - controllerTypes.Add(InteropEmu.ControllerType.SuborMouse); - if(!isNes) { - controllerTypes.Add(InteropEmu.ControllerType.SnesController); - } + List controllerTypes = new List() { InteropEmu.ControllerType.None, InteropEmu.ControllerType.StandardController }; + controllerTypes.Add(InteropEmu.ControllerType.SnesMouse); + controllerTypes.Add(InteropEmu.ControllerType.SuborMouse); + if(!isNes) { + controllerTypes.Add(InteropEmu.ControllerType.SnesController); } SetAvailableControllerTypes(cboPlayer3, controllerTypes.ToArray()); SetAvailableControllerTypes(cboPlayer4, controllerTypes.ToArray()); - if(isNes && !chkFourScore.Checked) { + if(isOriginalFamicom) { + //Original famicom only allows standard controllers in port 1/2 + controllerTypes = new List() { InteropEmu.ControllerType.StandardController }; + } else if(isNes && !chkFourScore.Checked) { //These use more than just bit 0, and won't work on the four score controllerTypes.Add(InteropEmu.ControllerType.ArkanoidController); controllerTypes.Add(InteropEmu.ControllerType.PowerPad); @@ -128,6 +149,11 @@ namespace Mesen.GUI.Forms.Config SetAvailableControllerTypes(cboPlayer1, controllerTypes.ToArray()); SetAvailableControllerTypes(cboPlayer2, controllerTypes.ToArray()); + + cboPlayer1.SelectedIndexChanged += cboPlayerController_SelectedIndexChanged; + cboPlayer2.SelectedIndexChanged += cboPlayerController_SelectedIndexChanged; + cboPlayer3.SelectedIndexChanged += cboPlayerController_SelectedIndexChanged; + cboPlayer4.SelectedIndexChanged += cboPlayerController_SelectedIndexChanged; } private void SetAvailableControllerTypes(ComboBox comboBox, InteropEmu.ControllerType[] controllerTypes) @@ -170,24 +196,23 @@ namespace Mesen.GUI.Forms.Config private void UpdateInterface() { - if(!this.Updating) { - bool isNes = ((InputInfo)Entity).ConsoleType == ConsoleType.Nes; - cboExpansionPort.Visible = !isNes; - lblExpansionPort.Visible = !isNes; - btnSetupExp.Visible = !isNes; - chkFourScore.Visible = isNes; + bool isNes = ((InputInfo)Entity).ConsoleType == ConsoleType.Nes; + cboExpansionPort.Visible = !isNes; + lblExpansionPort.Visible = !isNes; + btnSetupExp.Visible = !isNes; + chkFourScore.Visible = isNes; - UpdatePlayer3And4Visibility(); - UpdateAvailableControllerTypes(); + UpdatePlayer3And4Visibility(); + UpdateAvailableControllerTypes(); + UpdateSetupButtons(); - if(ConfigManager.Config.PreferenceInfo.DisableGameDatabase) { - //This option requires the game DB to be active - chkAutoConfigureInput.Enabled = false; - chkAutoConfigureInput.Checked = false; - } - - UpdateConflictWarning(); + if(ConfigManager.Config.PreferenceInfo.DisableGameDatabase) { + //This option requires the game DB to be active + chkAutoConfigureInput.Enabled = false; + chkAutoConfigureInput.Checked = false; } + + UpdateConflictWarning(); } private bool FourScoreAttached @@ -215,29 +240,42 @@ namespace Mesen.GUI.Forms.Config private void cboNesType_SelectedIndexChanged(object sender, EventArgs e) { - if(!this.Updating) { - UpdateObject(); - if(((InputInfo)Entity).ConsoleType == ConsoleType.Famicom) { - ((InputInfo)Entity).Controllers[0].ControllerType = InteropEmu.ControllerType.StandardController; - ((InputInfo)Entity).Controllers[1].ControllerType = InteropEmu.ControllerType.StandardController; - } - UpdateInterface(); + UpdateObject(); + if(((InputInfo)Entity).ConsoleType == ConsoleType.Famicom) { + ((InputInfo)Entity).Controllers[0].ControllerType = InteropEmu.ControllerType.StandardController; + ((InputInfo)Entity).Controllers[1].ControllerType = InteropEmu.ControllerType.StandardController; } + UpdateInterface(); } private void chkFourScore_CheckedChanged(object sender, EventArgs e) { - if(!this.Updating) { - UpdateObject(); - UpdateInterface(); - } + UpdateObject(); + UpdateInterface(); } private void cboExpansionPort_SelectedIndexChanged(object sender, EventArgs e) { - if(!this.Updating) { - UpdateObject(); - UpdateInterface(); + UpdateObject(); + UpdateInterface(); + } + + private void UpdateSetupButtons() + { + List dropdowns = new List() { cboPlayer1, cboPlayer2, cboPlayer3, cboPlayer4 }; + List