From 61e82793e96cf6df9de9fd28bd10f42271e8c72c Mon Sep 17 00:00:00 2001 From: "andres.delikat" Date: Sun, 26 Jun 2011 14:36:41 +0000 Subject: [PATCH] Start movie subtitle system --- .../BizHawk.MultiClient.csproj | 2 + BizHawk.MultiClient/movie/Movie.cs | 17 ++++- BizHawk.MultiClient/movie/Subtitle.cs | 34 +++++++++ BizHawk.MultiClient/movie/SubtitleList.cs | 70 +++++++++++++++++++ 4 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 BizHawk.MultiClient/movie/Subtitle.cs create mode 100644 BizHawk.MultiClient/movie/SubtitleList.cs diff --git a/BizHawk.MultiClient/BizHawk.MultiClient.csproj b/BizHawk.MultiClient/BizHawk.MultiClient.csproj index 17b3fbd487..2b97d3fe1d 100644 --- a/BizHawk.MultiClient/BizHawk.MultiClient.csproj +++ b/BizHawk.MultiClient/BizHawk.MultiClient.csproj @@ -155,6 +155,8 @@ + + Form diff --git a/BizHawk.MultiClient/movie/Movie.cs b/BizHawk.MultiClient/movie/Movie.cs index 6d803cafbb..d7a0961268 100644 --- a/BizHawk.MultiClient/movie/Movie.cs +++ b/BizHawk.MultiClient/movie/Movie.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; +using System.Drawing; namespace BizHawk.MultiClient { @@ -11,6 +12,7 @@ namespace BizHawk.MultiClient { private MovieHeader Header = new MovieHeader(); private MovieLog Log = new MovieLog(); + private SubtitleList Subtitles = new SubtitleList(); private bool IsText = true; private string Filename; @@ -23,8 +25,15 @@ namespace BizHawk.MultiClient public int lastLog; public int rerecordCount; - //TODO: - //Author field, needs to be passed in play dialog + public string GetSubtitle(int frame) + { + return Subtitles.GetSubtitle(frame); + } + + public Point GetSutitlePoint(int frame) + { + return Subtitles.GetSubtitlePoint(frame); + } public Movie(string filename, MOVIEMODE m) { @@ -247,6 +256,10 @@ namespace BizHawk.MultiClient str = ParseHeader(str, MovieHeader.AUTHOR); Header.AddHeaderLine(MovieHeader.AUTHOR, str); } + else if (str.StartsWith("subtitle") || str.StartsWith("sub")) + { + Subtitles.AddSubtitle(str); + } else if (str[0] == '|') { Log.AddFrame(str); diff --git a/BizHawk.MultiClient/movie/Subtitle.cs b/BizHawk.MultiClient/movie/Subtitle.cs new file mode 100644 index 0000000000..aad1eee5fc --- /dev/null +++ b/BizHawk.MultiClient/movie/Subtitle.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BizHawk.MultiClient +{ + class Subtitle + { + public string Message; + public int Frame; + public int X; + public int Y; + public int Duration; + + public Subtitle() + { + Message = ""; + X = 0; + Y = 0; + Duration = 0; + Frame = 0; + } + + public Subtitle(string message, int x, int y, int dur, int frame) + { + Message = message; + Frame = frame; + X = x; + Y = y; + Duration = dur; + } + } +} diff --git a/BizHawk.MultiClient/movie/SubtitleList.cs b/BizHawk.MultiClient/movie/SubtitleList.cs new file mode 100644 index 0000000000..7affb4697e --- /dev/null +++ b/BizHawk.MultiClient/movie/SubtitleList.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Drawing; + +namespace BizHawk.MultiClient +{ + class SubtitleList + { + private List subs = new List(); + + public SubtitleList() + { + + } + /// + /// Manages the logic of what subtitle should be displayed on any given frame based on frame & duration + /// + /// + /// + public string GetSubtitle(int frame) + { + if (subs.Count == 0) return ""; + + for (int x = 0; x < subs.Count; x++) + { + if (subs[x].Frame + subs[x].Duration >= frame) + return subs[x].Message; + } + return ""; + } + + public Point GetSubtitlePoint(int frame) + { + Point p = new Point(0, 0); + return p; + } + + /// + /// 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) + { + if (subtitleStr.Length == 0) return false; + + Subtitle s = new Subtitle(); + + int x = subtitleStr.IndexOf(' '); + if (x <= 0) return false; + + string str = subtitleStr.Substring(x, subtitleStr.Length - x); + try + { + s.Frame = Int16.Parse(str); + } + catch + { + return false; + } + + x = str.IndexOf(' '); + + + return true; + } + } +}