diff --git a/BizHawk.Client.EmuHawk/config/DisplayConfig.Designer.cs b/BizHawk.Client.EmuHawk/config/DisplayConfig.Designer.cs index 50f04c9da6..d837a5d851 100644 --- a/BizHawk.Client.EmuHawk/config/DisplayConfig.Designer.cs +++ b/BizHawk.Client.EmuHawk/config/DisplayConfig.Designer.cs @@ -190,6 +190,7 @@ // this.rbDispMethodOpenGL.Checked = true; this.rbDispMethodOpenGL.Name = "rbDispMethodOpenGL"; + this.rbDispMethodOpenGL.Tag = BizHawk.Client.Common.EDispMethod.OpenGL; this.rbDispMethodOpenGL.Text = "OpenGL"; // // lblDispMethodOpenGL @@ -427,6 +428,7 @@ // rbARSquare // this.rbARSquare.Name = "rbARSquare"; + this.rbARSquare.Tag = BizHawk.Client.Common.EDispManagerAR.None; this.rbARSquare.Text = "Use 1:1 pixel size (for crispness or debugging)"; this.rbARSquare.CheckedChanged += new System.EventHandler(this.rbARSquare_CheckedChanged); // @@ -438,6 +440,7 @@ // rbARBySystem // this.rbARBySystem.Name = "rbARBySystem"; + this.rbARBySystem.Tag = BizHawk.Client.Common.EDispManagerAR.System; this.rbARBySystem.Text = "Use system\'s recommendation"; this.rbARBySystem.CheckedChanged += new System.EventHandler(this.rbARBySystem_CheckedChanged); // @@ -452,6 +455,7 @@ // rbARCustomSize // this.rbARCustomSize.Name = "rbARCustomSize"; + this.rbARCustomSize.Tag = BizHawk.Client.Common.EDispManagerAR.Custom; this.rbARCustomSize.Text = "Use custom size:"; // // txtARCustomWidth @@ -480,6 +484,7 @@ // rbARCustomRatio // this.rbARCustomRatio.Name = "rbARCustomRatio"; + this.rbARCustomRatio.Tag = BizHawk.Client.Common.EDispManagerAR.CustomRatio; this.rbARCustomRatio.Text = "Use custom AR:"; // // txtARCustomRatioH @@ -616,6 +621,7 @@ // this.rbDispMethodD3D.Checked = true; this.rbDispMethodD3D.Name = "rbDispMethodD3D"; + this.rbDispMethodD3D.Tag = BizHawk.Client.Common.EDispMethod.SlimDX9; this.rbDispMethodD3D.Text = "Direct3D9"; // // lblDispMethodD3D @@ -649,6 +655,7 @@ // this.rbDispMethodGDIPlus.Checked = true; this.rbDispMethodGDIPlus.Name = "rbDispMethodGDIPlus"; + this.rbDispMethodGDIPlus.Tag = BizHawk.Client.Common.EDispMethod.GdiPlus; this.rbDispMethodGDIPlus.Text = "GDI+"; // // lblDispMethodGDIPlus diff --git a/BizHawk.Client.EmuHawk/config/DisplayConfig.cs b/BizHawk.Client.EmuHawk/config/DisplayConfig.cs index 5861a51434..1e0bb716e4 100644 --- a/BizHawk.Client.EmuHawk/config/DisplayConfig.cs +++ b/BizHawk.Client.EmuHawk/config/DisplayConfig.cs @@ -130,14 +130,7 @@ namespace BizHawk.Client.EmuHawk if (rbDispFeaturesMinimal.Checked) _config.DispSpeedupFeatures = 1; if (rbDispFeaturesNothing.Checked) _config.DispSpeedupFeatures = 0; - if (rbARSquare.Checked) - _config.DispManagerAR = EDispManagerAR.None; - else if (rbARBySystem.Checked) - _config.DispManagerAR = EDispManagerAR.System; - else if (rbARCustomSize.Checked) - _config.DispManagerAR = EDispManagerAR.Custom; - else if (rbARCustomRatio.Checked) - _config.DispManagerAR = EDispManagerAR.CustomRatio; + _config.DispManagerAR = grpAspectRatio.Tracker.GetSelectionTagAs() ?? throw new InvalidOperationException(); if (string.IsNullOrWhiteSpace(txtARCustomWidth.Text)) { @@ -188,12 +181,7 @@ namespace BizHawk.Client.EmuHawk } var oldDisplayMethod = _config.DispMethod; - if(rbDispMethodOpenGL.Checked) - _config.DispMethod = EDispMethod.OpenGL; - if(rbDispMethodGDIPlus.Checked) - _config.DispMethod = EDispMethod.GdiPlus; - if(rbDispMethodD3D.Checked) - _config.DispMethod = EDispMethod.SlimDX9; + _config.DispMethod = grpDispMethod.Tracker.GetSelectionTagAs() ?? throw new InvalidOperationException(); if (int.TryParse(txtCropLeft.Text, out int dispCropLeft)) { diff --git a/BizHawk.Client.EmuHawk/config/EmuHawkOptions.Designer.cs b/BizHawk.Client.EmuHawk/config/EmuHawkOptions.Designer.cs index 3a747552cf..351f799611 100644 --- a/BizHawk.Client.EmuHawk/config/EmuHawkOptions.Designer.cs +++ b/BizHawk.Client.EmuHawk/config/EmuHawkOptions.Designer.cs @@ -478,11 +478,13 @@ // rbKopiLua // this.rbKopiLua.Name = "rbKopiLua"; + this.rbKopiLua.Tag = BizHawk.Client.Common.ELuaEngine.NLuaPlusKopiLua; this.rbKopiLua.Text = "NLua+KopiLua - Reliable but slower"; // // rbLuaInterface // this.rbLuaInterface.Name = "rbLuaInterface"; + this.rbLuaInterface.Tag = BizHawk.Client.Common.ELuaEngine.LuaPlusLuaInterface; this.rbLuaInterface.Text = "Lua+LuaInterface - Faster but memory leaks, use at your own risk!"; // // flpDialogButtons diff --git a/BizHawk.Client.EmuHawk/config/EmuHawkOptions.cs b/BizHawk.Client.EmuHawk/config/EmuHawkOptions.cs index 2c043fbd66..78008b11fe 100644 --- a/BizHawk.Client.EmuHawk/config/EmuHawkOptions.cs +++ b/BizHawk.Client.EmuHawk/config/EmuHawkOptions.cs @@ -118,14 +118,7 @@ namespace BizHawk.Client.EmuHawk _config.MoviesInAwe = cbMoviesInAWE.Checked; var prevLuaEngine = _config.LuaEngine; - if (rbLuaInterface.Checked) - { - _config.LuaEngine = ELuaEngine.LuaPlusLuaInterface; - } - else if (rbKopiLua.Checked) - { - _config.LuaEngine = ELuaEngine.NLuaPlusKopiLua; - } + _config.LuaEngine = grpLuaEngine.Tracker.GetSelectionTagAs() ?? throw new InvalidOperationException(); _mainForm.AddOnScreenMessage("Custom configurations saved."); if (prevLuaEngine != _config.LuaEngine) diff --git a/BizHawk.Client.EmuHawk/config/SoundConfig.Designer.cs b/BizHawk.Client.EmuHawk/config/SoundConfig.Designer.cs index 45f2783a66..ca087c257f 100644 --- a/BizHawk.Client.EmuHawk/config/SoundConfig.Designer.cs +++ b/BizHawk.Client.EmuHawk/config/SoundConfig.Designer.cs @@ -288,18 +288,21 @@ // rbSoundMethodDirectSound // this.rbSoundMethodDirectSound.Name = "rbSoundMethodDirectSound"; + this.rbSoundMethodDirectSound.Tag = BizHawk.Client.Common.ESoundOutputMethod.DirectSound; this.rbSoundMethodDirectSound.Text = "DirectSound"; this.rbSoundMethodDirectSound.CheckedChanged += new System.EventHandler(this.rbSoundMethodAllRadios_CheckedChanged); // // rbSoundMethodXAudio2 // this.rbSoundMethodXAudio2.Name = "rbSoundMethodXAudio2"; + this.rbSoundMethodXAudio2.Tag = BizHawk.Client.Common.ESoundOutputMethod.XAudio2; this.rbSoundMethodXAudio2.Text = "XAudio2"; this.rbSoundMethodXAudio2.CheckedChanged += new System.EventHandler(this.rbSoundMethodAllRadios_CheckedChanged); // // rbSoundMethodOpenAL // this.rbSoundMethodOpenAL.Name = "rbSoundMethodOpenAL"; + this.rbSoundMethodOpenAL.Tag = BizHawk.Client.Common.ESoundOutputMethod.OpenAL; this.rbSoundMethodOpenAL.Text = "OpenAL"; this.rbSoundMethodOpenAL.CheckedChanged += new System.EventHandler(this.rbSoundMethodAllRadios_CheckedChanged); // diff --git a/BizHawk.Client.EmuHawk/config/SoundConfig.cs b/BizHawk.Client.EmuHawk/config/SoundConfig.cs index 9f37a1b018..438af75b50 100644 --- a/BizHawk.Client.EmuHawk/config/SoundConfig.cs +++ b/BizHawk.Client.EmuHawk/config/SoundConfig.cs @@ -62,9 +62,7 @@ namespace BizHawk.Client.EmuHawk _config.SoundEnabledNormal = cbFullSpeedEnable.Checked; _config.SoundEnabledRWFF = cbRewindFFWEnable.Checked; _config.MuteFrameAdvance = cbMuteFrameAdvance.Checked; - if (rbSoundMethodDirectSound.Checked) _config.SoundOutputMethod = ESoundOutputMethod.DirectSound; - if (rbSoundMethodXAudio2.Checked) _config.SoundOutputMethod = ESoundOutputMethod.XAudio2; - if (rbSoundMethodOpenAL.Checked) _config.SoundOutputMethod = ESoundOutputMethod.OpenAL; + _config.SoundOutputMethod = grpSoundMethod.Tracker.GetSelectionTagAs() ?? ESoundOutputMethod.Dummy; _config.SoundBufferSizeMs = (int)nudBufferSize.Value; _config.SoundVolume = tbFullSpeedVolume.Value; _config.SoundVolumeRWFF = tbRewindFFWVolume.Value; diff --git a/BizHawk.WinForms.Controls/GroupBoxEx/ITrackedRadioButton.cs b/BizHawk.WinForms.Controls/GroupBoxEx/ITrackedRadioButton.cs index b9ef99d4a6..8e8569c0fd 100644 --- a/BizHawk.WinForms.Controls/GroupBoxEx/ITrackedRadioButton.cs +++ b/BizHawk.WinForms.Controls/GroupBoxEx/ITrackedRadioButton.cs @@ -7,6 +7,8 @@ namespace BizHawk.WinForms.Controls string Name { get; } + object Tag { get; } + void UncheckFromTracker(); } } diff --git a/BizHawk.WinForms.Controls/GroupBoxEx/RadioButtonGroupTracker.cs b/BizHawk.WinForms.Controls/GroupBoxEx/RadioButtonGroupTracker.cs index 10574a0259..01a7c44482 100644 --- a/BizHawk.WinForms.Controls/GroupBoxEx/RadioButtonGroupTracker.cs +++ b/BizHawk.WinForms.Controls/GroupBoxEx/RadioButtonGroupTracker.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Windows.Forms; @@ -12,6 +13,20 @@ namespace BizHawk.WinForms.Controls /// public sealed class RadioButtonGroupTracker : List, IRadioButtonReadOnlyTracker { + /// The selected radio button, or if no button is selected or if the collection is empty. + public ITrackedRadioButton? Selection + { + get + { + if (Count == 0) return null; + foreach (var rb in this) if (rb.Checked) return rb; + return null; + } + } + + /// The of the selected radio button, cast to ?, or if no button is selected or if the collection is empty. + public T? GetSelectionTagAs() where T : struct, Enum => (T?) Selection?.Tag; + public void UpdateDeselected(string name) { foreach (var rb in this) if (rb.Name != name) rb.UncheckFromTracker();