2013-12-05 20:06:06 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
2015-07-25 16:01:26 +00:00
|
|
|
|
using System.Windows.Media;
|
2015-07-19 02:20:38 +00:00
|
|
|
|
using BizHawk.Emulation.Common;
|
|
|
|
|
using BizHawk.Client.Common;
|
2015-07-19 14:37:53 +00:00
|
|
|
|
using BizHawk.Common;
|
2015-07-19 02:20:38 +00:00
|
|
|
|
|
2013-12-05 20:06:06 +00:00
|
|
|
|
namespace BizHawk.Client.EmuHawk
|
|
|
|
|
{
|
|
|
|
|
public partial class BookmarksBranchesBox : UserControl
|
|
|
|
|
{
|
2015-07-22 21:26:25 +00:00
|
|
|
|
private const string BranchNumberColumnName = "BranchNumberColumn";
|
|
|
|
|
private const string FrameColumnName = "FrameColumn";
|
|
|
|
|
private const string TimeColumnName = "TimeColumn";
|
|
|
|
|
|
2015-07-19 14:50:14 +00:00
|
|
|
|
private readonly PlatformFrameRates FrameRates = new PlatformFrameRates();
|
2015-07-18 20:13:38 +00:00
|
|
|
|
public TAStudio Tastudio { get; set; }
|
2015-08-13 13:30:43 +00:00
|
|
|
|
private TasMovie Movie { get { return Tastudio.CurrentTasMovie; } }
|
2015-07-18 20:13:38 +00:00
|
|
|
|
|
2015-08-13 13:30:43 +00:00
|
|
|
|
private TasBranch GetBranch(int id)
|
2015-07-19 02:20:38 +00:00
|
|
|
|
{
|
2015-08-13 13:30:43 +00:00
|
|
|
|
return Tastudio.CurrentTasMovie.GetBranch(id);
|
2015-07-19 02:20:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 20:06:06 +00:00
|
|
|
|
public BookmarksBranchesBox()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2015-07-22 21:26:25 +00:00
|
|
|
|
|
|
|
|
|
BranchView.AllColumns.AddRange(new InputRoll.RollColumn[]
|
|
|
|
|
{
|
|
|
|
|
new InputRoll.RollColumn
|
|
|
|
|
{
|
|
|
|
|
Name = BranchNumberColumnName,
|
|
|
|
|
Text = "#",
|
|
|
|
|
Width = 30
|
|
|
|
|
},
|
|
|
|
|
new InputRoll.RollColumn
|
|
|
|
|
{
|
|
|
|
|
Name = FrameColumnName,
|
|
|
|
|
Text = "Frame",
|
2015-07-25 20:28:51 +00:00
|
|
|
|
Width = 64
|
2015-07-22 21:26:25 +00:00
|
|
|
|
},
|
|
|
|
|
new InputRoll.RollColumn
|
|
|
|
|
{
|
|
|
|
|
Name = TimeColumnName,
|
2015-08-05 01:41:31 +00:00
|
|
|
|
Text = "TimeStamp",
|
2015-07-25 20:28:51 +00:00
|
|
|
|
Width = 90
|
2015-07-22 21:26:25 +00:00
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2015-07-18 20:10:56 +00:00
|
|
|
|
BranchView.QueryItemText += QueryItemText;
|
|
|
|
|
BranchView.QueryItemBkColor += QueryItemBkColor;
|
2013-12-05 20:06:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-19 02:20:38 +00:00
|
|
|
|
public TasBranch SelectedBranch
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2015-07-26 03:42:50 +00:00
|
|
|
|
if (BranchView.AnyRowsSelected)
|
2015-07-19 02:20:38 +00:00
|
|
|
|
{
|
2015-08-13 13:30:43 +00:00
|
|
|
|
return GetBranch(BranchView.SelectedRows.First());
|
2015-07-19 02:20:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 19:14:33 +00:00
|
|
|
|
private int CurrentBranch = -1;
|
|
|
|
|
|
2015-08-24 22:30:45 +00:00
|
|
|
|
private void QueryItemText(int index, InputRoll.RollColumn column, out string text, ref int offsetX, ref int offsetY)
|
2013-12-05 20:06:06 +00:00
|
|
|
|
{
|
2015-07-18 20:10:56 +00:00
|
|
|
|
text = string.Empty;
|
2015-07-19 02:20:38 +00:00
|
|
|
|
|
2015-08-13 13:30:43 +00:00
|
|
|
|
if (index >= Movie.BranchCount)
|
2015-07-19 02:20:38 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 21:26:25 +00:00
|
|
|
|
switch (column.Name)
|
2015-07-19 02:20:38 +00:00
|
|
|
|
{
|
2015-07-22 21:26:25 +00:00
|
|
|
|
case BranchNumberColumnName:
|
2015-07-19 02:20:38 +00:00
|
|
|
|
text = index.ToString();
|
|
|
|
|
break;
|
2015-07-22 21:26:25 +00:00
|
|
|
|
case FrameColumnName:
|
2015-08-13 13:30:43 +00:00
|
|
|
|
text = GetBranch(index).Frame.ToString();
|
2015-07-19 02:20:38 +00:00
|
|
|
|
break;
|
2015-07-22 21:26:25 +00:00
|
|
|
|
case TimeColumnName:
|
2015-08-13 13:30:43 +00:00
|
|
|
|
text = GetBranch(index).TimeStamp.ToString(@"hh\:mm\:ss\.ff");
|
2015-07-19 02:20:38 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2015-07-18 20:10:56 +00:00
|
|
|
|
}
|
2013-12-05 20:06:06 +00:00
|
|
|
|
|
2015-07-22 21:26:25 +00:00
|
|
|
|
private void QueryItemBkColor(int index, InputRoll.RollColumn column, ref Color color)
|
2015-07-18 20:10:56 +00:00
|
|
|
|
{
|
2015-07-22 19:14:33 +00:00
|
|
|
|
if (index == CurrentBranch)
|
2015-07-29 18:38:10 +00:00
|
|
|
|
color = TAStudio.CurrentFrame_InputLog; // SystemColors.HotTrack;
|
2015-07-25 16:01:26 +00:00
|
|
|
|
|
|
|
|
|
// Highlight the branch cell a little, if hovering over it
|
|
|
|
|
if (BranchView.CurrentCellIsDataCell &&
|
|
|
|
|
BranchView.CurrentCell.Column.Name == BranchNumberColumnName &&
|
|
|
|
|
column.Name == BranchNumberColumnName &&
|
|
|
|
|
index == BranchView.CurrentCell.RowIndex)
|
|
|
|
|
{
|
|
|
|
|
color = Color.FromArgb((byte)(color.A - 24), (byte)(color.R - 24), (byte)(color.G - 24), (byte)(color.B - 24));
|
|
|
|
|
}
|
2013-12-05 20:06:06 +00:00
|
|
|
|
}
|
2015-07-19 02:20:38 +00:00
|
|
|
|
|
|
|
|
|
private void AddContextMenu_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2015-07-25 19:42:28 +00:00
|
|
|
|
Branch();
|
2015-07-19 02:20:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BranchView_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
2015-07-22 19:14:33 +00:00
|
|
|
|
LoadSelectedBranch();
|
2015-07-19 02:20:38 +00:00
|
|
|
|
}
|
2015-07-22 21:26:25 +00:00
|
|
|
|
|
2015-07-19 14:37:53 +00:00
|
|
|
|
private void LoadBranchContextMenuItem_Click(object sender, EventArgs e)
|
2015-07-22 19:14:33 +00:00
|
|
|
|
{
|
|
|
|
|
LoadSelectedBranch();
|
|
|
|
|
}
|
2015-07-22 21:26:25 +00:00
|
|
|
|
|
2015-07-22 19:14:33 +00:00
|
|
|
|
private void LoadSelectedBranch()
|
2015-07-19 14:37:53 +00:00
|
|
|
|
{
|
2015-09-14 17:45:27 +00:00
|
|
|
|
int index = BranchView.SelectedRows.First();
|
|
|
|
|
if (CurrentBranch == index)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-07-19 14:37:53 +00:00
|
|
|
|
if (SelectedBranch != null)
|
|
|
|
|
{
|
2015-09-14 17:45:27 +00:00
|
|
|
|
CurrentBranch = index;
|
2015-07-22 19:14:33 +00:00
|
|
|
|
BranchView.Refresh();
|
2015-07-19 14:37:53 +00:00
|
|
|
|
LoadBranch(SelectedBranch);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-19 02:20:38 +00:00
|
|
|
|
private void BranchesContextMenu_Opening(object sender, CancelEventArgs e)
|
|
|
|
|
{
|
2015-07-26 01:56:24 +00:00
|
|
|
|
UpdateBranchContextMenuItem.Enabled =
|
2015-07-22 19:14:33 +00:00
|
|
|
|
RemoveBranchContextMenuItem.Enabled =
|
2015-07-19 14:37:53 +00:00
|
|
|
|
LoadBranchContextMenuItem.Enabled =
|
|
|
|
|
SelectedBranch != null;
|
2015-07-19 02:20:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RemoveBranchContextMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (SelectedBranch != null)
|
|
|
|
|
{
|
2015-08-13 13:30:43 +00:00
|
|
|
|
int index = BranchView.SelectedRows.First();
|
2015-07-26 00:55:23 +00:00
|
|
|
|
if (index == CurrentBranch)
|
2015-07-25 16:07:22 +00:00
|
|
|
|
{
|
|
|
|
|
CurrentBranch = -1;
|
|
|
|
|
}
|
2015-09-13 20:36:10 +00:00
|
|
|
|
else if (index < CurrentBranch)
|
|
|
|
|
{
|
|
|
|
|
CurrentBranch--;
|
|
|
|
|
}
|
2015-07-25 16:07:22 +00:00
|
|
|
|
|
2015-08-13 13:30:43 +00:00
|
|
|
|
Movie.RemoveBranch(SelectedBranch);
|
|
|
|
|
BranchView.RowCount = Movie.BranchCount;
|
2015-07-26 00:55:23 +00:00
|
|
|
|
|
|
|
|
|
if (index == BranchView.SelectedRows.FirstOrDefault())
|
|
|
|
|
{
|
|
|
|
|
BranchView.ClearSelectedRows();
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 21:26:25 +00:00
|
|
|
|
BranchView.Refresh();
|
2015-09-14 17:45:27 +00:00
|
|
|
|
Tastudio.RefreshDialog();
|
2015-07-19 02:20:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadBranch(TasBranch branch)
|
|
|
|
|
{
|
2015-07-19 14:37:53 +00:00
|
|
|
|
Tastudio.CurrentTasMovie.LoadBranch(branch);
|
|
|
|
|
GlobalWin.DisplayManager.NeedsToPaint = true;
|
|
|
|
|
var stateInfo = new KeyValuePair<int, byte[]>(branch.Frame, branch.CoreData);
|
|
|
|
|
Tastudio.LoadState(stateInfo);
|
2015-07-22 00:31:51 +00:00
|
|
|
|
QuickBmpFile.Copy(new BitmapBufferVideoProvider(branch.OSDFrameBuffer), Global.Emulator.VideoProvider());
|
2015-07-19 14:37:53 +00:00
|
|
|
|
GlobalWin.MainForm.PauseEmulator();
|
|
|
|
|
GlobalWin.MainForm.PauseOnFrame = null;
|
|
|
|
|
Tastudio.RefreshDialog();
|
2015-07-19 02:20:38 +00:00
|
|
|
|
}
|
2015-07-19 14:50:14 +00:00
|
|
|
|
|
2015-07-20 00:49:23 +00:00
|
|
|
|
public void UpdateValues()
|
|
|
|
|
{
|
2015-08-13 13:30:43 +00:00
|
|
|
|
BranchView.RowCount = Movie.BranchCount;
|
2015-09-06 18:56:12 +00:00
|
|
|
|
BranchView.Refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Restart()
|
|
|
|
|
{
|
|
|
|
|
BranchView.DeselectAll();
|
|
|
|
|
BranchView.RowCount = Movie.BranchCount;
|
|
|
|
|
BranchView.Refresh();
|
2015-07-20 00:49:23 +00:00
|
|
|
|
}
|
2015-07-20 01:57:41 +00:00
|
|
|
|
|
|
|
|
|
public void Branch()
|
2015-07-26 01:56:24 +00:00
|
|
|
|
{
|
2015-07-30 20:14:14 +00:00
|
|
|
|
TasBranch branch = CreateBranch();
|
2015-08-13 13:30:43 +00:00
|
|
|
|
Movie.AddBranch(branch);
|
|
|
|
|
BranchView.RowCount = Movie.BranchCount;
|
|
|
|
|
CurrentBranch = Movie.BranchCount - 1;
|
2015-07-26 01:56:24 +00:00
|
|
|
|
BranchView.Refresh();
|
2015-07-29 23:45:51 +00:00
|
|
|
|
Tastudio.RefreshDialog();
|
2015-07-26 01:56:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TasBranch CreateBranch()
|
2015-07-20 01:57:41 +00:00
|
|
|
|
{
|
2015-07-25 19:42:28 +00:00
|
|
|
|
// TODO: don't use Global.Emulator
|
2015-07-26 01:56:24 +00:00
|
|
|
|
return new TasBranch
|
2015-07-25 19:42:28 +00:00
|
|
|
|
{
|
|
|
|
|
Frame = Global.Emulator.Frame,
|
|
|
|
|
CoreData = (byte[])((Global.Emulator as IStatable).SaveStateBinary().Clone()),
|
2015-08-13 18:03:22 +00:00
|
|
|
|
InputLog = Movie.InputLog.ToList(),
|
2015-07-25 19:42:28 +00:00
|
|
|
|
OSDFrameBuffer = GlobalWin.MainForm.CaptureOSD(),
|
2015-08-13 18:03:22 +00:00
|
|
|
|
LagLog = Movie.TasLagLog.Clone(),
|
|
|
|
|
ChangeLog = new TasMovieChangeLog(Movie),
|
|
|
|
|
TimeStamp = DateTime.Now,
|
|
|
|
|
Markers = Movie.Markers.DeepClone()
|
2015-07-25 19:42:28 +00:00
|
|
|
|
};
|
2015-07-20 01:57:41 +00:00
|
|
|
|
}
|
2015-07-25 12:40:17 +00:00
|
|
|
|
|
|
|
|
|
private void BranchView_CellHovered(object sender, InputRoll.CellEventArgs e)
|
|
|
|
|
{
|
2015-08-13 13:30:43 +00:00
|
|
|
|
if (e.NewCell != null && e.NewCell.RowIndex.HasValue && e.NewCell.Column != null && e.NewCell.RowIndex < Movie.BranchCount)
|
2015-07-25 12:40:17 +00:00
|
|
|
|
{
|
|
|
|
|
if (e.NewCell.Column.Name == BranchNumberColumnName)
|
|
|
|
|
{
|
2015-08-13 13:30:43 +00:00
|
|
|
|
ScreenShotPopUp(GetBranch(e.NewCell.RowIndex.Value), e.NewCell.RowIndex.Value);
|
2015-07-25 12:40:17 +00:00
|
|
|
|
}
|
2015-07-25 16:01:26 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CloseScreenShotPopUp();
|
|
|
|
|
}
|
2015-07-25 12:40:17 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CloseScreenShotPopUp();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BranchView_MouseMove(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (BranchView.CurrentCell == null || !BranchView.CurrentCell.RowIndex.HasValue || BranchView.CurrentCell.Column == null)
|
|
|
|
|
{
|
|
|
|
|
CloseScreenShotPopUp();
|
|
|
|
|
}
|
2015-07-25 16:01:26 +00:00
|
|
|
|
else if (BranchView.CurrentCell.Column.Name == BranchNumberColumnName)
|
|
|
|
|
{
|
|
|
|
|
BranchView.Refresh();
|
|
|
|
|
}
|
2015-07-25 12:40:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CloseScreenShotPopUp()
|
|
|
|
|
{
|
|
|
|
|
Tastudio.ScreenshotControl.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-25 16:01:26 +00:00
|
|
|
|
private void BranchView_MouseLeave(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Tastudio.ScreenshotControl.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-25 12:40:17 +00:00
|
|
|
|
private void ScreenShotPopUp(TasBranch branch, int index)
|
|
|
|
|
{
|
2015-07-26 01:31:06 +00:00
|
|
|
|
Point locationOnForm = this.FindForm().PointToClient(
|
|
|
|
|
this.Parent.PointToScreen(this.Location));
|
|
|
|
|
|
|
|
|
|
int x = locationOnForm.X - Tastudio.ScreenshotControl.Width;
|
|
|
|
|
int y = locationOnForm.Y + (BranchView.RowHeight * index);
|
2015-07-25 15:08:23 +00:00
|
|
|
|
|
|
|
|
|
Tastudio.ScreenshotControl.Location = new Point(x, y);
|
|
|
|
|
|
2015-07-25 12:40:17 +00:00
|
|
|
|
Tastudio.ScreenshotControl.Visible = true;
|
|
|
|
|
Tastudio.ScreenshotControl.Branch = branch;
|
2015-07-25 15:08:23 +00:00
|
|
|
|
Tastudio.ScreenshotControl.Refresh();
|
2015-07-25 12:40:17 +00:00
|
|
|
|
}
|
2015-07-26 01:56:24 +00:00
|
|
|
|
|
|
|
|
|
private void UpdateBranchContextMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (SelectedBranch != null)
|
|
|
|
|
{
|
|
|
|
|
UpdateBranch(SelectedBranch);
|
2015-08-13 13:30:43 +00:00
|
|
|
|
CurrentBranch = BranchView.SelectedRows.First();
|
2015-07-26 01:56:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateBranch(TasBranch branch)
|
|
|
|
|
{
|
2015-08-13 13:30:43 +00:00
|
|
|
|
Movie.UpdateBranch(branch, CreateBranch());
|
2015-07-26 01:56:24 +00:00
|
|
|
|
BranchView.Refresh();
|
2015-09-14 17:45:27 +00:00
|
|
|
|
Tastudio.RefreshDialog();
|
2015-07-26 01:56:24 +00:00
|
|
|
|
}
|
2015-07-30 02:15:00 +00:00
|
|
|
|
|
|
|
|
|
private void BranchView_MouseDown(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Button == MouseButtons.Left)
|
|
|
|
|
{
|
|
|
|
|
if (BranchView.CurrentCell != null && BranchView.CurrentCell.IsDataCell
|
|
|
|
|
&& BranchView.CurrentCell.Column.Name == BranchNumberColumnName)
|
|
|
|
|
{
|
|
|
|
|
BranchView.DragCurrentCell();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BranchView_MouseUp(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Button == MouseButtons.Left)
|
|
|
|
|
{
|
|
|
|
|
BranchView.ReleaseCurrentCell();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BranchView_CellDropped(object sender, InputRoll.CellEventArgs e)
|
|
|
|
|
{
|
2015-08-13 13:30:43 +00:00
|
|
|
|
if (e.NewCell != null && e.NewCell.IsDataCell && e.OldCell.RowIndex.Value < Movie.BranchCount)
|
2015-07-30 02:15:00 +00:00
|
|
|
|
{
|
2015-08-13 13:30:43 +00:00
|
|
|
|
Movie.SwapBranches(e.OldCell.RowIndex.Value, e.NewCell.RowIndex.Value);
|
2015-07-30 02:15:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-05 20:06:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|