add some movie related objects to client.common, and refactor some things too

This commit is contained in:
adelikat 2013-10-21 01:50:58 +00:00
parent f04efe0294
commit bce6ec3dd6
10 changed files with 127 additions and 150 deletions

View File

@ -52,6 +52,9 @@
<Compile Include="Global.cs" /> <Compile Include="Global.cs" />
<Compile Include="helpers\InputValidate.cs" /> <Compile Include="helpers\InputValidate.cs" />
<Compile Include="KeyTurbo.cs" /> <Compile Include="KeyTurbo.cs" />
<Compile Include="movie\MovieHeader.cs" />
<Compile Include="movie\Subtitle.cs" />
<Compile Include="movie\SubtitleList.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RecentFiles.cs" /> <Compile Include="RecentFiles.cs" />
<Compile Include="helpers\StringHelpers.cs" /> <Compile Include="helpers\StringHelpers.cs" />

View File

@ -1,10 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using BizHawk.Client.Common; namespace BizHawk.Client.Common
namespace BizHawk.MultiClient
{ {
public class MovieHeader public class MovieHeader
{ {
@ -55,16 +52,10 @@ namespace BizHawk.MultiClient
return System.Guid.NewGuid().ToString(); return System.Guid.NewGuid().ToString();
} }
public MovieHeader() //All required fields will be set to default values public MovieHeader(string version) //All required fields will be set to default values
{ {
if (GlobalWinF.MainForm != null)
{ HeaderParams.Add(EMULATIONVERSION, version);
HeaderParams.Add(EMULATIONVERSION, GlobalWinF.MainForm.GetEmuVersion());
}
else
{
HeaderParams.Add(EMULATIONVERSION, MainForm.EMUVERSION);
}
HeaderParams.Add(MOVIEVERSION, MovieVersion); HeaderParams.Add(MOVIEVERSION, MovieVersion);
HeaderParams.Add(PLATFORM, ""); HeaderParams.Add(PLATFORM, "");
HeaderParams.Add(GAMENAME, ""); HeaderParams.Add(GAMENAME, "");
@ -285,15 +276,12 @@ namespace BizHawk.MultiClient
public void ReadHeader(StreamReader reader) public void ReadHeader(StreamReader reader)
{ {
using (reader) string str;
while ((str = reader.ReadLine()) != null)
{ {
string str; AddHeaderFromLine(str);
while ((str = reader.ReadLine()) != null)
{
AddHeaderFromLine(str);
}
reader.Close();
} }
reader.Close();
} }
} }
} }

View File

@ -0,0 +1,49 @@
using System;
using System.Text;
namespace BizHawk.Client.Common
{
public class Subtitle
{
public string Message { get; set; }
public int Frame { get; set; }
public int X { get; set; }
public int Y { get; set; }
public int Duration { get; set; }
public uint Color { get; set; }
public Subtitle()
{
Message = String.Empty;
X = 0;
Y = 0;
Duration = 120;
Frame = 0;
Color = 0xFFFFFFFF;
}
public Subtitle(Subtitle s)
{
Message = s.Message;
Frame = s.Frame;
X = s.X;
Y = s.Y;
Duration = s.Duration;
Color = s.Color;
}
public override string ToString()
{
StringBuilder sb = new StringBuilder("subtitle ");
sb
.Append(Frame.ToString()).Append(" ")
.Append(X.ToString()).Append(" ")
.Append(Y.ToString()).Append(" ")
.Append(Duration.ToString()).Append(" ")
.Append(String.Format("{0:X8}", Color)).Append(" ")
.Append(Message);
return sb.ToString();
}
}
}

View File

