Don't expose `MainForm.MovieSession` via `IMainFormForConfig`

This commit is contained in:
YoshiRulz 2021-11-20 05:16:31 +10:00
parent ed5128343f
commit 5582b2163d
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
4 changed files with 49 additions and 25 deletions

View File

@ -8,8 +8,6 @@ namespace BizHawk.Client.EmuHawk
/// <remarks>only referenced from <see cref="GenericCoreConfig"/></remarks>
IEmulator Emulator { get; }
IMovieSession MovieSession { get; }
void PutCoreSettings(object o);
void PutCoreSyncSettings(object o);

View File

@ -888,7 +888,7 @@ namespace BizHawk.Client.EmuHawk
private void PathsMenuItem_Click(object sender, EventArgs e)
{
using var form = new PathConfig(this, Config.PathEntries, Game.System);
using var form = new PathConfig(Config.PathEntries, Game.System, newPath => MovieSession.BackupDirectory = newPath);
if (form.ShowDialog().IsOk()) AddOnScreenMessage("Path settings saved");
}
@ -1439,7 +1439,12 @@ namespace BizHawk.Client.EmuHawk
}
else if (Emulator is QuickNES)
{
GenericCoreConfig.DoDialog(this, "QuickNES Controller Settings", true, false);
GenericCoreConfig.DoDialog(
this,
"QuickNES Controller Settings",
isMovieActive: MovieSession.Movie.IsActive(),
hideSettings: true,
hideSyncSettings: false);
}
}
@ -1551,7 +1556,7 @@ namespace BizHawk.Client.EmuHawk
}
else
{
GenericCoreConfig.DoDialog(this, "Gameboy Settings");
OpenGenericCoreConfig("Gameboy Settings");
}
}
@ -1748,15 +1753,18 @@ namespace BizHawk.Client.EmuHawk
}
}
private void OpenGenericCoreConfig(string title)
=> GenericCoreConfig.DoDialog(this, title, isMovieActive: MovieSession.Movie.IsActive());
private void GenericCoreSettingsMenuItem_Click(object sender, EventArgs e)
{
var coreName = ((CoreAttribute) Attribute.GetCustomAttribute(Emulator.GetType(), typeof(CoreAttribute))).CoreName;
GenericCoreConfig.DoDialog(this, $"{coreName} Settings");
OpenGenericCoreConfig($"{coreName} Settings");
}
private void AppleIISettingsMenuItem_Click(object sender, EventArgs e)
{
GenericCoreConfig.DoDialog(this, "Apple II Settings");
OpenGenericCoreConfig("Apple II Settings");
}
private void AppleSubMenu_DropDownOpened(object sender, EventArgs e)
@ -1829,7 +1837,7 @@ namespace BizHawk.Client.EmuHawk
private void C64SettingsMenuItem_Click(object sender, EventArgs e)
{
GenericCoreConfig.DoDialog(this, "C64 Settings");
OpenGenericCoreConfig("C64 Settings");
}
private void IntVSubMenu_DropDownOpened(object sender, EventArgs e)

View File

