add some movie related objects to client.common, and refactor some things too
This commit is contained in:
parent
f04efe0294
commit
bce6ec3dd6
|
@ -52,6 +52,9 @@
|
|||
<Compile Include="Global.cs" />
|
||||
<Compile Include="helpers\InputValidate.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="RecentFiles.cs" />
|
||||
<Compile Include="helpers\StringHelpers.cs" />
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using BizHawk.Client.Common;
|
||||
|
||||
namespace BizHawk.MultiClient
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
public class MovieHeader
|
||||
{
|
||||
|
@ -55,16 +52,10 @@ namespace BizHawk.MultiClient
|
|||
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, GlobalWinF.MainForm.GetEmuVersion());
|
||||
}
|
||||
else
|
||||
{
|
||||
HeaderParams.Add(EMULATIONVERSION, MainForm.EMUVERSION);
|
||||
}
|
||||
|
||||
HeaderParams.Add(EMULATIONVERSION, version);
|
||||
HeaderParams.Add(MOVIEVERSION, MovieVersion);
|
||||
HeaderParams.Add(PLATFORM, "");
|
||||
HeaderParams.Add(GAMENAME, "");
|
||||
|
@ -285,15 +276,12 @@ namespace BizHawk.MultiClient
|
|||
|
||||
public void ReadHeader(StreamReader reader)
|
||||
{
|
||||
using (reader)
|
||||
string str;
|
||||
while ((str = reader.ReadLine()) != null)
|
||||
{
|
||||
string str;
|
||||
while ((str = reader.ReadLine()) != null)
|
||||
{
|
||||
AddHeaderFromLine(str);
|
||||
}
|
||||
reader.Close();
|
||||
AddHeaderFromLine(str);
|
||||
}
|
||||
reader.Close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,62 +1,46 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
|
||||
using BizHawk.Client.Common;
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public SubtitleList(Movie m)
|
||||
{
|
||||
if (m != null && m.Subtitles.Count == 0)
|
||||
foreach (var subtitle in subtitles)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int x = 0; x < m.Subtitles.Count; x++)
|
||||
{
|
||||
Subtitle s = new Subtitle(m.Subtitles.GetSubtitleByIndex(x));
|
||||
subs.Add(s);
|
||||
_subtitles.Add(new Subtitle(subtitle)); //TODO: Multiclient.EditSubtitlesForm needs a deep copy here, refactor it so that it doesn't
|
||||
}
|
||||
}
|
||||
|
||||
public Subtitle GetSubtitleByIndex(int index)
|
||||
public IEnumerator<Subtitle> GetEnumerator()
|
||||
{
|
||||
if (index >= subs.Count || index < 0) return new Subtitle();
|
||||
|
||||
return subs[index];
|
||||
return _subtitles.GetEnumerator();
|
||||
}
|
||||
|
||||
public string GetSubtitleText(int index)
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
if (index >= subs.Count || index < 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder("subtitle ");
|
||||
sb.Append(subs[index].Frame.ToString());
|
||||
sb.Append(" ");
|
||||
sb.Append(subs[index].X.ToString());
|
||||
sb.Append(" ");
|
||||
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();
|
||||
public Subtitle this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
return _subtitles[index];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -66,45 +50,42 @@ namespace BizHawk.MultiClient
|
|||
/// <returns></returns>
|
||||
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)
|
||||
{
|
||||
return t.Message;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
public Subtitle GetSubtitle(int frame)
|
||||
{
|
||||
if (subs.Count == 0) return new Subtitle();
|
||||
|
||||
foreach (Subtitle t in subs)
|
||||
if (_subtitles.Any())
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
public List<Subtitle> GetSubtitles(int frame)
|
||||
{
|
||||
if (subs.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return subs.Where(t => frame >= t.Frame && frame <= t.Frame + t.Duration).ToList();
|
||||
return _subtitles.Where(t => frame >= t.Frame && frame <= t.Frame + t.Duration).ToList();
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return subs.Count; }
|
||||
get { return _subtitles.Count; }
|
||||
}
|
||||
|
||||
//TODO
|
||||
|
@ -119,9 +100,12 @@ namespace BizHawk.MultiClient
|
|||
/// </summary>
|
||||
/// <param name="subtitleStr"></param>
|
||||
/// <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();
|
||||
|
||||
|
@ -199,34 +183,33 @@ namespace BizHawk.MultiClient
|
|||
}
|
||||
|
||||
s.Message = str;
|
||||
subs.Add(s);
|
||||
_subtitles.Add(s);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
int length = subs.Count;
|
||||
for (int x = 0; x < length; x++)
|
||||
foreach(var subtitle in _subtitles)
|
||||
{
|
||||
sw.WriteLine(GetSubtitleText(x));
|
||||
sw.WriteLine(subtitle.ToString());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -358,7 +358,6 @@
|
|||
<DependentUpon>EditSubtitlesForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="movie\Movie.cs" />
|
||||
<Compile Include="movie\MovieHeader.cs" />
|
||||
<Compile Include="movie\MovieImport.cs" />
|
||||
<Compile Include="movie\MovieLog.cs" />
|
||||
<Compile Include="movie\MovieMnemonics.cs" />
|
||||
|
@ -376,8 +375,6 @@
|
|||
<Compile Include="movie\RecordMovie.Designer.cs">
|
||||
<DependentUpon>RecordMovie.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="movie\Subtitle.cs" />
|
||||
<Compile Include="movie\SubtitleList.cs" />
|
||||
<Compile Include="movie\SubtitleMaker.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
|
|
@ -860,7 +860,7 @@ namespace BizHawk.MultiClient
|
|||
Subtitle sub = new Subtitle();
|
||||
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)
|
||||
{
|
||||
index = x;
|
||||
|
@ -876,7 +876,7 @@ namespace BizHawk.MultiClient
|
|||
if (s.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (index >= 0)
|
||||
GlobalWinF.MovieSession.Movie.Subtitles.Remove(index);
|
||||
GlobalWinF.MovieSession.Movie.Subtitles.RemoveAt(index);
|
||||
GlobalWinF.MovieSession.Movie.Subtitles.AddSubtitle(s.sub);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ using System.Drawing;
|
|||
using System.Windows.Forms;
|
||||
using System.Globalization;
|
||||
|
||||
using BizHawk.Client.Common;
|
||||
|
||||
namespace BizHawk.MultiClient
|
||||
{
|
||||
public partial class EditSubtitlesForm : Form
|
||||
|
@ -53,7 +55,7 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
if (!ReadOnly)
|
||||
{
|
||||
selectedMovie.Subtitles.ClearSubtitles();
|
||||
selectedMovie.Subtitles.Clear();
|
||||
for (int x = 0; x < SubGrid.Rows.Count - 1; x++)
|
||||
{
|
||||
Subtitle s = new Subtitle();
|
||||
|
@ -86,12 +88,12 @@ namespace BizHawk.MultiClient
|
|||
public void GetMovie(Movie m)
|
||||
{
|
||||
selectedMovie = m;
|
||||
SubtitleList subs = new SubtitleList(m);
|
||||
SubtitleList subs = new SubtitleList(m.Subtitles);
|
||||
if (subs.Count == 0) return;
|
||||
|
||||
for (int x = 0; x < subs.Count; x++)
|
||||
{
|
||||
Subtitle s = subs.GetSubtitleByIndex(x);
|
||||
Subtitle s = subs[x];
|
||||
SubGrid.Rows.Add();
|
||||
DataGridViewCell c = SubGrid.Rows[x].Cells[0];
|
||||
c.Value = s.Frame;
|
||||
|
|
|
@ -12,33 +12,30 @@ namespace BizHawk.MultiClient
|
|||
#region Constructors
|
||||
|
||||
public Movie(string filename)
|
||||
: this()
|
||||
{
|
||||
Mode = MOVIEMODE.INACTIVE;
|
||||
Rerecords = 0;
|
||||
Filename = filename;
|
||||
IsText = true;
|
||||
preload_framecount = 0;
|
||||
IsCountingRerecords = true;
|
||||
StartsFromSavestate = false;
|
||||
if (filename.Length > 0)
|
||||
Loaded = true;
|
||||
Loaded = filename.Length > 0;
|
||||
}
|
||||
|
||||
public Movie()
|
||||
{
|
||||
Filename = "";
|
||||
Mode = MOVIEMODE.INACTIVE;
|
||||
IsText = true;
|
||||
Filename = String.Empty;
|
||||
preload_framecount = 0;
|
||||
StartsFromSavestate = false;
|
||||
Loaded = false;
|
||||
IsCountingRerecords = true;
|
||||
Mode = MOVIEMODE.INACTIVE;
|
||||
IsText = true;
|
||||
|
||||
string version = GlobalWinF.MainForm != null ? GlobalWinF.MainForm.GetEmuVersion() : MainForm.EMUVERSION;
|
||||
Header = new MovieHeader(version);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
public MovieHeader Header = new MovieHeader();
|
||||
public MovieHeader Header;
|
||||
public SubtitleList Subtitles = new SubtitleList();
|
||||
|
||||
public bool MakeBackup = true; //make backup before altering movie
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,8 @@
|
|||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using BizHawk.Client.Common;
|
||||
|
||||
namespace BizHawk.MultiClient
|
||||
{
|
||||
public partial class SubtitleMaker : Form
|
||||
|
|
Loading…
Reference in New Issue