Add helpers for getting selected radio button of group
This commit is contained in:
parent
6bf948a7b7
commit
905b18e429
|
@ -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
|
||||
|
|
|
@ -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<EDispManagerAR>() ?? 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<EDispMethod>() ?? throw new InvalidOperationException();
|
||||
|
||||
if (int.TryParse(txtCropLeft.Text, out int dispCropLeft))
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<ELuaEngine>() ?? throw new InvalidOperationException();
|
||||
|
||||
_mainForm.AddOnScreenMessage("Custom configurations saved.");
|
||||
if (prevLuaEngine != _config.LuaEngine)
|
||||
|
|
|
@ -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);
|
||||
//
|
||||
|
|
|
@ -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>() ?? ESoundOutputMethod.Dummy;
|
||||
_config.SoundBufferSizeMs = (int)nudBufferSize.Value;
|
||||
_config.SoundVolume = tbFullSpeedVolume.Value;
|
||||
_config.SoundVolumeRWFF = tbRewindFFWVolume.Value;
|
||||
|
|
|
@ -7,6 +7,8 @@ namespace BizHawk.WinForms.Controls
|
|||
|
||||
string Name { get; }
|
||||
|
||||
object Tag { get; }
|
||||
|
||||
void UncheckFromTracker();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
|
||||
|
@ -12,6 +13,20 @@ namespace BizHawk.WinForms.Controls
|
|||
/// <inheritdoc cref="IRadioButtonReadOnlyTracker"/>
|
||||
public sealed class RadioButtonGroupTracker : List<ITrackedRadioButton>, IRadioButtonReadOnlyTracker
|
||||
{
|
||||
/// <value>The selected radio button, or <see langword="null"/> if no button is selected or if the collection is empty.</value>
|
||||
public ITrackedRadioButton? Selection
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Count == 0) return null;
|
||||
foreach (var rb in this) if (rb.Checked) return rb;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <returns>The <see cref="Control.Tag"/> of the selected radio button, cast to <typeparamref name="T"/><c>?</c>, or <see langword="null"/> if no button is selected or if the collection is empty.</returns>
|
||||
public T? GetSelectionTagAs<T>() where T : struct, Enum => (T?) Selection?.Tag;
|
||||
|
||||
public void UpdateDeselected(string name)
|
||||
{
|
||||
foreach (var rb in this) if (rb.Name != name) rb.UncheckFromTracker();
|
||||
|
|
Loading…
Reference in New Issue