@ -1,62 +1,46 @@
using System.Collections.Generic; using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using BizHawk.Client.Common;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
public class SubtitleList public class SubtitleList : IEnumerable<Subtitle>
{ {
private readonly List<Subtitle> subs = new List<Subtitle>(); private readonly List<Subtitle> _subtitles = new List<Subtitle>();
public SubtitleList() public SubtitleList() { }
public SubtitleList(SubtitleList subtitles)
{ {
foreach (var subtitle in subtitles)
}
public SubtitleList(Movie m)
{
if (m != null && m.Subtitles.Count == 0)
{ {
return; _subtitles.Add(new Subtitle(subtitle)); //TODO: Multiclient.EditSubtitlesForm needs a deep copy here, refactor it so that it doesn't
}
for (int x = 0; x < m.Subtitles.Count; x++)
{
Subtitle s = new Subtitle(m.Subtitles.GetSubtitleByIndex(x));
subs.Add(s);
} }
} }
public Subtitle GetSubtitleByIndex(int index) public IEnumerator<Subtitle> GetEnumerator()
{ {
if (index >= subs.Count || index < 0) return new Subtitle(); return _subtitles.GetEnumerator();
return subs[index];
} }
public string GetSubtitleText(int index) IEnumerator IEnumerable.GetEnumerator()
{ {
if (index >= subs.Count || index < 0) return GetEnumerator();
{ }
return "";
}
StringBuilder sb = new StringBuilder("subtitle "); public Subtitle this[int index]
sb.Append(subs[index].Frame.ToString()); {
sb.Append(" "); get
sb.Append(subs[index].X.ToString()); {
sb.Append(" "); return _subtitles[index];
sb.Append(subs[index].Y.ToString()); }
sb.Append(" ");
sb.Append(subs[index].Duration.ToString());
sb.Append(" ");
sb.Append(string.Format("{0:X8}", subs[index].Color));
sb.Append(" ");
sb.Append(subs[index].Message);
return sb.ToString();
} }
/// <summary> /// <summary>
@ -66,45 +50,42 @@ namespace BizHawk.MultiClient
/// <returns></returns> /// <returns></returns>
public string GetSubtitleMessage(int frame) public string GetSubtitleMessage(int frame)
{ {
if (subs.Count == 0) return ""; if (_subtitles.Count == 0) return "";
foreach (Subtitle t in subs) foreach (Subtitle t in _subtitles)
{ {
if (frame >= t.Frame && frame <= t.Frame + t.Duration) if (frame >= t.Frame && frame <= t.Frame + t.Duration)
{ {
return t.Message; return t.Message;
} }
} }
return ""; return String.Empty;
} }
public Subtitle GetSubtitle(int frame) public Subtitle GetSubtitle(int frame)
{ {
if (subs.Count == 0) return new Subtitle(); if (_subtitles.Any())
foreach (Subtitle t in subs)
{ {
if (frame >= t.Frame && frame <= t.Frame + t.Duration) foreach (Subtitle t in _subtitles)
{ {
return t; if (frame >= t.Frame && frame <= t.Frame + t.Duration)
{
return t;
}
} }
} }
return new Subtitle(); return new Subtitle();
} }
public List<Subtitle> GetSubtitles(int frame) public List<Subtitle> GetSubtitles(int frame)
{ {
if (subs.Count == 0) return _subtitles.Where(t => frame >= t.Frame && frame <= t.Frame + t.Duration).ToList();
{
return null;
}
return subs.Where(t => frame >= t.Frame && frame <= t.Frame + t.Duration).ToList();
} }
public int Count public int Count
{ {
get { return subs.Count; } get { return _subtitles.Count; }
} }
//TODO //TODO
@ -119,9 +100,12 @@ namespace BizHawk.MultiClient
/// </summary> /// </summary>
/// <param name="subtitleStr"></param> /// <param name="subtitleStr"></param>
/// <returns></returns> /// <returns></returns>
public bool AddSubtitle(string subtitleStr) public bool AddSubtitle(string subtitleStr) //TODO: refactor with String.Split
{ {
if (subtitleStr.Length == 0) return false; if (!String.IsNullOrWhiteSpace(subtitleStr))
{
return false;
}
Subtitle s = new Subtitle(); Subtitle s = new Subtitle();
@ -199,34 +183,33 @@ namespace BizHawk.MultiClient
} }
s.Message = str; s.Message = str;
subs.Add(s); _subtitles.Add(s);
return true; return true;
} }
public void AddSubtitle(Subtitle s) public void AddSubtitle(Subtitle s)
{ {
subs.Add(s); _subtitles.Add(s);
} }
public void ClearSubtitles() public void Clear()
{ {
subs.Clear(); _subtitles.Clear();
} }
public void Remove(int index) public void RemoveAt(int index)
{ {
if (index >= subs.Count) return; if (index >= _subtitles.Count) return;
subs.RemoveAt(index); _subtitles.RemoveAt(index);
} }
public void WriteText(StreamWriter sw) public void WriteText(StreamWriter sw)
{ {
int length = subs.Count; foreach(var subtitle in _subtitles)
for (int x = 0; x < length; x++)
{ {
sw.WriteLine(GetSubtitleText(x)); sw.WriteLine(subtitle.ToString());
} }
} }
} }

View File

@ -358,7 +358,6 @@
<DependentUpon>EditSubtitlesForm.cs</DependentUpon> <DependentUpon>EditSubtitlesForm.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="movie\Movie.cs" /> <Compile Include="movie\Movie.cs" />
<Compile Include="movie\MovieHeader.cs" />
<Compile Include="movie\MovieImport.cs" /> <Compile Include="movie\MovieImport.cs" />
<Compile Include="movie\MovieLog.cs" /> <Compile Include="movie\MovieLog.cs" />
<Compile Include="movie\MovieMnemonics.cs" /> <Compile Include="movie\MovieMnemonics.cs" />
@ -376,8 +375,6 @@
<Compile Include="movie\RecordMovie.Designer.cs"> <Compile Include="movie\RecordMovie.Designer.cs">
<DependentUpon>RecordMovie.cs</DependentUpon> <DependentUpon>RecordMovie.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="movie\Subtitle.cs" />
<Compile Include="movie\SubtitleList.cs" />
<Compile Include="movie\SubtitleMaker.cs"> <Compile Include="movie\SubtitleMaker.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>

View File

