tastudio: add branch undo feature
the fact that it's separated from changelog is because there's no way to extend the latter, but *also* it's intended, as we want branches to be independent from changelog manipulations todo: figure out branch text edits
This commit is contained in:
parent
c6d1aad25f
commit
d254ad01d8
|
@ -14,26 +14,35 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
public sealed partial class TasMovie : Bk2Movie, INotifyPropertyChanged
|
||||
{
|
||||
public new const string Extension = "tasproj";
|
||||
public const string DefaultProjectName = "default";
|
||||
|
||||
private readonly Bk2MnemonicConstants Mnemonics = new Bk2MnemonicConstants();
|
||||
private readonly TasStateManager StateManager;
|
||||
public readonly TasSession Session;
|
||||
private readonly TasLagLog LagLog = new TasLagLog();
|
||||
private readonly Dictionary<int, IController> InputStateCache = new Dictionary<int, IController>();
|
||||
public BackgroundWorker _progressReportWorker = null;
|
||||
public bool LastPositionStable = true;
|
||||
public string NewBranchText = "";
|
||||
public readonly IStringLog VerificationLog = StringLogUtil.MakeStringLog(); // For movies that do not begin with power-on, this is the input required to get into the initial state
|
||||
public readonly TasBranchCollection Branches = new TasBranchCollection();
|
||||
|
||||
public BackgroundWorker _progressReportWorker = null;
|
||||
public void NewBGWorker(BackgroundWorker newWorker)
|
||||
{
|
||||
_progressReportWorker = newWorker;
|
||||
}
|
||||
|
||||
public int LastValidFrame
|
||||
{
|
||||
get { return LagLog.LastValidFrame; }
|
||||
}
|
||||
public readonly TasSession Session;
|
||||
private readonly Bk2MnemonicConstants Mnemonics = new Bk2MnemonicConstants();
|
||||
private readonly TasStateManager StateManager;
|
||||
private readonly TasLagLog LagLog = new TasLagLog();
|
||||
private readonly Dictionary<int, IController> InputStateCache = new Dictionary<int, IController>();
|
||||
public TasLagLog TasLagLog { get { return LagLog; } }
|
||||
public IStringLog InputLog { get { return _log; } }
|
||||
public TasMovieMarkerList Markers { get; set; }
|
||||
public bool BindMarkersToInput { get; set; }
|
||||
public bool UseInputCache { get; set; }
|
||||
public int CurrentBranch { get; set; }
|
||||
public int BranchCount { get { return Branches.Count; } }
|
||||
public int LastValidFrame { get { return LagLog.LastValidFrame; } }
|
||||
public override string PreferredExtension { get { return Extension; } }
|
||||
public TasStateManager TasStateManager { get { return StateManager; } }
|
||||
public TasMovieRecord this[int index] { get { return new TasMovieRecord {
|
||||
// State = StateManager[index],
|
||||
HasState = StateManager.HasState(index),
|
||||
LogEntry = GetInputLogEntry(index),
|
||||
Lagged = LagLog[index + 1],
|
||||
WasLagged = LagLog.History(index + 1)
|
||||
}; } }
|
||||
|
||||
public TasMovie(string path, bool startsFromSavestate = false, BackgroundWorker progressReportWorker = null)
|
||||
: base(path)
|
||||
|
@ -46,14 +55,12 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
|
||||
ChangeLog = new TasMovieChangeLog(this);
|
||||
|
||||
StateManager = new TasStateManager(this);
|
||||
Session = new TasSession(this);
|
||||
Header[HeaderKeys.MOVIEVERSION] = "BizHawk v2.0 Tasproj v1.0";
|
||||
Markers = new TasMovieMarkerList(this);
|
||||
Markers.CollectionChanged += Markers_CollectionChanged;
|
||||
Markers.Add(0, startsFromSavestate ? "Savestate" : "Power on");
|
||||
|
||||
BindMarkersToInput = true;
|
||||
CurrentBranch = -1;
|
||||
}
|
||||
|
@ -68,86 +75,19 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
|
||||
ChangeLog = new TasMovieChangeLog(this);
|
||||
|
||||
StateManager = new TasStateManager(this);
|
||||
Session = new TasSession(this);
|
||||
Header[HeaderKeys.MOVIEVERSION] = "BizHawk v2.0 Tasproj v1.0";
|
||||
Markers = new TasMovieMarkerList(this);
|
||||
Markers.CollectionChanged += Markers_CollectionChanged;
|
||||
Markers.Add(0, startsFromSavestate ? "Savestate" : "Power on");
|
||||
|
||||
BindMarkersToInput = true;
|
||||
CurrentBranch = -1;
|
||||
}
|
||||
|
||||
public TasLagLog TasLagLog { get { return LagLog; } }
|
||||
public IStringLog InputLog { get { return _log; } }
|
||||
public TasMovieMarkerList Markers { get; set; }
|
||||
public bool BindMarkersToInput { get; set; }
|
||||
public bool UseInputCache { get; set; }
|
||||
public bool LastPositionStable = true;
|
||||
public string NewBranchText = "";
|
||||
public int CurrentBranch { get; set; }
|
||||
public int BranchCount { get { return Branches.Count; } }
|
||||
|
||||
public TasBranch GetBranch(int index)
|
||||
public void NewBGWorker(BackgroundWorker newWorker)
|
||||
{
|
||||
if (index >= Branches.Count || index < 0)
|
||||
return null;
|
||||
else
|
||||
return Branches[index];
|
||||
}
|
||||
|
||||
public int BranchHashByIndex(int index)
|
||||
{
|
||||
if (index >= Branches.Count)
|
||||
return -1;
|
||||
else
|
||||
return Branches[index].UniqueIdentifier.GetHashCode();
|
||||
}
|
||||
|
||||
public int BranchIndexByHash(int hash)
|
||||
{
|
||||
TasBranch branch = Branches.Where(b => b.UniqueIdentifier.GetHashCode() == hash).SingleOrDefault();
|
||||
if (branch == null)
|
||||
return -1;
|
||||
return Branches.IndexOf(branch);
|
||||
}
|
||||
|
||||
public int BranchIndexByFrame(int frame)
|
||||
{
|
||||
TasBranch branch = Branches.Where(b => b.Frame == frame)
|
||||
.OrderByDescending(b => b.TimeStamp).FirstOrDefault();
|
||||
if (branch == null)
|
||||
return -1;
|
||||
return Branches.IndexOf(branch);
|
||||
}
|
||||
|
||||
public override string PreferredExtension
|
||||
{
|
||||
get { return Extension; }
|
||||
}
|
||||
|
||||
public TasStateManager TasStateManager
|
||||
{
|
||||
get { return StateManager; }
|
||||
}
|
||||
|
||||
public new const string Extension = "tasproj";
|
||||
|
||||
public TasMovieRecord this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
return new TasMovieRecord
|
||||
{
|
||||
// State = StateManager[index],
|
||||
HasState = StateManager.HasState(index),
|
||||
LogEntry = GetInputLogEntry(index),
|
||||
Lagged = LagLog[index + 1],
|
||||
WasLagged = LagLog.History(index + 1)
|
||||
};
|
||||
}
|
||||
_progressReportWorker = newWorker;
|
||||
}
|
||||
|
||||
public void ReportProgress(double percent)
|
||||
|
@ -160,49 +100,24 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
|
||||
#region Events and Handlers
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private bool _changes;
|
||||
public override bool Changes
|
||||
// TODO: use LogGenerators rather than string comparisons
|
||||
private int? DivergentPoint(IStringLog currentLog, IStringLog newLog)
|
||||
{
|
||||
get { return _changes; }
|
||||
protected set
|
||||
int max = newLog.Count;
|
||||
if (currentLog.Count < newLog.Count)
|
||||
{
|
||||
if (_changes != value)
|
||||
max = currentLog.Count;
|
||||
}
|
||||
|
||||
for (int i = 0; i < max; i++)
|
||||
{
|
||||
if (newLog[i] != currentLog[i])
|
||||
{
|
||||
_changes = value;
|
||||
OnPropertyChanged("Changes");
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This event is Raised only when Changes is TOGGLED.
|
||||
private void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
if (PropertyChanged != null)
|
||||
{
|
||||
// Raising the event when FirstName or LastName property value changed
|
||||
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
|
||||
void Markers_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
Changes = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void ClearChanges()
|
||||
{
|
||||
Changes = false;
|
||||
}
|
||||
|
||||
public void FlagChanges()
|
||||
{
|
||||
Changes = true;
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void StartNewRecording()
|
||||
|
@ -520,53 +435,48 @@ namespace BizHawk.Client.Common
|
|||
return true;
|
||||
}
|
||||
|
||||
public void LoadBranch(TasBranch branch)
|
||||
#region Branches
|
||||
|
||||
public TasBranch GetBranch(int index)
|
||||
{
|
||||
int? divergentPoint = DivergentPoint(_log, branch.InputLog);
|
||||
|
||||
if (_log != null) _log.Dispose();
|
||||
_log = branch.InputLog.Clone();
|
||||
//_changes = true;
|
||||
|
||||
// if there are branch states, they will be loaded anyway
|
||||
// but if there's none, or only *after* divergent point, don't invalidate the entire movie anymore
|
||||
if (divergentPoint.HasValue)
|
||||
{
|
||||
StateManager.Invalidate(divergentPoint.Value);
|
||||
LagLog.FromLagLog(branch.LagLog); // don't truncate LagLog if the branch's one is shorter, but input is the same
|
||||
}
|
||||
if (index >= Branches.Count || index < 0)
|
||||
return null;
|
||||
else
|
||||
StateManager.Invalidate(branch.InputLog.Count);
|
||||
|
||||
StateManager.LoadBranch(Branches.IndexOf(branch));
|
||||
|
||||
StateManager.SetState(branch.Frame, branch.CoreData);
|
||||
|
||||
//ChangeLog = branch.ChangeLog;
|
||||
if (BindMarkersToInput) // pretty critical not to erase them
|
||||
Markers = branch.Markers;
|
||||
|
||||
Changes = true;
|
||||
return Branches[index];
|
||||
}
|
||||
|
||||
// TODO: use LogGenerators rather than string comparisons
|
||||
private int? DivergentPoint(IStringLog currentLog, IStringLog newLog)
|
||||
public TasBranch GetBranch(Guid id)
|
||||
{
|
||||
int max = newLog.Count;
|
||||
if (currentLog.Count < newLog.Count)
|
||||
{
|
||||
max = currentLog.Count;
|
||||
}
|
||||
TasBranch branch = Branches.Where(b => b.UniqueIdentifier == id).SingleOrDefault();
|
||||
if (branch != null)
|
||||
return branch;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
for (int i = 0; i < max; i++)
|
||||
{
|
||||
if (newLog[i] != currentLog[i])
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
public int BranchHashByIndex(int index)
|
||||
{
|
||||
if (index >= Branches.Count)
|
||||
return -1;
|
||||
else
|
||||
return Branches[index].UniqueIdentifier.GetHashCode();
|
||||
}
|
||||
|
||||
return null;
|
||||
public int BranchIndexByHash(int hash)
|
||||
{
|
||||
TasBranch branch = Branches.Where(b => b.UniqueIdentifier.GetHashCode() == hash).SingleOrDefault();
|
||||
if (branch == null)
|
||||
return -1;
|
||||
return Branches.IndexOf(branch);
|
||||
}
|
||||
|
||||
public int BranchIndexByFrame(int frame)
|
||||
{
|
||||
TasBranch branch = Branches.Where(b => b.Frame == frame)
|
||||
.OrderByDescending(b => b.TimeStamp).FirstOrDefault();
|
||||
if (branch == null)
|
||||
return -1;
|
||||
return Branches.IndexOf(branch);
|
||||
}
|
||||
|
||||
public void AddBranch(TasBranch branch)
|
||||
|
@ -583,6 +493,34 @@ namespace BizHawk.Client.Common
|
|||
Changes = true;
|
||||
}
|
||||
|
||||
public void LoadBranch(TasBranch branch)
|
||||
{
|
||||
int? divergentPoint = DivergentPoint(_log, branch.InputLog);
|
||||
|
||||
if (_log != null) _log.Dispose();
|
||||
_log = branch.InputLog.Clone();
|
||||
//_changes = true;
|
||||
|
||||
// if there are branch states, they will be loaded anyway
|
||||
// but if there's none, or only *after* divergent point, don't invalidate the entire movie anymore
|
||||
if (divergentPoint.HasValue)
|
||||
{
|
||||
StateManager.Invalidate(divergentPoint.Value);
|
||||
LagLog.FromLagLog(branch.LagLog); // don't truncate LagLog if the branch's one is shorter, but input is the same
|
||||
}
|
||||
else
|
||||
StateManager.Invalidate(branch.InputLog.Count);
|
||||
|
||||
StateManager.LoadBranch(Branches.IndexOf(branch));
|
||||
StateManager.SetState(branch.Frame, branch.CoreData);
|
||||
|
||||
//ChangeLog = branch.ChangeLog;
|
||||
if (BindMarkersToInput) // pretty critical not to erase them
|
||||
Markers = branch.Markers;
|
||||
|
||||
Changes = true;
|
||||
}
|
||||
|
||||
public void UpdateBranch(TasBranch old, TasBranch newBranch)
|
||||
{
|
||||
int index = Branches.IndexOf(old);
|
||||
|
@ -605,5 +543,52 @@ namespace BizHawk.Client.Common
|
|||
Branches.Insert(b2, branch);
|
||||
Changes = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events and Handlers
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private bool _changes;
|
||||
public override bool Changes
|
||||
{
|
||||
get { return _changes; }
|
||||
protected set
|
||||
{
|
||||
if (_changes != value)
|
||||
{
|
||||
_changes = value;
|
||||
OnPropertyChanged("Changes");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This event is Raised only when Changes is TOGGLED.
|
||||
private void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
if (PropertyChanged != null)
|
||||
{
|
||||
// Raising the event when FirstName or LastName property value changed
|
||||
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
|
||||
void Markers_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
Changes = true;
|
||||
}
|
||||
|
||||
public void ClearChanges()
|
||||
{
|
||||
Changes = false;
|
||||
}
|
||||
|
||||
public void FlagChanges()
|
||||
{
|
||||
Changes = true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -857,6 +857,9 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public void UpdateBranch(int index)
|
||||
{
|
||||
if (index == -1) // backup branch is outsider
|
||||
return;
|
||||
|
||||
int branchHash = _movie.BranchHashByIndex(index);
|
||||
|
||||
// RemoveBranch
|
||||
|
@ -899,6 +902,9 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public void LoadBranch(int index)
|
||||
{
|
||||
if (index == -1) // backup branch is outsider
|
||||
return;
|
||||
|
||||
int branchHash = _movie.BranchHashByIndex(index);
|
||||
|
||||
//Invalidate(0); // Not a good way of doing it?
|
||||
|
|
|
@ -30,8 +30,8 @@
|
|||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.BookmarksBranchesGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.UndoBranchButton = new System.Windows.Forms.Button();
|
||||
this.JumpToBranchButton = new System.Windows.Forms.Button();
|
||||
this.EditBranchTextButton = new System.Windows.Forms.Button();
|
||||
this.UpdateBranchButton = new System.Windows.Forms.Button();
|
||||
this.AddWithTextBranchButton = new System.Windows.Forms.Button();
|
||||
this.AddBranchButton = new System.Windows.Forms.Button();
|
||||
|
@ -43,10 +43,11 @@
|
|||
this.LoadBranchContextMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.UpdateBranchContextMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.EditBranchTextContextMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.JumpToBranchContextMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.UndoBranchToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
|
||||
this.RemoveBranchContextMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
|
||||
this.JumpToBranchContextMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.BookmarksBranchesGroupBox.SuspendLayout();
|
||||
this.BranchesContextMenu.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
|
@ -56,8 +57,8 @@
|
|||
this.BookmarksBranchesGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.BookmarksBranchesGroupBox.Controls.Add(this.UndoBranchButton);
|
||||
this.BookmarksBranchesGroupBox.Controls.Add(this.JumpToBranchButton);
|
||||
this.BookmarksBranchesGroupBox.Controls.Add(this.EditBranchTextButton);
|
||||
this.BookmarksBranchesGroupBox.Controls.Add(this.UpdateBranchButton);
|
||||
this.BookmarksBranchesGroupBox.Controls.Add(this.AddWithTextBranchButton);
|
||||
this.BookmarksBranchesGroupBox.Controls.Add(this.AddBranchButton);
|
||||
|
@ -70,12 +71,24 @@
|
|||
this.BookmarksBranchesGroupBox.TabStop = false;
|
||||
this.BookmarksBranchesGroupBox.Text = "Branches";
|
||||
//
|
||||
// UndoBranchButton
|
||||
//
|
||||
this.UndoBranchButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.UndoBranchButton.Enabled = false;
|
||||
this.UndoBranchButton.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.undo;
|
||||
this.UndoBranchButton.Location = new System.Drawing.Point(159, 249);
|
||||
this.UndoBranchButton.Name = "UndoBranchButton";
|
||||
this.UndoBranchButton.Size = new System.Drawing.Size(23, 23);
|
||||
this.UndoBranchButton.TabIndex = 10;
|
||||
this.UndoBranchButton.UseVisualStyleBackColor = true;
|
||||
this.UndoBranchButton.Click += new System.EventHandler(this.UndoBranchToolStripMenuItem_Click);
|
||||
//
|
||||
// JumpToBranchButton
|
||||
//
|
||||
this.JumpToBranchButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.JumpToBranchButton.Enabled = false;
|
||||
this.JumpToBranchButton.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.JumpTo;
|
||||
this.JumpToBranchButton.Location = new System.Drawing.Point(161, 249);
|
||||
this.JumpToBranchButton.Location = new System.Drawing.Point(130, 249);
|
||||
this.JumpToBranchButton.Name = "JumpToBranchButton";
|
||||
this.JumpToBranchButton.Size = new System.Drawing.Size(23, 23);
|
||||
this.JumpToBranchButton.TabIndex = 9;
|
||||
|
@ -83,19 +96,6 @@
|
|||
this.JumpToBranchButton.UseVisualStyleBackColor = true;
|
||||
this.JumpToBranchButton.Click += new System.EventHandler(this.JumpToBranchToolStripMenuItem_Click);
|
||||
//
|
||||
// EditBranchTextButton
|
||||
//
|
||||
this.EditBranchTextButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.EditBranchTextButton.Enabled = false;
|
||||
this.EditBranchTextButton.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.pencil;
|
||||
this.EditBranchTextButton.Location = new System.Drawing.Point(130, 249);
|
||||
this.EditBranchTextButton.Name = "EditBranchTextButton";
|
||||
this.EditBranchTextButton.Size = new System.Drawing.Size(25, 23);
|
||||
this.EditBranchTextButton.TabIndex = 5;
|
||||
this.toolTip1.SetToolTip(this.EditBranchTextButton, "Edit Branch Text");
|
||||
this.EditBranchTextButton.UseVisualStyleBackColor = true;
|
||||
this.EditBranchTextButton.Click += new System.EventHandler(this.EditBranchTextToolStripMenuItem_Click);
|
||||
//
|
||||
// UpdateBranchButton
|
||||
//
|
||||
this.UpdateBranchButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
|
@ -172,7 +172,7 @@
|
|||
this.BranchView.Size = new System.Drawing.Size(186, 224);
|
||||
this.BranchView.suspendHotkeys = false;
|
||||
this.BranchView.TabIndex = 0;
|
||||
this.BranchView.CellHovered += new BizHawk.Client.EmuHawk.InputRoll.HoverEventHandler(this.BranchView_CellHovered);
|
||||
this.BranchView.PointedCellChanged += new BizHawk.Client.EmuHawk.InputRoll.CellChangeEventHandler(this.BranchView_PointedCellChanged);
|
||||
this.BranchView.CellDropped += new BizHawk.Client.EmuHawk.InputRoll.CellDroppedEvent(this.BranchView_CellDropped);
|
||||
this.BranchView.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.BranchView_MouseDoubleClick);
|
||||
this.BranchView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.BranchView_MouseDown);
|
||||
|
@ -189,10 +189,11 @@
|
|||
this.UpdateBranchContextMenuItem,
|
||||
this.EditBranchTextContextMenuItem,
|
||||
this.JumpToBranchContextMenuItem,
|
||||
this.UndoBranchToolStripMenuItem,
|
||||
this.toolStripSeparator2,
|
||||
this.RemoveBranchContextMenuItem});
|
||||
this.BranchesContextMenu.Name = "BranchesContextMenu";
|
||||
this.BranchesContextMenu.Size = new System.Drawing.Size(153, 186);
|
||||
this.BranchesContextMenu.Size = new System.Drawing.Size(153, 208);
|
||||
this.BranchesContextMenu.Opening += new System.ComponentModel.CancelEventHandler(this.BranchesContextMenu_Opening);
|
||||
//
|
||||
// AddBranchContextMenu
|
||||
|
@ -235,6 +236,23 @@
|
|||
this.EditBranchTextContextMenuItem.Text = "Edit Text";
|
||||
this.EditBranchTextContextMenuItem.Click += new System.EventHandler(this.EditBranchTextToolStripMenuItem_Click);
|
||||
//
|
||||
// JumpToBranchContextMenuItem
|
||||
//
|
||||
this.JumpToBranchContextMenuItem.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.JumpTo;
|
||||
this.JumpToBranchContextMenuItem.Name = "JumpToBranchContextMenuItem";
|
||||
this.JumpToBranchContextMenuItem.Size = new System.Drawing.Size(152, 22);
|
||||
this.JumpToBranchContextMenuItem.Text = "Jump To";
|
||||
this.JumpToBranchContextMenuItem.Click += new System.EventHandler(this.JumpToBranchToolStripMenuItem_Click);
|
||||
//
|
||||
// UndoBranchToolStripMenuItem
|
||||
//
|
||||
this.UndoBranchToolStripMenuItem.Enabled = false;
|
||||
this.UndoBranchToolStripMenuItem.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.undo;
|
||||
this.UndoBranchToolStripMenuItem.Name = "UndoBranchToolStripMenuItem";
|
||||
this.UndoBranchToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
|
||||
this.UndoBranchToolStripMenuItem.Text = "Undo";
|
||||
this.UndoBranchToolStripMenuItem.Click += new System.EventHandler(this.UndoBranchToolStripMenuItem_Click);
|
||||
//
|
||||
// toolStripSeparator2
|
||||
//
|
||||
this.toolStripSeparator2.Name = "toolStripSeparator2";
|
||||
|
@ -248,14 +266,6 @@
|
|||
this.RemoveBranchContextMenuItem.Text = "Remove";
|
||||
this.RemoveBranchContextMenuItem.Click += new System.EventHandler(this.RemoveBranchToolStripMenuItem_Click);
|
||||
//
|
||||
// JumpToBranchContextMenuItem
|
||||
//
|
||||
this.JumpToBranchContextMenuItem.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.JumpTo;
|
||||
this.JumpToBranchContextMenuItem.Name = "JumpToBranchToolStripMenuItem";
|
||||
this.JumpToBranchContextMenuItem.Size = new System.Drawing.Size(152, 22);
|
||||
this.JumpToBranchContextMenuItem.Text = "Jump To";
|
||||
this.JumpToBranchContextMenuItem.Click += new System.EventHandler(this.JumpToBranchToolStripMenuItem_Click);
|
||||
//
|
||||
// BookmarksBranchesBox
|
||||
//
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
|
||||
|
@ -279,7 +289,6 @@
|
|||
private System.Windows.Forms.ToolStripMenuItem UpdateBranchContextMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem EditBranchTextContextMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem AddBranchWithTextContextMenuItem;
|
||||
private System.Windows.Forms.Button EditBranchTextButton;
|
||||
private System.Windows.Forms.Button UpdateBranchButton;
|
||||
private System.Windows.Forms.Button AddWithTextBranchButton;
|
||||
private System.Windows.Forms.Button AddBranchButton;
|
||||
|
@ -288,5 +297,7 @@
|
|||
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
|
||||
private System.Windows.Forms.Button JumpToBranchButton;
|
||||
private System.Windows.Forms.ToolStripMenuItem JumpToBranchContextMenuItem;
|
||||
private System.Windows.Forms.Button UndoBranchButton;
|
||||
private System.Windows.Forms.ToolStripMenuItem UndoBranchToolStripMenuItem;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,24 +16,21 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
public partial class BookmarksBranchesBox : UserControl
|
||||
{
|
||||
public TAStudio Tastudio { get; set; }
|
||||
private const string BranchNumberColumnName = "BranchNumberColumn";
|
||||
private const string FrameColumnName = "FrameColumn";
|
||||
private const string UserTextColumnName = "TextColumn";
|
||||
private readonly PlatformFrameRates FrameRates = new PlatformFrameRates();
|
||||
private ScreenshotForm Screenshot = new ScreenshotForm();
|
||||
private TasMovie Movie { get { return Tastudio.CurrentTasMovie; } }
|
||||
public TAStudio Tastudio { get; set; }
|
||||
|
||||
public TasBranch BackupBranch;
|
||||
private enum BranchUndo { Load, Update, Text, Remove, None }
|
||||
private BranchUndo _branchUndo = BranchUndo.None;
|
||||
public int HoverInterval {
|
||||
get { return BranchView.HoverInterval; }
|
||||
set { BranchView.HoverInterval = value; }
|
||||
}
|
||||
|
||||
private TasBranch GetBranch(int id)
|
||||
{
|
||||
return Tastudio.CurrentTasMovie.GetBranch(id);
|
||||
}
|
||||
|
||||
public BookmarksBranchesBox()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
@ -125,6 +122,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
#region Actions
|
||||
|
||||
private TasBranch GetBranch(int index)
|
||||
{
|
||||
return Tastudio.CurrentTasMovie.GetBranch(index);
|
||||
}
|
||||
|
||||
public void Branch()
|
||||
{
|
||||
TasBranch branch = CreateBranch();
|
||||
|
@ -221,6 +223,17 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void LoadBranchToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
BackupBranch = CreateBranch();
|
||||
|
||||
var currentHashes = Movie.Branches.Select(b => b.UniqueIdentifier.GetHashCode()).ToList();
|
||||
do BackupBranch.UniqueIdentifier = Guid.NewGuid();
|
||||
while (currentHashes.Contains(BackupBranch.UniqueIdentifier.GetHashCode()));
|
||||
|
||||
UndoBranchToolStripMenuItem.Enabled = UndoBranchButton.Enabled = true;
|
||||
UndoBranchToolStripMenuItem.Text = "Undo Branch Load";
|
||||
toolTip1.SetToolTip(UndoBranchButton, "Undo Branch Load");
|
||||
_branchUndo = BranchUndo.Load;
|
||||
|
||||
LoadSelectedBranch();
|
||||
}
|
||||
|
||||
|
@ -229,6 +242,13 @@ namespace BizHawk.Client.EmuHawk
|
|||
if (SelectedBranch != null)
|
||||
{
|
||||
Movie.CurrentBranch = BranchView.SelectedRows.First();
|
||||
|
||||
BackupBranch = SelectedBranch;
|
||||
UndoBranchToolStripMenuItem.Enabled = UndoBranchButton.Enabled = true;
|
||||
UndoBranchToolStripMenuItem.Text = "Undo Branch Update";
|
||||
toolTip1.SetToolTip(UndoBranchButton, "Undo Branch Update");
|
||||
_branchUndo = BranchUndo.Update;
|
||||
|
||||
UpdateBranch(SelectedBranch);
|
||||
GlobalWin.OSD.AddMessage("Saved branch " + Movie.CurrentBranch.ToString());
|
||||
}
|
||||
|
@ -239,6 +259,13 @@ namespace BizHawk.Client.EmuHawk
|
|||
if (SelectedBranch != null)
|
||||
{
|
||||
int index = BranchView.SelectedRows.First();
|
||||
|
||||
BackupBranch = SelectedBranch;
|
||||
UndoBranchToolStripMenuItem.Enabled = UndoBranchButton.Enabled = true;
|
||||
UndoBranchToolStripMenuItem.Text = "Undo Branch Text Edit";
|
||||
toolTip1.SetToolTip(UndoBranchButton, "Undo Branch Text Edit");
|
||||
_branchUndo = BranchUndo.Text;
|
||||
|
||||
EditBranchTextPopUp(index);
|
||||
GlobalWin.OSD.AddMessage("Edited branch " + index.ToString());
|
||||
}
|
||||
|
@ -268,6 +295,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
Movie.CurrentBranch--;
|
||||
}
|
||||
|
||||
BackupBranch = SelectedBranch;
|
||||
UndoBranchToolStripMenuItem.Enabled = UndoBranchButton.Enabled = true;
|
||||
UndoBranchToolStripMenuItem.Text = "Undo Branch Removal";
|
||||
toolTip1.SetToolTip(UndoBranchButton, "Undo Branch Removal");
|
||||
_branchUndo = BranchUndo.Remove;
|
||||
|
||||
Movie.RemoveBranch(SelectedBranch);
|
||||
BranchView.RowCount = Movie.BranchCount;
|
||||
|
||||
|
@ -283,6 +316,33 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
private void UndoBranchToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_branchUndo == BranchUndo.Load)
|
||||
{
|
||||
LoadBranch(BackupBranch);
|
||||
GlobalWin.OSD.AddMessage("Branch Load canceled");
|
||||
}
|
||||
else if (_branchUndo == BranchUndo.Update)
|
||||
{
|
||||
Movie.UpdateBranch(Movie.GetBranch(BackupBranch.UniqueIdentifier), BackupBranch);
|
||||
GlobalWin.OSD.AddMessage("Branch Update canceled");
|
||||
}
|
||||
else if (_branchUndo == BranchUndo.Text)
|
||||
{
|
||||
Movie.GetBranch(BackupBranch.UniqueIdentifier).UserText = BackupBranch.UserText;
|
||||
}
|
||||
else if (_branchUndo == BranchUndo.Remove)
|
||||
{
|
||||
Movie.AddBranch(BackupBranch);
|
||||
BranchView.RowCount = Movie.BranchCount;
|
||||
GlobalWin.OSD.AddMessage("Branch Removal canceled");
|
||||
}
|
||||
UndoBranchToolStripMenuItem.Enabled = UndoBranchButton.Enabled = false;
|
||||
BranchView.Refresh();
|
||||
Tastudio.RefreshDialog();
|
||||
}
|
||||
|
||||
public void AddBranchExternal()
|
||||
{
|
||||
AddBranchToolStripMenuItem_Click(null, null);
|
||||
|
@ -430,7 +490,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
UpdateBranchButton.Enabled =
|
||||
LoadBranchButton.Enabled =
|
||||
EditBranchTextButton.Enabled =
|
||||
JumpToBranchButton.Enabled =
|
||||
SelectedBranch != null;
|
||||
|
||||
|
@ -456,7 +515,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void BranchView_MouseDoubleClick(object sender, MouseEventArgs e)
|
||||
{
|
||||
LoadSelectedBranch();
|
||||
LoadBranchToolStripMenuItem_Click(null, null);
|
||||
}
|
||||
|
||||
private void BranchView_MouseMove(object sender, MouseEventArgs e)
|
||||
|
@ -476,7 +535,15 @@ namespace BizHawk.Client.EmuHawk
|
|||
Screenshot.FadeOut();
|
||||
}
|
||||
|
||||
private void BranchView_CellHovered(object sender, InputRoll.CellEventArgs e)
|
||||
private void BranchView_CellDropped(object sender, InputRoll.CellEventArgs e)
|
||||
{
|
||||
if (e.NewCell != null && e.NewCell.IsDataCell && e.OldCell.RowIndex.Value < Movie.BranchCount)
|
||||
{
|
||||
Movie.SwapBranches(e.OldCell.RowIndex.Value, e.NewCell.RowIndex.Value);
|
||||
}
|
||||
}
|
||||
|
||||
private void BranchView_PointedCellChanged(object sender, InputRoll.CellEventArgs e)
|
||||
{
|
||||
if (e.NewCell != null && e.NewCell.RowIndex.HasValue && e.NewCell.Column != null && e.NewCell.RowIndex < Movie.BranchCount)
|
||||
{
|
||||
|
@ -507,14 +574,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
}
|
||||
|
||||
private void BranchView_CellDropped(object sender, InputRoll.CellEventArgs e)
|
||||
{
|
||||
if (e.NewCell != null && e.NewCell.IsDataCell && e.OldCell.RowIndex.Value < Movie.BranchCount)
|
||||
{
|
||||
Movie.SwapBranches(e.OldCell.RowIndex.Value, e.NewCell.RowIndex.Value);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,7 +123,4 @@
|
|||
<metadata name="BranchesContextMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>23, 17</value>
|
||||
</metadata>
|
||||
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>185, 17</value>
|
||||
</metadata>
|
||||
</root>
|
Loading…
Reference in New Issue