pass in globals to Play/Record movie dialogs

This commit is contained in:
adelikat 2019-12-22 14:18:17 -06:00
parent 1332079f84
commit afd460f1d2
3 changed files with 59 additions and 34 deletions

View File

@ -489,13 +489,13 @@ namespace BizHawk.Client.EmuHawk
// Inaccurate core but allow the user to continue anyway // 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(); form.ShowDialog();
} }
private void PlayMovieMenuItem_Click(object sender, EventArgs e) 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(); form.ShowDialog();
} }

View File

@ -10,12 +10,17 @@ using System.Windows.Forms;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Client.EmuHawk.WinFormExtensions; using BizHawk.Client.EmuHawk.WinFormExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
public partial class PlayMovie : Form public partial class PlayMovie : Form
{ {
private readonly MainForm _mainForm; 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 readonly PlatformFrameRates _platformFrameRates = new PlatformFrameRates();
private List<IMovie> _movieList = new List<IMovie>(); private List<IMovie> _movieList = new List<IMovie>();
@ -25,9 +30,18 @@ namespace BizHawk.Client.EmuHawk
private bool _sortDetailsReverse; private bool _sortDetailsReverse;
private string _sortedDetailsCol; private string _sortedDetailsCol;
public PlayMovie(MainForm mainForm) public PlayMovie(
MainForm mainForm,
Config config,
GameInfo game,
IEmulator emulator,
IMovieSession movieSession)
{ {
_mainForm = mainForm; _mainForm = mainForm;
_config = config;
_game = game;
_emulator = emulator;
_movieSession = movieSession;
InitializeComponent(); InitializeComponent();
MovieView.RetrieveVirtualItem += MovieView_QueryItemText; MovieView.RetrieveVirtualItem += MovieView_QueryItemText;
MovieView.VirtualMode = true; MovieView.VirtualMode = true;
@ -40,11 +54,11 @@ namespace BizHawk.Client.EmuHawk
private void PlayMovie_Load(object sender, EventArgs e) private void PlayMovie_Load(object sender, EventArgs e)
{ {
IncludeSubDirectories.Checked = Global.Config.PlayMovie_IncludeSubdir; IncludeSubDirectories.Checked = _config.PlayMovie_IncludeSubdir;
MatchHashCheckBox.Checked = Global.Config.PlayMovie_MatchHash; MatchHashCheckBox.Checked = _config.PlayMovie_MatchHash;
ScanFiles(); ScanFiles();
PreHighlightMovie(); PreHighlightMovie();
TurboCheckbox.Checked = Global.Config.TurboSeek; TurboCheckbox.Checked = _config.TurboSeek;
} }
private void MovieView_QueryItemText(object sender, RetrieveVirtualItemEventArgs e) private void MovieView_QueryItemText(object sender, RetrieveVirtualItemEventArgs e)
@ -121,8 +135,8 @@ namespace BizHawk.Client.EmuHawk
movie.PreLoadHeaderAndLength(hf); movie.PreLoadHeaderAndLength(hf);
// Don't do this from browse // Don't do this from browse
if (movie.Hash == Global.Game.Hash || if (movie.Hash == _game.Hash
Global.Config.PlayMovie_MatchHash == false || force) || _config.PlayMovie_MatchHash == false || force)
{ {
return movie; return movie;
} }
@ -144,7 +158,7 @@ namespace BizHawk.Client.EmuHawk
private void PreHighlightMovie() private void PreHighlightMovie()
{ {
if (Global.Game == null) if (_game.IsNullInstance())
{ {
return; return;
} }
@ -154,7 +168,7 @@ namespace BizHawk.Client.EmuHawk
// Pull out matching names // Pull out matching names
for (var i = 0; i < _movieList.Count; i++) 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); indices.Add(i);
} }
@ -224,7 +238,7 @@ namespace BizHawk.Client.EmuHawk
MovieView.VirtualListSize = 0; MovieView.VirtualListSize = 0;
MovieView.Update(); MovieView.Update();
var directory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null); var directory = PathManager.MakeAbsolutePath(_config.PathEntries.MoviesPathFragment, null);
if (!Directory.Exists(directory)) if (!Directory.Exists(directory))
{ {
Directory.CreateDirectory(directory); Directory.CreateDirectory(directory);
@ -240,7 +254,7 @@ namespace BizHawk.Client.EmuHawk
string dp = dpTodo.Dequeue(); string dp = dpTodo.Dequeue();
// enqueue subdirectories if appropriate // enqueue subdirectories if appropriate
if (Global.Config.PlayMovie_IncludeSubdir) if (_config.PlayMovie_IncludeSubdir)
{ {
foreach (var subDir in Directory.GetDirectories(dp)) foreach (var subDir in Directory.GetDirectories(dp))
{ {
@ -398,10 +412,10 @@ namespace BizHawk.Client.EmuHawk
switch (kvp.Key) switch (kvp.Key)
{ {
case HeaderKeys.SHA1: case HeaderKeys.SHA1:
if (kvp.Value != Global.Game.Hash) if (kvp.Value != _game.Hash)
{ {
item.BackColor = Color.Pink; item.BackColor = Color.Pink;
toolTip1.SetToolTip(DetailsView, $"Current SHA1: {Global.Game.Hash}"); toolTip1.SetToolTip(DetailsView, $"Current SHA1: {_game.Hash}");
} }
break; break;
case HeaderKeys.EMULATIONVERSION: case HeaderKeys.EMULATIONVERSION:
@ -411,13 +425,13 @@ namespace BizHawk.Client.EmuHawk
} }
break; break;
case HeaderKeys.PLATFORM: case HeaderKeys.PLATFORM:
// feos: previously it was compared against Global.Game.System, but when the movie is created // feos: previously it was compared against _game.System, but when the movie is created
// its platform is copied from Global.Emulator.SystemId, see PopulateWithDefaultHeaderValues() // its platform is copied from _emulator.SystemId, see PopulateWithDefaultHeaderValues()
// the problem is that for GameGear and SG100, those mismatch, resulting in false positive here // 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) // 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 // 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) // 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; item.BackColor = Color.Pink;
} }
@ -558,7 +572,7 @@ namespace BizHawk.Client.EmuHawk
using var ofd = new OpenFileDialog using var ofd = new OpenFileDialog
{ {
Filter = $"Movie Files (*.{MovieService.DefaultExtension})|*.{MovieService.DefaultExtension}|TAS project Files (*.{TasMovie.Extension})|*.{TasMovie.Extension}|All Files|*.*", 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(); var result = ofd.ShowHawkDialog();
@ -588,29 +602,29 @@ namespace BizHawk.Client.EmuHawk
private void IncludeSubDirectories_CheckedChanged(object sender, EventArgs e) private void IncludeSubDirectories_CheckedChanged(object sender, EventArgs e)
{ {
Global.Config.PlayMovie_IncludeSubdir = IncludeSubDirectories.Checked; _config.PlayMovie_IncludeSubdir = IncludeSubDirectories.Checked;
ScanFiles(); ScanFiles();
PreHighlightMovie(); PreHighlightMovie();
} }
private void MatchHashCheckBox_CheckedChanged(object sender, EventArgs e) private void MatchHashCheckBox_CheckedChanged(object sender, EventArgs e)
{ {
Global.Config.PlayMovie_MatchHash = MatchHashCheckBox.Checked; _config.PlayMovie_MatchHash = MatchHashCheckBox.Checked;
ScanFiles(); ScanFiles();
PreHighlightMovie(); PreHighlightMovie();
} }
private void Ok_Click(object sender, EventArgs e) private void Ok_Click(object sender, EventArgs e)
{ {
Global.Config.TurboSeek = TurboCheckbox.Checked; _config.TurboSeek = TurboCheckbox.Checked;
Run(); Run();
Global.MovieSession.ReadOnly = ReadOnlyCheckBox.Checked; _movieSession.ReadOnly = ReadOnlyCheckBox.Checked;
if (StopOnFrameCheckbox.Checked && if (StopOnFrameCheckbox.Checked &&
(StopOnFrameTextBox.ToRawInt().HasValue || LastFrameCheckbox.Checked)) (StopOnFrameTextBox.ToRawInt().HasValue || LastFrameCheckbox.Checked))
{ {
_mainForm.PauseOnFrame = LastFrameCheckbox.Checked _mainForm.PauseOnFrame = LastFrameCheckbox.Checked
? Global.MovieSession.Movie.InputLogLength ? _movieSession.Movie.InputLogLength
: StopOnFrameTextBox.ToRawInt(); : StopOnFrameTextBox.ToRawInt();
} }

View File

@ -16,12 +16,23 @@ namespace BizHawk.Client.EmuHawk
public partial class RecordMovie : Form public partial class RecordMovie : Form
{ {
private readonly MainForm _mainForm; private readonly MainForm _mainForm;
private readonly Config _config;
private readonly GameInfo _game;
private readonly IEmulator _emulator; 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; _mainForm = mainForm;
_config = config;
_game = game;
_emulator = core; _emulator = core;
_movieSession = movieSession;
InitializeComponent(); InitializeComponent();
if (!_emulator.HasSavestates()) if (!_emulator.HasSavestates())
@ -56,7 +67,7 @@ namespace BizHawk.Client.EmuHawk
path = path.Insert(0, Path.DirectorySeparatorChar.ToString()); 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))) if (!MovieService.MovieExtensions.Contains(Path.GetExtension(path)))
{ {
@ -129,10 +140,10 @@ namespace BizHawk.Client.EmuHawk
movieToRecord.Save(); movieToRecord.Save();
_mainForm.StartNewMovie(movieToRecord, true); _mainForm.StartNewMovie(movieToRecord, true);
Global.Config.UseDefaultAuthor = DefaultAuthorCheckBox.Checked; _config.UseDefaultAuthor = DefaultAuthorCheckBox.Checked;
if (DefaultAuthorCheckBox.Checked) if (DefaultAuthorCheckBox.Checked)
{ {
Global.Config.DefaultAuthor = AuthorBox.Text; _config.DefaultAuthor = AuthorBox.Text;
} }
Close(); Close();
@ -150,7 +161,7 @@ namespace BizHawk.Client.EmuHawk
private void BrowseBtn_Click(object sender, EventArgs e) 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 // Create movie folder if it doesn't already exist
try try
@ -173,10 +184,10 @@ namespace BizHawk.Client.EmuHawk
using var sfd = new SaveFileDialog using var sfd = new SaveFileDialog
{ {
InitialDirectory = movieFolderPath, InitialDirectory = movieFolderPath,
DefaultExt = $".{Global.MovieSession.Movie.PreferredExtension}", DefaultExt = $".{_movieSession.Movie.PreferredExtension}",
FileName = RecordBox.Text, FileName = RecordBox.Text,
OverwritePrompt = false, 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(); var result = sfd.ShowHawkDialog();
@ -189,12 +200,12 @@ namespace BizHawk.Client.EmuHawk
private void RecordMovie_Load(object sender, EventArgs e) private void RecordMovie_Load(object sender, EventArgs e)
{ {
RecordBox.Text = PathManager.FilesystemSafeName(Global.Game); RecordBox.Text = PathManager.FilesystemSafeName(_game);
StartFromCombo.SelectedIndex = 0; StartFromCombo.SelectedIndex = 0;
DefaultAuthorCheckBox.Checked = Global.Config.UseDefaultAuthor; DefaultAuthorCheckBox.Checked = _config.UseDefaultAuthor;
if (Global.Config.UseDefaultAuthor) if (_config.UseDefaultAuthor)
{ {
AuthorBox.Text = Global.Config.DefaultAuthor; AuthorBox.Text = _config.DefaultAuthor;
} }
} }