GBPrefs/DGBPrefs - pass in dependencies

This commit is contained in:
adelikat 2020-11-28 10:53:27 -06:00
parent 342164d05c
commit be8825fefc
5 changed files with 46 additions and 23 deletions

View File

@ -1569,7 +1569,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (Emulator is Gameboy gb) if (Emulator is Gameboy gb)
{ {
GBPrefs.DoGBPrefsDialog(this, gb); GBPrefs.DoGBPrefsDialog(this, Config, Game, MovieSession, gb);
} }
else // SameBoy else // SameBoy
{ {
@ -1787,7 +1787,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (Emulator is GambatteLink gambatte) if (Emulator is GambatteLink gambatte)
{ {
DGBPrefs.DoDGBPrefsDialog(this, gambatte); DGBPrefs.DoDGBPrefsDialog(this, Config, Game, gambatte);
} }
} }

View File

@ -5,14 +5,20 @@ using System.Windows.Forms;
using System.IO; using System.IO;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Nintendo.Gameboy; using BizHawk.Emulation.Cores.Nintendo.Gameboy;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
public partial class ColorChooserForm : Form public partial class ColorChooserForm : Form
{ {
private ColorChooserForm() private readonly Config _config;
private readonly IGameInfo _game;
private ColorChooserForm(Config config, IGameInfo game)
{ {
_config = config;
_game = game;
InitializeComponent(); InitializeComponent();
Icon = Properties.Resources.GambatteIcon; Icon = Properties.Resources.GambatteIcon;
} }
@ -230,9 +236,9 @@ namespace BizHawk.Client.EmuHawk
RefreshAllBackdrops(); RefreshAllBackdrops();
} }
public static void DoColorChooserFormDialog(IWin32Window parent, Gameboy.GambatteSettings s) public static void DoColorChooserFormDialog(IWin32Window parent, Config config, IGameInfo game, Gameboy.GambatteSettings s)
{ {
using var dlg = new ColorChooserForm(); using var dlg = new ColorChooserForm(config, game);
dlg.SetAllColors(s.GBPalette); dlg.SetAllColors(s.GBPalette);
@ -295,13 +301,13 @@ namespace BizHawk.Client.EmuHawk
{ {
using var ofd = new OpenFileDialog using var ofd = new OpenFileDialog
{ {
InitialDirectory = GlobalWin.Config.PathEntries.ScreenshotAbsolutePathFor("GB"), InitialDirectory = _config.PathEntries.ScreenshotAbsolutePathFor("GB"),
Filter = new FilesystemFilterSet(FilesystemFilter.Palettes).ToString(), Filter = new FilesystemFilterSet(FilesystemFilter.Palettes).ToString(),
RestoreDirectory = true RestoreDirectory = true
}; };
var result = ofd.ShowDialog(this); var result = ofd.ShowDialog(this);
if (result == DialogResult.OK) if (result.IsOk())
{ {
LoadColorFile(ofd.FileName, true); LoadColorFile(ofd.FileName, true);
} }
@ -331,8 +337,8 @@ namespace BizHawk.Client.EmuHawk
{ {
using var sfd = new SaveFileDialog using var sfd = new SaveFileDialog
{ {
InitialDirectory = GlobalWin.Config.PathEntries.PalettesAbsolutePathFor("GB"), InitialDirectory = _config.PathEntries.PalettesAbsolutePathFor("GB"),
FileName = $"{GlobalWin.Game.Name}.pal", FileName = $"{_game.Name}.pal",
Filter = new FilesystemFilterSet(FilesystemFilter.Palettes).ToString(), Filter = new FilesystemFilterSet(FilesystemFilter.Palettes).ToString(),
RestoreDirectory = true RestoreDirectory = true
}; };

View File

@ -1,21 +1,28 @@
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Nintendo.Gameboy; using BizHawk.Emulation.Cores.Nintendo.Gameboy;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
public partial class DGBPrefs : Form public partial class DGBPrefs : Form
{ {
private DGBPrefs() private readonly Config _config;
private readonly IGameInfo _game;
private readonly IMovieSession _movieSession;
private DGBPrefs(Config config, IGameInfo game)
{ {
_config = config;
_game = game;
InitializeComponent(); InitializeComponent();
Icon = Properties.Resources.DualIcon; Icon = Properties.Resources.DualIcon;
} }
private void PutSettings(GambatteLink.GambatteLinkSettings s, GambatteLink.GambatteLinkSyncSettings ss) private void PutSettings(GambatteLink.GambatteLinkSettings s, GambatteLink.GambatteLinkSyncSettings ss)
{ {
gbPrefControl1.PutSettings(s.L, ss.L); gbPrefControl1.PutSettings(_config, _game, _movieSession, s.L, ss.L);
gbPrefControl2.PutSettings(s.R, ss.R); gbPrefControl2.PutSettings(_config, _game, _movieSession, s.R, ss.R);
} }
private void GetSettings(out GambatteLink.GambatteLinkSettings s, out GambatteLink.GambatteLinkSyncSettings ss) private void GetSettings(out GambatteLink.GambatteLinkSettings s, out GambatteLink.GambatteLinkSyncSettings ss)
@ -29,12 +36,12 @@ namespace BizHawk.Client.EmuHawk
private bool SyncSettingsChanged => gbPrefControl1.SyncSettingsChanged || gbPrefControl2.SyncSettingsChanged; private bool SyncSettingsChanged => gbPrefControl1.SyncSettingsChanged || gbPrefControl2.SyncSettingsChanged;
public static void DoDGBPrefsDialog(IMainFormForConfig mainForm, GambatteLink gambatte) public static void DoDGBPrefsDialog(IMainFormForConfig mainForm, Config config, IGameInfo game, GambatteLink gambatte)
{ {
var s = gambatte.GetSettings(); var s = gambatte.GetSettings();
var ss = gambatte.GetSyncSettings(); var ss = gambatte.GetSyncSettings();
using var dlg = new DGBPrefs(); using var dlg = new DGBPrefs(config, game);
dlg.PutSettings(s, ss); dlg.PutSettings(s, ss);
dlg.gbPrefControl1.ColorGameBoy = gambatte.IsCGBMode(false); dlg.gbPrefControl1.ColorGameBoy = gambatte.IsCGBMode(false);

View File

@ -4,11 +4,16 @@ using System.Windows.Forms;
using BizHawk.Emulation.Cores.Nintendo.Gameboy; using BizHawk.Emulation.Cores.Nintendo.Gameboy;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
public partial class GBPrefControl : UserControl public partial class GBPrefControl : UserControl
{ {
private Config _config;
private IGameInfo _game;
private IMovieSession _movieSession;
public GBPrefControl() public GBPrefControl()
{ {
InitializeComponent(); InitializeComponent();
@ -23,12 +28,15 @@ namespace BizHawk.Client.EmuHawk
private Gameboy.GambatteSettings _s; private Gameboy.GambatteSettings _s;
private Gameboy.GambatteSyncSettings _ss; private Gameboy.GambatteSyncSettings _ss;
public void PutSettings(Gameboy.GambatteSettings s, Gameboy.GambatteSyncSettings ss) public void PutSettings(Config config, IGameInfo game, IMovieSession movieSession, Gameboy.GambatteSettings s, Gameboy.GambatteSyncSettings ss)
{ {
_game = game;
_config = config;
_movieSession = movieSession;
_s = s ?? new Gameboy.GambatteSettings(); _s = s ?? new Gameboy.GambatteSettings();
_ss = ss ?? new Gameboy.GambatteSyncSettings(); _ss = ss ?? new Gameboy.GambatteSyncSettings();
propertyGrid1.SelectedObject = _ss; propertyGrid1.SelectedObject = _ss;
propertyGrid1.Enabled = GlobalWin.MovieSession.Movie.NotActive(); propertyGrid1.Enabled = movieSession.Movie.NotActive();
checkBoxMuted.Checked = _s.Muted; checkBoxMuted.Checked = _s.Muted;
cbDisplayBG.Checked = _s.DisplayBG; cbDisplayBG.Checked = _s.DisplayBG;
cbDisplayOBJ.Checked = _s.DisplayOBJ; cbDisplayOBJ.Checked = _s.DisplayOBJ;
@ -43,8 +51,8 @@ namespace BizHawk.Client.EmuHawk
private void ButtonDefaults_Click(object sender, EventArgs e) private void ButtonDefaults_Click(object sender, EventArgs e)
{ {
PutSettings(null, GlobalWin.MovieSession.Movie.IsActive() ? _ss : null); PutSettings(_config, _game, _movieSession, null, _movieSession.Movie.IsActive() ? _ss : null);
if (GlobalWin.MovieSession.Movie.NotActive()) if (_movieSession.Movie.NotActive())
{ {
SyncSettingsChanged = true; SyncSettingsChanged = true;
} }
@ -58,7 +66,7 @@ namespace BizHawk.Client.EmuHawk
} }
else else
{ {
ColorChooserForm.DoColorChooserFormDialog(ParentForm, _s); ColorChooserForm.DoColorChooserFormDialog(ParentForm, _config, _game, _s);
} }
} }

View File

@ -1,4 +1,6 @@
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Nintendo.Gameboy; using BizHawk.Emulation.Cores.Nintendo.Gameboy;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
@ -11,15 +13,15 @@ namespace BizHawk.Client.EmuHawk
Icon = Properties.Resources.GambatteIcon; Icon = Properties.Resources.GambatteIcon;
} }
public static void DoGBPrefsDialog(IMainFormForConfig mainForm, Gameboy gb) public static void DoGBPrefsDialog(IMainFormForConfig mainForm, Config config, IGameInfo game, IMovieSession movieSession, Gameboy gb)
{ {
var s = gb.GetSettings(); var s = gb.GetSettings();
var ss = gb.GetSyncSettings(); var ss = gb.GetSyncSettings();
using var dlg = new GBPrefs(); using var dlg = new GBPrefs();
dlg.gbPrefControl1.PutSettings(s, ss); dlg.gbPrefControl1.PutSettings(config, game, movieSession, s, ss);
dlg.gbPrefControl1.ColorGameBoy = gb.IsCGBMode(); dlg.gbPrefControl1.ColorGameBoy = gb.IsCGBMode();
if (mainForm.ShowDialogAsChild(dlg) == DialogResult.OK) if (mainForm.ShowDialogAsChild(dlg).IsOk())
{ {
dlg.gbPrefControl1.GetSettings(out s, out ss); dlg.gbPrefControl1.GetSettings(out s, out ss);
gb.PutSettings(s); gb.PutSettings(s);