Tastudio - lots of progress on branches

This commit is contained in:
adelikat 2015-07-18 22:20:38 -04:00
parent bf3587bd5b
commit 1af28239dc
9 changed files with 184 additions and 1 deletions

View File

@ -29,6 +29,7 @@ namespace BizHawk.Client.Common
Markers,
ClientSettings,
VerificationLog,
Branches,
UserData
}
@ -67,6 +68,7 @@ namespace BizHawk.Client.Common
AddLumpName(BinaryStateLump.ClientSettings, "ClientSettings.json");
AddLumpName(BinaryStateLump.VerificationLog, "VerificationLog.txt");
AddLumpName(BinaryStateLump.UserData, "UserData.txt");
AddLumpName(BinaryStateLump.Branches, "Branches");
}
public static string GetReadName(BinaryStateLump lump)

View File

@ -156,6 +156,7 @@
<Compile Include="movie\bk2\Bk2Movie.HeaderApi.cs">
<DependentUpon>Bk2Movie.cs</DependentUpon>
</Compile>
<Compile Include="movie\tasproj\TasBranch.cs" />
<Compile Include="movie\tasproj\TasMovie.History.cs" />
<Compile Include="movie\bk2\Bk2Movie.InputLog.cs">
<DependentUpon>Bk2Movie.cs</DependentUpon>

View File

@ -0,0 +1,29 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
namespace BizHawk.Client.Common
{
public class TasBranch
{
public int Frame { get; set; }
public byte[] CoreData { get; set; }
public List<string> InputLog { get; set; }
public byte[] OSDFrameBuffer { get; set; }
}
public class TasBranchCollection : List<TasBranch>
{
private List<TasBranch> Branches = new List<TasBranch>();
public void Save(BinaryWriter bw)
{
}
public void Load(BinaryReader br, long length)
{
}
}
}

View File

@ -90,6 +90,12 @@ namespace BizHawk.Client.Common
{
bs.PutLump(BinaryStateLump.VerificationLog, tw => tw.WriteLine(InputLogToString(VerificationLog)));
}
if (Branches.Any())
{
bs.PutLump(BinaryStateLump.Branches, (BinaryWriter bw) => Branches.Save(bw));
}
ReportProgress(PROGRESS_STEP);
}
@ -263,6 +269,14 @@ namespace BizHawk.Client.Common
}
});
}
if (bl.HasLump(BinaryStateLump.Branches))
{
bl.GetLump(BinaryStateLump.Branches, true, delegate(BinaryReader br, long length)
{
Branches.Load(br, length);
});
}
}
Changes = false;

View File

@ -22,6 +22,8 @@ namespace BizHawk.Client.Common
private readonly Dictionary<int, IController> InputStateCache = new Dictionary<int, IController>();
private readonly List<string> VerificationLog = new List<string>(); // For movies that do not begin with power-on, this is the input required to get into the initial state
private readonly TasBranchCollection Branches = new TasBranchCollection();
private BackgroundWorker _progressReportWorker = null;
public void NewBGWorker(BackgroundWorker newWorker)
{
@ -75,7 +77,8 @@ namespace BizHawk.Client.Common
}
public TasLagLog TasLagLog { get { return LagLog; } }
public TasBranchCollection TasBranches { get { return Branches; } }
public List<string> InputLog { get { return _log; } }
public TasMovieMarkerList Markers { get; set; }
public bool BindMarkersToInput { get; set; }
public bool UseInputCache { get; set; }

View File

