From d864929ad4f69c49f07fc37a24ce08a5b0804af5 Mon Sep 17 00:00:00 2001 From: adelikat Date: Mon, 28 Oct 2013 01:31:30 +0000 Subject: [PATCH] Add Subtitle Form - fix bug where Y wasn't being saved. SubtitleList - refactor to inherit List and extend with the 2 useful methods it has beyond basic List functionality. --- BizHawk.Client.Common/movie/Movie.cs | 4 +- BizHawk.Client.Common/movie/MovieImport.cs | 2 +- BizHawk.Client.Common/movie/SubtitleList.cs | 65 ++----------------- BizHawk.MultiClient/MainForm.Events.cs | 2 +- .../movie/EditSubtitlesForm.cs | 7 +- BizHawk.MultiClient/movie/SubtitleMaker.cs | 1 + 6 files changed, 13 insertions(+), 68 deletions(-) diff --git a/BizHawk.Client.Common/movie/Movie.cs b/BizHawk.Client.Common/movie/Movie.cs index 689ad3953c..e82bb677bc 100644 --- a/BizHawk.Client.Common/movie/Movie.cs +++ b/BizHawk.Client.Common/movie/Movie.cs @@ -324,7 +324,7 @@ namespace BizHawk.Client.Common if (str.StartsWith("subtitle") || str.StartsWith("sub")) { - Subtitles.AddSubtitle(str); + Subtitles.AddFromString(str); } else if (str[0] == '|') { @@ -867,7 +867,7 @@ namespace BizHawk.Client.Common } else if (str.StartsWith("subtitle") || str.StartsWith("sub")) { - Subtitles.AddSubtitle(str); + Subtitles.AddFromString(str); } else if (Header.AddHeaderFromLine(str)) { diff --git a/BizHawk.Client.Common/movie/MovieImport.cs b/BizHawk.Client.Common/movie/MovieImport.cs index e91a6359cd..abb440da21 100644 --- a/BizHawk.Client.Common/movie/MovieImport.cs +++ b/BizHawk.Client.Common/movie/MovieImport.cs @@ -278,7 +278,7 @@ namespace BizHawk.Client.Common length = line.Substring(first + 1, second - first - 1); } string message = line.Substring(second + 1).Trim(); - m.Subtitles.AddSubtitle("subtitle " + frame + " 0 0 " + length + " FFFFFFFF " + message); + m.Subtitles.AddFromString("subtitle " + frame + " 0 0 " + length + " FFFFFFFF " + message); } return m; } diff --git a/BizHawk.Client.Common/movie/SubtitleList.cs b/BizHawk.Client.Common/movie/SubtitleList.cs index 83aa8e6d07..3417f93bd9 100644 --- a/BizHawk.Client.Common/movie/SubtitleList.cs +++ b/BizHawk.Client.Common/movie/SubtitleList.cs @@ -8,54 +8,14 @@ using System.IO; namespace BizHawk.Client.Common { - public class SubtitleList : IEnumerable + public class SubtitleList : List { - private readonly List _subtitles = new List(); - - public SubtitleList() { } - - public SubtitleList(IEnumerable subtitles) - { - foreach (var subtitle in subtitles) - { - _subtitles.Add(new Subtitle(subtitle)); //TODO: Multiclient.EditSubtitlesForm needs a deep copy here, refactor it so that it doesn't - } - } - - public IEnumerator GetEnumerator() - { - return _subtitles.GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } - - public Subtitle this[int index] - { - get - { - return _subtitles[index]; - } - } - public IEnumerable GetSubtitles(int frame) { - return _subtitles.Where(t => frame >= t.Frame && frame <= t.Frame + t.Duration); + return this.Where(t => frame >= t.Frame && frame <= t.Frame + t.Duration); } - public int Count - { - get { return _subtitles.Count; } - } - - /// - /// Attempts to parse string for necessary subtitle information, required is a frame and a message, space delminated, the word subtitle assumed to be first - /// - /// - /// - public bool AddSubtitle(string subtitleStr) + public bool AddFromString(string subtitleStr) { if (!String.IsNullOrWhiteSpace(subtitleStr)) { @@ -70,7 +30,7 @@ namespace BizHawk.Client.Common message += subparts[i] + ' '; } - _subtitles.Add(new Subtitle() + Add(new Subtitle() { Frame = int.Parse(subparts[1]), X = int.Parse(subparts[2]), @@ -92,22 +52,5 @@ namespace BizHawk.Client.Common return false; } } - - public void AddSubtitle(Subtitle subtitle) - { - _subtitles.Add(subtitle); - } - - public void Clear() - { - _subtitles.Clear(); - } - - public void RemoveAt(int index) - { - if (index >= _subtitles.Count) return; - - _subtitles.RemoveAt(index); - } } } \ No newline at end of file diff --git a/BizHawk.MultiClient/MainForm.Events.cs b/BizHawk.MultiClient/MainForm.Events.cs index 888b753212..1f5f74efb4 100644 --- a/BizHawk.MultiClient/MainForm.Events.cs +++ b/BizHawk.MultiClient/MainForm.Events.cs @@ -1946,7 +1946,7 @@ namespace BizHawk.MultiClient Global.MovieSession.Movie.Subtitles.RemoveAt(index); } - Global.MovieSession.Movie.Subtitles.AddSubtitle(subForm.sub); + Global.MovieSession.Movie.Subtitles.Add(subForm.sub); } } diff --git a/BizHawk.MultiClient/movie/EditSubtitlesForm.cs b/BizHawk.MultiClient/movie/EditSubtitlesForm.cs index 46f884f80a..14a5b6714a 100644 --- a/BizHawk.MultiClient/movie/EditSubtitlesForm.cs +++ b/BizHawk.MultiClient/movie/EditSubtitlesForm.cs @@ -77,7 +77,7 @@ namespace BizHawk.MultiClient try { c = SubGrid.Rows[x].Cells[5]; } catch { ShowError(x, 5); return; } s.Message = c.Value.ToString(); - selectedMovie.Subtitles.AddSubtitle(s); + selectedMovie.Subtitles.Add(s); } selectedMovie.WriteMovie(); } @@ -87,7 +87,8 @@ namespace BizHawk.MultiClient public void GetMovie(Movie m) { selectedMovie = m; - SubtitleList subs = new SubtitleList(m.Subtitles); + SubtitleList subs = new SubtitleList(); + subs.AddRange(m.Subtitles); for (int x = 0; x < subs.Count; x++) { @@ -152,7 +153,7 @@ namespace BizHawk.MultiClient c = SubGrid.Rows[index].Cells[5]; try { s.Message = c.Value.ToString(); } catch { } - selectedMovie.Subtitles.AddSubtitle(s); + selectedMovie.Subtitles.Add(s); return s; } diff --git a/BizHawk.MultiClient/movie/SubtitleMaker.cs b/BizHawk.MultiClient/movie/SubtitleMaker.cs index 0c6fa50f96..edeb7080bb 100644 --- a/BizHawk.MultiClient/movie/SubtitleMaker.cs +++ b/BizHawk.MultiClient/movie/SubtitleMaker.cs @@ -30,6 +30,7 @@ namespace BizHawk.MultiClient sub.Frame = (int)FrameNumeric.Value; sub.Message = Message.Text; sub.X = (int)XNumeric.Value; + sub.Y = (int)YNumeric.Value; sub.Duration = (int)DurationNumeric.Value; sub.Color = (uint)colorDialog1.Color.ToArgb(); DialogResult = DialogResult.OK;