From afd460f1d2c4c1539c6e6c63a07f83a55cce9b4a Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 22 Dec 2019 14:18:17 -0600 Subject: [PATCH] pass in globals to Play/Record movie dialogs --- BizHawk.Client.EmuHawk/MainForm.Events.cs | 4 +- BizHawk.Client.EmuHawk/movie/PlayMovie.cs | 56 +++++++++++++-------- BizHawk.Client.EmuHawk/movie/RecordMovie.cs | 33 ++++++++---- 3 files changed, 59 insertions(+), 34 deletions(-) diff --git a/BizHawk.Client.EmuHawk/MainForm.Events.cs b/BizHawk.Client.EmuHawk/MainForm.Events.cs index 38d7f03b70..eaf744b152 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -489,13 +489,13 @@ namespace BizHawk.Client.EmuHawk // Inaccurate core but allow the user to continue anyway } - using var form = new RecordMovie(this, Emulator); + using var form = new RecordMovie(this, Config, Game, Emulator, MovieSession); form.ShowDialog(); } private void PlayMovieMenuItem_Click(object sender, EventArgs e) { - using var form = new PlayMovie(this); + using var form = new PlayMovie(this, Config, Game, Emulator, MovieSession); form.ShowDialog(); } diff --git a/BizHawk.Client.EmuHawk/movie/PlayMovie.cs b/BizHawk.Client.EmuHawk/movie/PlayMovie.cs index c2d818bf81..7998e5a9a7 100644 --- a/BizHawk.Client.EmuHawk/movie/PlayMovie.cs +++ b/BizHawk.Client.EmuHawk/movie/PlayMovie.cs @@ -10,12 +10,17 @@ using System.Windows.Forms; using BizHawk.Client.Common; using BizHawk.Common; using BizHawk.Client.EmuHawk.WinFormExtensions; +using BizHawk.Emulation.Common; namespace BizHawk.Client.EmuHawk { public partial class PlayMovie : Form { private readonly MainForm _mainForm; + private readonly Config _config; + private readonly GameInfo _game; + private readonly IEmulator _emulator; + private readonly IMovieSession _movieSession; private readonly PlatformFrameRates _platformFrameRates = new PlatformFrameRates(); private List _movieList = new List(); @@ -25,9 +30,18 @@ namespace BizHawk.Client.EmuHawk private bool _sortDetailsReverse; private string _sortedDetailsCol; - public PlayMovie(MainForm mainForm) + public PlayMovie( + MainForm mainForm, + Config config, + GameInfo game, + IEmulator emulator, + IMovieSession movieSession) { _mainForm = mainForm; + _config = config; + _game = game; + _emulator = emulator; + _movieSession = movieSession; InitializeComponent(); MovieView.RetrieveVirtualItem += MovieView_QueryItemText; MovieView.VirtualMode = true; @@ -40,11 +54,11 @@ namespace BizHawk.Client.EmuHawk private void PlayMovie_Load(object sender, EventArgs e) { - IncludeSubDirectories.Checked = Global.Config.PlayMovie_IncludeSubdir; - MatchHashCheckBox.Checked = Global.Config.PlayMovie_MatchHash; + IncludeSubDirectories.Checked = _config.PlayMovie_IncludeSubdir; + MatchHashCheckBox.Checked = _config.PlayMovie_MatchHash; ScanFiles(); PreHighlightMovie(); - TurboCheckbox.Checked = Global.Config.TurboSeek; + TurboCheckbox.Checked = _config.TurboSeek; } private void MovieView_QueryItemText(object sender, RetrieveVirtualItemEventArgs e) @@ -121,8 +135,8 @@ namespace BizHawk.Client.EmuHawk movie.PreLoadHeaderAndLength(hf); // Don't do this from browse - if (movie.Hash == Global.Game.Hash || - Global.Config.PlayMovie_MatchHash == false || force) + if (movie.Hash == _game.Hash + || _config.PlayMovie_MatchHash == false || force) { return movie; } @@ -144,7 +158,7 @@ namespace BizHawk.Client.EmuHawk private void PreHighlightMovie() { - if (Global.Game == null) + if (_game.IsNullInstance()) { return; } @@ -154,7 +168,7 @@ namespace BizHawk.Client.EmuHawk // Pull out matching names for (var i = 0; i < _movieList.Count; i++) { - if (PathManager.FilesystemSafeName(Global.Game) == _movieList[i].GameName) + if (PathManager.FilesystemSafeName(_game) == _movieList[i].GameName) { indices.Add(i); } @@ -224,7 +238,7 @@ namespace BizHawk.Client.EmuHawk MovieView.VirtualListSize = 0; MovieView.Update(); - var directory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null); + var directory = PathManager.MakeAbsolutePath(_config.PathEntries.MoviesPathFragment, null); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); @@ -240,7 +254,7 @@ namespace BizHawk.Client.EmuHawk string dp = dpTodo.Dequeue(); // enqueue subdirectories if appropriate - if (Global.Config.PlayMovie_IncludeSubdir) + if (_config.PlayMovie_IncludeSubdir) { foreach (var subDir in Directory.GetDirectories(dp)) { @@ -398,10 +412,10 @@ namespace BizHawk.Client.EmuHawk switch (kvp.Key) { case HeaderKeys.SHA1: - if (kvp.Value != Global.Game.Hash) + if (kvp.Value != _game.Hash) { item.BackColor = Color.Pink; - toolTip1.SetToolTip(DetailsView, $"Current SHA1: {Global.Game.Hash}"); + toolTip1.SetToolTip(DetailsView, $"Current SHA1: {_game.Hash}"); } break; case HeaderKeys.EMULATIONVERSION: @@ -411,13 +425,13 @@ namespace BizHawk.Client.EmuHawk } break; case HeaderKeys.PLATFORM: - // feos: previously it was compared against Global.Game.System, but when the movie is created - // its platform is copied from Global.Emulator.SystemId, see PopulateWithDefaultHeaderValues() + // feos: previously it was compared against _game.System, but when the movie is created + // its platform is copied from _emulator.SystemId, see PopulateWithDefaultHeaderValues() // the problem is that for GameGear and SG100, those mismatch, resulting in false positive here // I have a patch to make GG and SG appear as platforms in movie header (issue #1246) // but even with it, for all the old movies, this false positive would have to be worked around anyway // TODO: actually check header flags like "IsGGMode" and "IsSegaCDMode" (those are never parsed by BizHawk) - if (kvp.Value != Global.Emulator.SystemId) + if (kvp.Value != _emulator.SystemId) { item.BackColor = Color.Pink; } @@ -558,7 +572,7 @@ namespace BizHawk.Client.EmuHawk using var ofd = new OpenFileDialog { Filter = $"Movie Files (*.{MovieService.DefaultExtension})|*.{MovieService.DefaultExtension}|TAS project Files (*.{TasMovie.Extension})|*.{TasMovie.Extension}|All Files|*.*", - InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null) + InitialDirectory = PathManager.MakeAbsolutePath(_config.PathEntries.MoviesPathFragment, null) }; var result = ofd.ShowHawkDialog(); @@ -588,29 +602,29 @@ namespace BizHawk.Client.EmuHawk private void IncludeSubDirectories_CheckedChanged(object sender, EventArgs e) { - Global.Config.PlayMovie_IncludeSubdir = IncludeSubDirectories.Checked; + _config.PlayMovie_IncludeSubdir = IncludeSubDirectories.Checked; ScanFiles(); PreHighlightMovie(); } private void MatchHashCheckBox_CheckedChanged(object sender, EventArgs e) { - Global.Config.PlayMovie_MatchHash = MatchHashCheckBox.Checked; + _config.PlayMovie_MatchHash = MatchHashCheckBox.Checked; ScanFiles(); PreHighlightMovie(); } private void Ok_Click(object sender, EventArgs e) { - Global.Config.TurboSeek = TurboCheckbox.Checked; + _config.TurboSeek = TurboCheckbox.Checked; Run(); - Global.MovieSession.ReadOnly = ReadOnlyCheckBox.Checked; + _movieSession.ReadOnly = ReadOnlyCheckBox.Checked; if (StopOnFrameCheckbox.Checked && (StopOnFrameTextBox.ToRawInt().HasValue || LastFrameCheckbox.Checked)) { _mainForm.PauseOnFrame = LastFrameCheckbox.Checked - ? Global.MovieSession.Movie.InputLogLength + ? _movieSession.Movie.InputLogLength : StopOnFrameTextBox.ToRawInt(); } diff --git a/BizHawk.Client.EmuHawk/movie/RecordMovie.cs b/BizHawk.Client.EmuHawk/movie/RecordMovie.cs index ede556cfb3..3026a99c90 100644 --- a/BizHawk.Client.EmuHawk/movie/RecordMovie.cs +++ b/BizHawk.Client.EmuHawk/movie/RecordMovie.cs @@ -16,12 +16,23 @@ namespace BizHawk.Client.EmuHawk public partial class RecordMovie : Form { private readonly MainForm _mainForm; + private readonly Config _config; + private readonly GameInfo _game; private readonly IEmulator _emulator; + private readonly IMovieSession _movieSession; - public RecordMovie(MainForm mainForm, IEmulator core) + public RecordMovie( + MainForm mainForm, + Config config, + GameInfo game, + IEmulator core, + IMovieSession movieSession) { _mainForm = mainForm; + _config = config; + _game = game; _emulator = core; + _movieSession = movieSession; InitializeComponent(); if (!_emulator.HasSavestates()) @@ -56,7 +67,7 @@ namespace BizHawk.Client.EmuHawk path = path.Insert(0, Path.DirectorySeparatorChar.ToString()); } - path = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null) + path; + path = PathManager.MakeAbsolutePath(_config.PathEntries.MoviesPathFragment, null) + path; if (!MovieService.MovieExtensions.Contains(Path.GetExtension(path))) { @@ -129,10 +140,10 @@ namespace BizHawk.Client.EmuHawk movieToRecord.Save(); _mainForm.StartNewMovie(movieToRecord, true); - Global.Config.UseDefaultAuthor = DefaultAuthorCheckBox.Checked; + _config.UseDefaultAuthor = DefaultAuthorCheckBox.Checked; if (DefaultAuthorCheckBox.Checked) { - Global.Config.DefaultAuthor = AuthorBox.Text; + _config.DefaultAuthor = AuthorBox.Text; } Close(); @@ -150,7 +161,7 @@ namespace BizHawk.Client.EmuHawk private void BrowseBtn_Click(object sender, EventArgs e) { - string movieFolderPath = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null); + string movieFolderPath = PathManager.MakeAbsolutePath(_config.PathEntries.MoviesPathFragment, null); // Create movie folder if it doesn't already exist try @@ -173,10 +184,10 @@ namespace BizHawk.Client.EmuHawk using var sfd = new SaveFileDialog { InitialDirectory = movieFolderPath, - DefaultExt = $".{Global.MovieSession.Movie.PreferredExtension}", + DefaultExt = $".{_movieSession.Movie.PreferredExtension}", FileName = RecordBox.Text, OverwritePrompt = false, - Filter = $"Movie Files (*.{Global.MovieSession.Movie.PreferredExtension})|*.{Global.MovieSession.Movie.PreferredExtension}|All Files|*.*" + Filter = $"Movie Files (*.{_movieSession.Movie.PreferredExtension})|*.{_movieSession.Movie.PreferredExtension}|All Files|*.*" }; var result = sfd.ShowHawkDialog(); @@ -189,12 +200,12 @@ namespace BizHawk.Client.EmuHawk private void RecordMovie_Load(object sender, EventArgs e) { - RecordBox.Text = PathManager.FilesystemSafeName(Global.Game); + RecordBox.Text = PathManager.FilesystemSafeName(_game); StartFromCombo.SelectedIndex = 0; - DefaultAuthorCheckBox.Checked = Global.Config.UseDefaultAuthor; - if (Global.Config.UseDefaultAuthor) + DefaultAuthorCheckBox.Checked = _config.UseDefaultAuthor; + if (_config.UseDefaultAuthor) { - AuthorBox.Text = Global.Config.DefaultAuthor; + AuthorBox.Text = _config.DefaultAuthor; } }