diff --git a/BizHawk.Client.Common/movie/Subtitle.cs b/BizHawk.Client.Common/movie/Subtitle.cs
index 73d056ef2e..dee3fcd3d0 100644
--- a/BizHawk.Client.Common/movie/Subtitle.cs
+++ b/BizHawk.Client.Common/movie/Subtitle.cs
@@ -45,7 +45,7 @@ namespace BizHawk.Client.Common
return sb.ToString();
}
- public string ToSubRip(int index, double fps)
+ public string ToSubRip(int index, double fps, bool addcolortag)
{
var sb = new StringBuilder();
@@ -83,16 +83,23 @@ namespace BizHawk.Client.Common
// TODO: Positioning
// Color tag open
- uint rgb = (Color & 0x00FFFFFF);
- sb.Append("");
+ if (addcolortag)
+ {
+ uint rgb = (Color & 0x00FFFFFF);
+ sb.Append("");
+ }
// Message text
- sb.Append(Message);
+ sb.Append(Message.Trim());
- // Color tag close
- sb.Append("\r\n");
+ // Color tag closeaddcolortag
+ if (addcolortag)
+ {
+ sb.Append("");
+ }
+ sb.Append("\r\n");
// Seperator
sb.Append("\r\n");
diff --git a/BizHawk.Client.Common/movie/SubtitleList.cs b/BizHawk.Client.Common/movie/SubtitleList.cs
index a0570c4aa5..3e478a0e91 100644
--- a/BizHawk.Client.Common/movie/SubtitleList.cs
+++ b/BizHawk.Client.Common/movie/SubtitleList.cs
@@ -7,6 +7,15 @@ namespace BizHawk.Client.Common
{
public class SubtitleList : List
{
+ public bool ConcatMultilines { get; set; }
+ public bool AddColorTag { get; set; }
+
+ public SubtitleList()
+ {
+ ConcatMultilines = false;
+ AddColorTag = false;
+ }
+
public IEnumerable GetSubtitles(int frame)
{
return this.Where(t => frame >= t.Frame && frame <= t.Frame + t.Duration);
@@ -15,6 +24,7 @@ namespace BizHawk.Client.Common
public override string ToString()
{
var sb = new StringBuilder();
+ this.OrderBy(s => s.Frame).ThenBy(s => s.Y);
ForEach(subtitle => sb.AppendLine(subtitle.ToString()));
return sb.ToString();
}
@@ -41,7 +51,7 @@ namespace BizHawk.Client.Common
Y = int.Parse(subparts[3]),
Duration = int.Parse(subparts[4]),
Color = uint.Parse(subparts[5], NumberStyles.HexNumber),
- Message = message
+ Message = message.Trim()
});
return true;
@@ -58,11 +68,44 @@ namespace BizHawk.Client.Common
public string ToSubRip(double fps)
{
int index = 1;
+ var sb = new StringBuilder();
+ SubtitleList subs = new SubtitleList();
+ foreach (var subtitle in this)
+ subs.Add(subtitle);
- var sb = new StringBuilder();
+ // absense of line wrap forces miltiline subtitle macros
+ // so we sort them just in case and optionally concat back to a single unit
+ // todo: instead of making this pretty, add the line wrap feature to subtitles
+ if (ConcatMultilines)
+ {
+ int lastframe = 0;
+ subs.OrderBy(s => s.Frame).ThenBy(s => s.Y);
- foreach (var subtitle in this)
- sb.Append(subtitle.ToSubRip(index++, fps));
+ for (int i = 0; ; i++)
+ {
+ if (i == subs.Count()) // we're modifying it
+ break;
+
+ subs[i].Message = subs[i].Message.Trim();
+
+ if (i > 0 && lastframe == subs[i].Frame)
+ {
+ subs[i].Message = subs[i - 1].Message + " " + subs[i].Message;
+ subs.Remove(subs[i - 1]);
+ i--;
+ }
+
+ lastframe = subs[i].Frame;
+ }
+ }
+ else
+ {
+ // srt stacks musltilines upwards
+ subs.OrderBy(s => s.Frame).ThenByDescending(s => s.Y);
+ }
+
+ foreach (var subtitle in subs)
+ sb.Append(subtitle.ToSubRip(index++, fps, AddColorTag));
return sb.ToString();
}
diff --git a/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs b/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs
index e2f0b36048..d5e4bed262 100644
--- a/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs
+++ b/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using System.Linq;
using BizHawk.Common;
@@ -96,6 +97,7 @@ namespace BizHawk.Client.Common
Subtitles.AddFromString(line);
}
}
+ Subtitles.OrderBy(s => s.Frame).ThenBy(s => s.Y);
});
}
diff --git a/BizHawk.Client.EmuHawk/movie/EditSubtitlesForm.Designer.cs b/BizHawk.Client.EmuHawk/movie/EditSubtitlesForm.Designer.cs
index 96726bd739..a7da08ec91 100644
--- a/BizHawk.Client.EmuHawk/movie/EditSubtitlesForm.Designer.cs
+++ b/BizHawk.Client.EmuHawk/movie/EditSubtitlesForm.Designer.cs
@@ -39,6 +39,9 @@
this.DispColor = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Message = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Export = new System.Windows.Forms.Button();
+ this.ConcatMultilines = new System.Windows.Forms.CheckBox();
+ this.AddColorTag = new System.Windows.Forms.CheckBox();
+ this.label1 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.SubGrid)).BeginInit();
this.SuspendLayout();
//
@@ -139,14 +142,48 @@
//
this.Export.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.Export.Location = new System.Drawing.Point(12, 216);
- this.Export.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
+ this.Export.Margin = new System.Windows.Forms.Padding(2);
this.Export.Name = "Export";
- this.Export.Size = new System.Drawing.Size(94, 23);
+ this.Export.Size = new System.Drawing.Size(95, 23);
this.Export.TabIndex = 3;
this.Export.Text = "&Export to SubRip";
this.Export.UseVisualStyleBackColor = true;
this.Export.Click += new System.EventHandler(this.Export_Click);
//
+ // ConcatMultilines
+ //
+ this.ConcatMultilines.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.ConcatMultilines.AutoSize = true;
+ this.ConcatMultilines.Location = new System.Drawing.Point(182, 220);
+ this.ConcatMultilines.Name = "ConcatMultilines";
+ this.ConcatMultilines.Size = new System.Drawing.Size(105, 17);
+ this.ConcatMultilines.TabIndex = 4;
+ this.ConcatMultilines.Text = "Concat multilines";
+ this.ConcatMultilines.UseVisualStyleBackColor = true;
+ this.ConcatMultilines.CheckedChanged += new System.EventHandler(this.ConcatMultilines_CheckedChanged);
+ //
+ // AddColorTag
+ //
+ this.AddColorTag.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.AddColorTag.AutoSize = true;
+ this.AddColorTag.Location = new System.Drawing.Point(293, 220);
+ this.AddColorTag.Name = "AddColorTag";
+ this.AddColorTag.Size = new System.Drawing.Size(89, 17);
+ this.AddColorTag.TabIndex = 5;
+ this.AddColorTag.Text = "Add color tag";
+ this.AddColorTag.UseVisualStyleBackColor = true;
+ this.AddColorTag.CheckedChanged += new System.EventHandler(this.AddColorTag_CheckedChanged);
+ //
+ // label1
+ //
+ this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(120, 221);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(56, 13);
+ this.label1.TabIndex = 6;
+ this.label1.Text = "On export:";
+ //
// EditSubtitlesForm
//
this.AcceptButton = this.OK;
@@ -154,6 +191,9 @@
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.Cancel;
this.ClientSize = new System.Drawing.Size(572, 251);
+ this.Controls.Add(this.label1);
+ this.Controls.Add(this.AddColorTag);
+ this.Controls.Add(this.ConcatMultilines);
this.Controls.Add(this.Export);
this.Controls.Add(this.SubGrid);
this.Controls.Add(this.OK);
@@ -166,6 +206,7 @@
this.Load += new System.EventHandler(this.EditSubtitlesForm_Load);
((System.ComponentModel.ISupportInitialize)(this.SubGrid)).EndInit();
this.ResumeLayout(false);
+ this.PerformLayout();
}
@@ -181,5 +222,8 @@
private System.Windows.Forms.DataGridViewTextBoxColumn Length;
private System.Windows.Forms.DataGridViewTextBoxColumn DispColor;
private System.Windows.Forms.DataGridViewTextBoxColumn Message;
+ private System.Windows.Forms.CheckBox ConcatMultilines;
+ private System.Windows.Forms.CheckBox AddColorTag;
+ private System.Windows.Forms.Label label1;
}
}
\ No newline at end of file
diff --git a/BizHawk.Client.EmuHawk/movie/EditSubtitlesForm.cs b/BizHawk.Client.EmuHawk/movie/EditSubtitlesForm.cs
index dd68e9313b..373a963add 100644
--- a/BizHawk.Client.EmuHawk/movie/EditSubtitlesForm.cs
+++ b/BizHawk.Client.EmuHawk/movie/EditSubtitlesForm.cs
@@ -226,5 +226,15 @@ namespace BizHawk.Client.EmuHawk
e.Row.Cells["Length"].Value = 0;
e.Row.Cells["DispColor"].Value = "FFFFFFFF";
}
+
+ private void ConcatMultilines_CheckedChanged(object sender, EventArgs e)
+ {
+ _selectedMovie.Subtitles.ConcatMultilines = ConcatMultilines.Checked;
+ }
+
+ private void AddColorTag_CheckedChanged(object sender, EventArgs e)
+ {
+ _selectedMovie.Subtitles.AddColorTag = AddColorTag.Checked;
+ }
}
}