From 336d2fc3a9746883c57e09b49d3df9f98bf164ce Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 12 Jun 2020 15:53:01 -0500 Subject: [PATCH] simplify EditSubtitlesForm --- src/BizHawk.Client.EmuHawk/MainForm.Events.cs | 3 +- .../movie/EditSubtitlesForm.cs | 63 +++++++++---------- src/BizHawk.Client.EmuHawk/movie/PlayMovie.cs | 3 +- .../tools/TAStudio/TAStudio.MenuItems.cs | 3 +- 4 files changed, 34 insertions(+), 38 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs index f9d017028b..5c9058eed4 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -2527,8 +2527,7 @@ namespace BizHawk.Client.EmuHawk { if (MovieSession.Movie.IsActive()) { - using var form = new EditSubtitlesForm { ReadOnly = MovieSession.ReadOnly }; - form.GetMovie(MovieSession.Movie); + using var form = new EditSubtitlesForm(MovieSession.Movie, MovieSession.ReadOnly); form.ShowDialog(); } } diff --git a/src/BizHawk.Client.EmuHawk/movie/EditSubtitlesForm.cs b/src/BizHawk.Client.EmuHawk/movie/EditSubtitlesForm.cs index 67f58da086..8fb5cd2554 100644 --- a/src/BizHawk.Client.EmuHawk/movie/EditSubtitlesForm.cs +++ b/src/BizHawk.Client.EmuHawk/movie/EditSubtitlesForm.cs @@ -10,17 +10,42 @@ namespace BizHawk.Client.EmuHawk { public partial class EditSubtitlesForm : Form { - public bool ReadOnly { get; set; } - private IMovie _selectedMovie; + + private readonly IMovie _selectedMovie; + private readonly bool _readOnly; - public EditSubtitlesForm() + public EditSubtitlesForm(IMovie movie, bool readOnly) { + _selectedMovie = movie; + _readOnly = readOnly; InitializeComponent(); } private void EditSubtitlesForm_Load(object sender, EventArgs e) { - if (ReadOnly) + var subs = new SubtitleList(); + subs.AddRange(_selectedMovie.Subtitles); + + for (int x = 0; x < subs.Count; x++) + { + var s = subs[x]; + SubGrid.Rows.Add(); + var c = SubGrid.Rows[x].Cells[0]; + c.Value = s.Frame; + c = SubGrid.Rows[x].Cells[1]; + c.Value = s.X; + c = SubGrid.Rows[x].Cells[2]; + c.Value = s.Y; + c = SubGrid.Rows[x].Cells[3]; + c.Value = s.Duration; + c = SubGrid.Rows[x].Cells[4]; + c.Value = $"{s.Color:X8}"; + c.Style.BackColor = Color.FromArgb((int)s.Color); + c = SubGrid.Rows[x].Cells[5]; + c.Value = s.Message; + } + + if (_readOnly) { // Set all columns to read only for (int i = 0; i < SubGrid.Columns.Count; i++) @@ -53,7 +78,7 @@ namespace BizHawk.Client.EmuHawk private void Ok_Click(object sender, EventArgs e) { - if (!ReadOnly) + if (!_readOnly) { _selectedMovie.Subtitles.Clear(); for (int i = 0; i < SubGrid.Rows.Count - 1; i++) @@ -86,32 +111,6 @@ namespace BizHawk.Client.EmuHawk Close(); } - public void GetMovie(IMovie m) - { - _selectedMovie = m; - var subs = new SubtitleList(); - subs.AddRange(m.Subtitles); - - for (int x = 0; x < subs.Count; x++) - { - var s = subs[x]; - SubGrid.Rows.Add(); - var c = SubGrid.Rows[x].Cells[0]; - c.Value = s.Frame; - c = SubGrid.Rows[x].Cells[1]; - c.Value = s.X; - c = SubGrid.Rows[x].Cells[2]; - c.Value = s.Y; - c = SubGrid.Rows[x].Cells[3]; - c.Value = s.Duration; - c = SubGrid.Rows[x].Cells[4]; - c.Value = $"{s.Color:X8}"; - c.Style.BackColor = Color.FromArgb((int)s.Color); - c = SubGrid.Rows[x].Cells[5]; - c.Value = s.Message; - } - } - private void ChangeRow(Subtitle s, int index) { if (index >= SubGrid.Rows.Count) @@ -176,7 +175,7 @@ namespace BizHawk.Client.EmuHawk private void SubGrid_MouseDoubleClick(object sender, MouseEventArgs e) { - if (ReadOnly) + if (_readOnly) { return; } diff --git a/src/BizHawk.Client.EmuHawk/movie/PlayMovie.cs b/src/BizHawk.Client.EmuHawk/movie/PlayMovie.cs index 195ed359cb..cd8c680cd8 100644 --- a/src/BizHawk.Client.EmuHawk/movie/PlayMovie.cs +++ b/src/BizHawk.Client.EmuHawk/movie/PlayMovie.cs @@ -528,8 +528,7 @@ namespace BizHawk.Client.EmuHawk var indices = MovieView.SelectedIndices; if (indices.Count > 0) { - var s = new EditSubtitlesForm { ReadOnly = true }; - s.GetMovie(_movieList[MovieView.SelectedIndices[0]]); + var s = new EditSubtitlesForm(_movieList[MovieView.SelectedIndices[0]], true); s.Show(); } } diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs index 81630f4b16..f995b9a5db 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs @@ -999,8 +999,7 @@ namespace BizHawk.Client.EmuHawk private void SubtitlesMenuItem_Click(object sender, EventArgs e) { - var form = new EditSubtitlesForm { ReadOnly = false }; - form.GetMovie(CurrentTasMovie); + var form = new EditSubtitlesForm(CurrentTasMovie, false); form.ShowDialog(); }