@ -860,7 +860,7 @@ namespace BizHawk.MultiClient
Subtitle sub = new Subtitle(); Subtitle sub = new Subtitle();
for (int x = 0; x < GlobalWinF.MovieSession.Movie.Subtitles.Count; x++) for (int x = 0; x < GlobalWinF.MovieSession.Movie.Subtitles.Count; x++)
{ {
sub = GlobalWinF.MovieSession.Movie.Subtitles.GetSubtitleByIndex(x); sub = GlobalWinF.MovieSession.Movie.Subtitles[x];
if (Global.Emulator.Frame == sub.Frame) if (Global.Emulator.Frame == sub.Frame)
{ {
index = x; index = x;
@ -876,7 +876,7 @@ namespace BizHawk.MultiClient
if (s.ShowDialog() == DialogResult.OK) if (s.ShowDialog() == DialogResult.OK)
{ {
if (index >= 0) if (index >= 0)
GlobalWinF.MovieSession.Movie.Subtitles.Remove(index); GlobalWinF.MovieSession.Movie.Subtitles.RemoveAt(index);
GlobalWinF.MovieSession.Movie.Subtitles.AddSubtitle(s.sub); GlobalWinF.MovieSession.Movie.Subtitles.AddSubtitle(s.sub);
} }
} }

View File

@ -3,6 +3,8 @@ using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using System.Globalization; using System.Globalization;
using BizHawk.Client.Common;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
public partial class EditSubtitlesForm : Form public partial class EditSubtitlesForm : Form
@ -53,7 +55,7 @@ namespace BizHawk.MultiClient
{ {
if (!ReadOnly) if (!ReadOnly)
{ {
selectedMovie.Subtitles.ClearSubtitles(); selectedMovie.Subtitles.Clear();
for (int x = 0; x < SubGrid.Rows.Count - 1; x++) for (int x = 0; x < SubGrid.Rows.Count - 1; x++)
{ {
Subtitle s = new Subtitle(); Subtitle s = new Subtitle();
@ -86,12 +88,12 @@ namespace BizHawk.MultiClient
public void GetMovie(Movie m) public void GetMovie(Movie m)
{ {
selectedMovie = m; selectedMovie = m;
SubtitleList subs = new SubtitleList(m); SubtitleList subs = new SubtitleList(m.Subtitles);
if (subs.Count == 0) return; if (subs.Count == 0) return;
for (int x = 0; x < subs.Count; x++) for (int x = 0; x < subs.Count; x++)
{ {
Subtitle s = subs.GetSubtitleByIndex(x); Subtitle s = subs[x];
SubGrid.Rows.Add(); SubGrid.Rows.Add();
DataGridViewCell c = SubGrid.Rows[x].Cells[0]; DataGridViewCell c = SubGrid.Rows[x].Cells[0];
c.Value = s.Frame; c.Value = s.Frame;

View File

@ -12,33 +12,30 @@ namespace BizHawk.MultiClient
#region Constructors #region Constructors
public Movie(string filename) public Movie(string filename)
: this()
{ {
Mode = MOVIEMODE.INACTIVE;
Rerecords = 0; Rerecords = 0;
Filename = filename; Filename = filename;
IsText = true; Loaded = filename.Length > 0;
preload_framecount = 0;
IsCountingRerecords = true;
StartsFromSavestate = false;
if (filename.Length > 0)
Loaded = true;
} }
public Movie() public Movie()
{ {
Filename = ""; Filename = String.Empty;
Mode = MOVIEMODE.INACTIVE;
IsText = true;
preload_framecount = 0; preload_framecount = 0;
StartsFromSavestate = false; StartsFromSavestate = false;
Loaded = false;
IsCountingRerecords = true; IsCountingRerecords = true;
Mode = MOVIEMODE.INACTIVE;
IsText = true;
string version = GlobalWinF.MainForm != null ? GlobalWinF.MainForm.GetEmuVersion() : MainForm.EMUVERSION;
Header = new MovieHeader(version);
} }
#endregion #endregion
#region Properties #region Properties
public MovieHeader Header = new MovieHeader(); public MovieHeader Header;
public SubtitleList Subtitles = new SubtitleList(); public SubtitleList Subtitles = new SubtitleList();
public bool MakeBackup = true; //make backup before altering movie public bool MakeBackup = true; //make backup before altering movie

View File

@ -1,44 +0,0 @@
using System;
namespace BizHawk.MultiClient
{
public class Subtitle
{
public string Message;
public int Frame;
public int X;
public int Y;
public int Duration;
public uint Color;
public Subtitle()
{
Message = "";
X = 0;
Y = 0;
Duration = 120;
Frame = 0;
Color = 0xFFFFFFFF;
}
public Subtitle(string message, int x, int y, int dur, int frame, UInt32 color)
{
Message = message;
Frame = frame;
X = x;
Y = y;
Duration = dur;
Color = color;
}
public Subtitle(Subtitle s)
{
Message = s.Message;
Frame = s.Frame;
X = s.X;
Y = s.Y;
Duration = s.Duration;
Color = s.Color;
}
}
}

View File

@ -2,6 +2,8 @@
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Client.Common;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
public partial class SubtitleMaker : Form public partial class SubtitleMaker : Form