@ -815,6 +815,18 @@ namespace BizHawk.Client.EmuHawk
}
}
public byte[] CurrentFrameBuffer(bool captureOSD)
{
using (var bb = captureOSD ? CaptureOSD() : MakeScreenshotImage())
{
using (var img = bb.ToSysdrawingBitmap())
{
ImageConverter converter = new ImageConverter();
return (byte[])converter.ConvertTo(img, typeof(byte[]));
}
}
}
public void TakeScreenshotToClipboard()
{
using (var bb = Global.Config.Screenshot_CaptureOSD ? CaptureOSD() : MakeScreenshotImage())

View File

@ -28,12 +28,17 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.BookmarksBranchesGroupBox = new System.Windows.Forms.GroupBox();
this.BranchesContextMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
this.AddContextMenu = new System.Windows.Forms.ToolStripMenuItem();
this.RemoveBranchContextMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.BranchView = new BizHawk.Client.EmuHawk.VirtualListView();
this.BranchNumberColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.FrameColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.TimeColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.BookmarksBranchesGroupBox.SuspendLayout();
this.BranchesContextMenu.SuspendLayout();
this.SuspendLayout();
//
// BookmarksBranchesGroupBox
@ -49,6 +54,29 @@
this.BookmarksBranchesGroupBox.TabStop = false;
this.BookmarksBranchesGroupBox.Text = "Bookmarks / Branches";
//
// BranchesContextMenu
//
this.BranchesContextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.AddContextMenu,
this.RemoveBranchContextMenuItem});
this.BranchesContextMenu.Name = "BranchesContextMenu";
this.BranchesContextMenu.Size = new System.Drawing.Size(153, 70);
this.BranchesContextMenu.Opening += new System.ComponentModel.CancelEventHandler(this.BranchesContextMenu_Opening);
//
// AddContextMenu
//
this.AddContextMenu.Name = "AddContextMenu";
this.AddContextMenu.Size = new System.Drawing.Size(152, 22);
this.AddContextMenu.Text = "Add";
this.AddContextMenu.Click += new System.EventHandler(this.AddContextMenu_Click);
//
// RemoveBranchContextMenuItem
//
this.RemoveBranchContextMenuItem.Name = "RemoveBranchContextMenuItem";
this.RemoveBranchContextMenuItem.Size = new System.Drawing.Size(152, 22);
this.RemoveBranchContextMenuItem.Text = "Remove";
this.RemoveBranchContextMenuItem.Click += new System.EventHandler(this.RemoveBranchContextMenuItem_Click);
//
// BranchView
//
this.BranchView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
@ -59,9 +87,12 @@
this.BranchNumberColumn,
this.FrameColumn,
this.TimeColumn});
this.BranchView.ContextMenuStrip = this.BranchesContextMenu;
this.BranchView.FullRowSelect = true;
this.BranchView.GridLines = true;
this.BranchView.ItemCount = 0;
this.BranchView.Location = new System.Drawing.Point(6, 19);
this.BranchView.MultiSelect = false;
this.BranchView.Name = "BranchView";
this.BranchView.SelectAllInProgress = false;
this.BranchView.selectedItem = -1;
@ -70,6 +101,7 @@
this.BranchView.UseCompatibleStateImageBehavior = false;
this.BranchView.UseCustomBackground = true;
this.BranchView.View = System.Windows.Forms.View.Details;
this.BranchView.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.BranchView_MouseDoubleClick);
//
// BranchNumberColumn
//
@ -93,6 +125,7 @@
this.Name = "BookmarksBranchesBox";
this.Size = new System.Drawing.Size(204, 253);
this.BookmarksBranchesGroupBox.ResumeLayout(false);
this.BranchesContextMenu.ResumeLayout(false);
this.ResumeLayout(false);
}
@ -104,5 +137,8 @@
private System.Windows.Forms.ColumnHeader BranchNumberColumn;
private System.Windows.Forms.ColumnHeader FrameColumn;
private System.Windows.Forms.ColumnHeader TimeColumn;
private System.Windows.Forms.ContextMenuStrip BranchesContextMenu;
private System.Windows.Forms.ToolStripMenuItem AddContextMenu;
private System.Windows.Forms.ToolStripMenuItem RemoveBranchContextMenuItem;
}
}

View File

@ -7,12 +7,20 @@ using System.Linq;
using System.Text;
using System.Windows.Forms;
using BizHawk.Emulation.Common;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
public partial class BookmarksBranchesBox : UserControl
{
public TAStudio Tastudio { get; set; }
public TasBranchCollection Branches
{
get { return Tastudio.CurrentTasMovie.TasBranches; }
}
public BookmarksBranchesBox()
{
InitializeComponent();
@ -20,14 +28,89 @@ namespace BizHawk.Client.EmuHawk
BranchView.QueryItemBkColor += QueryItemBkColor;
}
public TasBranch SelectedBranch
{
get
{
if (BranchView.SelectedIndices.Count > 0)
{
return Branches[BranchView.SelectedIndices[0]];
}
return null;
}
}
private void QueryItemText(int index, int column, out string text)
{
text = string.Empty;
var columnName = BranchView.Columns[column].Name;
if (index >= Tastudio.CurrentTasMovie.TasBranches.Count)
{
return;
}
switch (column)
{
case 0: // BranchNumberColumn
text = index.ToString();
break;
case 1: // FrameColumn
text = Branches[index].Frame.ToString();
break;
case 2: // TimeColumn
text = "TODO";
break;
}
}
private void QueryItemBkColor(int index, int column, ref Color color)
{
}
private void AddContextMenu_Click(object sender, EventArgs e)
{
// TODO: don't use Global.Emulator
var branch = new TasBranch
{
Frame = Global.Emulator.Frame,
CoreData = (Global.Emulator as IStatable).SaveStateBinary(),
InputLog = Tastudio.CurrentTasMovie.InputLog.ToList(),
OSDFrameBuffer = GlobalWin.MainForm.CurrentFrameBuffer(captureOSD: true)
};
Branches.Add(branch);
BranchView.ItemCount = Branches.Count;
}
private void BranchView_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (SelectedBranch != null)
{
LoadBranch(SelectedBranch);
}
}
private void BranchesContextMenu_Opening(object sender, CancelEventArgs e)
{
RemoveBranchContextMenuItem.Enabled = SelectedBranch != null;
}
private void RemoveBranchContextMenuItem_Click(object sender, EventArgs e)
{
if (SelectedBranch != null)
{
Branches.Remove(SelectedBranch);
BranchView.ItemCount = Branches.Count;
}
}
private void LoadBranch(TasBranch branch)
{
MessageBox.Show("TODO: load this branch");
}
}
}

View File

@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="BranchesContextMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>