@ -1,8 +1,7 @@
using System;
using System.Windows.Forms;
using System.Reflection;
using System.ComponentModel;
using BizHawk.Client.Common;
using System.Windows.Forms;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.EmuHawk
@ -15,7 +14,11 @@ namespace BizHawk.Client.EmuHawk
private bool _syncSettingsChanged;
private bool _settingsChanged;
private GenericCoreConfig(IMainFormForConfig mainForm, bool ignoreSettings = false, bool ignoreSyncSettings = false)
private GenericCoreConfig(
IMainFormForConfig mainForm,
bool isMovieActive,
bool ignoreSettings = false,
bool ignoreSyncSettings = false)
{
InitializeComponent();
_mainForm = mainForm;
@ -52,7 +55,7 @@ namespace BizHawk.Client.EmuHawk
tabControl1.TabPages.Remove(tabPage2);
}
if (_mainForm.MovieSession.Movie.IsActive())
if (isMovieActive)
{
propertyGrid2.Enabled = false; // disable changes to sync setting when movie, so as not to confuse user
}
@ -74,7 +77,7 @@ namespace BizHawk.Client.EmuHawk
Close();
}
public static void DoDialog(IMainFormForConfig owner, string title)
public static void DoDialog(IMainFormForConfig owner, string title, bool isMovieActive)
{
if (owner.Emulator is Emulation.Cores.Waterbox.NymaCore core)
{
@ -84,7 +87,7 @@ namespace BizHawk.Client.EmuHawk
// OH GOD THE HACKS WHY
TypeDescriptor.AddProvider(desc, typeof(Emulation.Cores.Waterbox.NymaCore.NymaSettings));
TypeDescriptor.AddProvider(desc, typeof(Emulation.Cores.Waterbox.NymaCore.NymaSyncSettings));
DoDialog(owner, "Nyma Core", !core.SettingsInfo.HasSettings, !core.SettingsInfo.HasSyncSettings);
DoDialog(owner, "Nyma Core", isMovieActive, !core.SettingsInfo.HasSettings, !core.SettingsInfo.HasSyncSettings);
}
finally
{
@ -98,7 +101,7 @@ namespace BizHawk.Client.EmuHawk
try
{
TypeDescriptor.AddProvider(desc, typeof(Emulation.Cores.Arcades.MAME.MAME.MAMESyncSettings));
DoDialog(owner, "MAME", true, false);
DoDialog(owner, "MAME", isMovieActive, true, false);
}
finally
{
@ -107,16 +110,28 @@ namespace BizHawk.Client.EmuHawk
}
else
{
using var dlg = new GenericCoreConfig(owner) { Text = title };
owner.ShowDialogAsChild(dlg);
DoDialog(owner, title, isMovieActive, false, false);
}
}
public static void DoDialog(IMainFormForConfig owner, string title, bool hideSettings, bool hideSyncSettings)
public static void DoDialog(
IMainFormForConfig owner,
string title,
bool isMovieActive,
bool hideSettings,
bool hideSyncSettings)
{
using var dlg = new GenericCoreConfig(owner, hideSettings, hideSyncSettings) { Text = title };
using var dlg = new GenericCoreConfig(
owner,
isMovieActive: isMovieActive,
ignoreSettings: hideSettings,
ignoreSyncSettings: hideSyncSettings)
{
Text = title,
};
owner.ShowDialogAsChild(dlg);
}
private void PropertyGrid2_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
{
_syncSettingsChanged = true;

View File

@ -13,10 +13,10 @@ namespace BizHawk.Client.EmuHawk
{
public partial class PathConfig : Form
{
private readonly IMainFormForConfig _mainForm;
private readonly PathEntryCollection _pathEntries;
private readonly Action<string> _setMovieBackupPath;
private readonly string _sysID;
private static AutoCompleteStringCollection AutoCompleteOptions => new AutoCompleteStringCollection
@ -26,10 +26,13 @@ namespace BizHawk.Client.EmuHawk
"%rom%",
};
public PathConfig(IMainFormForConfig mainForm, PathEntryCollection pathEntries, string sysID)
public PathConfig(
PathEntryCollection pathEntries,
string sysID,
Action<string> setMovieBackupPath)
{
_mainForm = mainForm;
_pathEntries = pathEntries;
_setMovieBackupPath = setMovieBackupPath;
_sysID = sysID;
InitializeComponent();
SpecialCommandsBtn.Image = Properties.Resources.Help;
@ -219,7 +222,7 @@ namespace BizHawk.Client.EmuHawk
pathEntry.Path = t.Text;
}
_mainForm.MovieSession.BackupDirectory = _pathEntries.MovieBackupsAbsolutePath();
_setMovieBackupPath(_pathEntries.MovieBackupsAbsolutePath());
}
private void DoRomToggle()