diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs index f2bb6d35f27..8caad035ec8 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs @@ -401,6 +401,18 @@ public LuaTable GetBranches() indexFrom: 0); } + [LuaMethodExample("local branch = tastudio.getselectedbranch();")] + [LuaMethod("getselectedbranch", "gets the index of the first selected branch in the branches list")] + public int? GetSelectedBranch() + { + if (Engaged()) + { + return Tastudio.GetSelectedBranch(); + } + + return null; + } + [LuaMethodExample("local nltasget = tastudio.getbranchinput( \"97021544-2454-4483-824f-47f75e7fcb6a\", 500 );")] [LuaMethod("getbranchinput", "Gets the controller state of the given frame with the given branch identifier")] public LuaTable GetBranchInput(string branchId, int frame) @@ -592,5 +604,57 @@ public void OnBranchRemove(LuaFunction luaf) }; } } + + [LuaMethodExample("function LoadUndone()\r\n\tconsole.log(\"You did a branch load undo\")\r\nend\r\ntastudio.onbranchundoload(LoadUndone)")] + [LuaMethod("onbranchundoload", "called whenever a branch load is undone. luaf must be a function without parameters")] + public void OnBranchUndoLoad(LuaFunction luaf) + { + if (Engaged()) + { + Tastudio.BranchLoadUndoneCallback = () => + { + luaf.Call(); + }; + } + } + + [LuaMethodExample("function UpdateUndone(index)\r\n\tconsole.log(\"You did a branch updaate undo for branch \"..index)\r\nend\r\ntastudio.onbranchundoupdate(UpdateUndone)")] + [LuaMethod("onbranchundoupdate", "called whenever a branch update is undone. luaf must be a function that takes the integer branch index as a parameter")] + public void OnBranchUndoUpdate(LuaFunction luaf) + { + if (Engaged()) + { + Tastudio.BranchUpdateUndoneCallback = index => + { + luaf.Call(index); + }; + } + } + + [LuaMethodExample("function RemoveUndone(index)\r\n\tconsole.log(\"You did a branch remove undo for branch \"..index)\r\nend\r\ntastudio.onbranchundoremove(RemoveUndone)")] + [LuaMethod("onbranchundoremove", "called whenever a branch removal is undone. luaf must be a function that takes the integer branch index as a parameter")] + public void OnBranchUndoRemove(LuaFunction luaf) + { + if (Engaged()) + { + Tastudio.BranchRemoveUndoneCallback = index => + { + luaf.Call(index); + }; + } + } + + [LuaMethodExample("function Reordered(oldindex, newindex)\r\n\tconsole.log(\"You reordered branches from \"..oldIndex..\" to \"..newIndex)\r\nend\r\ntastudio.onbranchesreorder(Reordered)")] + [LuaMethod("onbranchesreorder", "called whenever branches are reordered in the branches box. luaf must be a function that takes two integers for the branch indices as parameters")] + public void OnBranchesReorder(LuaFunction luaf) + { + if (Engaged()) + { + Tastudio.BranchesReorderedCallback = (oldIndex, newIndex) => + { + luaf.Call(oldIndex, newIndex); + }; + } + } } } diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs index c36c37904c9..eab694e1dc0 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs @@ -37,6 +37,14 @@ private enum BranchUndo public Action RemovedCallback { get; set; } + public Action LoadUndoneCallback { get; set; } + + public Action UpdateUndoneCallback { get; set; } + + public Action RemoveUndoneCallback { get; set; } + + public Action ReorderedCallback { get; set; } + public TAStudio Tastudio { get; set; } public IDialogController DialogController => Tastudio.MainForm; @@ -358,7 +366,7 @@ private void UndoBranchToolStripMenuItem_Click(object sender, EventArgs e) if (_branchUndo == BranchUndo.Load) { LoadBranch(_backupBranch); - LoadedCallback?.Invoke(Branches.IndexOf(_backupBranch)); + LoadUndoneCallback?.Invoke(); Tastudio.MainForm.AddOnScreenMessage("Branch Load canceled"); } else if (_branchUndo == BranchUndo.Update) @@ -367,7 +375,7 @@ private void UndoBranchToolStripMenuItem_Click(object sender, EventArgs e) if (branch != null) { Branches.Replace(branch, _backupBranch); - SavedCallback?.Invoke(Branches.IndexOf(_backupBranch)); + UpdateUndoneCallback?.Invoke(Branches.IndexOf(_backupBranch)); Tastudio.MainForm.AddOnScreenMessage("Branch Update canceled"); } } @@ -385,7 +393,7 @@ private void UndoBranchToolStripMenuItem_Click(object sender, EventArgs e) { Branches.Add(_backupBranch); BranchView.RowCount = Branches.Count; - SavedCallback?.Invoke(Branches.IndexOf(_backupBranch)); + RemoveUndoneCallback?.Invoke(Branches.IndexOf(_backupBranch)); Tastudio.MainForm.AddOnScreenMessage("Branch Removal canceled"); } @@ -453,6 +461,11 @@ public void RemoveBranchExternal() RemoveBranchToolStripMenuItem_Click(null, null); } + public int? GetSelectedBranch() + { + return BranchView.SelectionStartIndex; + } + public void SelectBranchExternal(int slot) { if (Tastudio.AxisEditingMode) @@ -635,6 +648,7 @@ private void BranchView_CellDropped(object sender, InputRoll.CellEventArgs e) : Branches[Branches.Current].Uuid; Branches.Swap(e.OldCell.RowIndex.Value, e.NewCell.RowIndex.Value); + ReorderedCallback?.Invoke(e.OldCell.RowIndex.Value, e.NewCell.RowIndex.Value); int newIndex = Branches.IndexOfHash(guid); Branches.Current = newIndex; Select(newIndex, true); diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Callbacks.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Callbacks.cs index 637837fbac7..47f43a6bad6 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Callbacks.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Callbacks.cs @@ -13,6 +13,10 @@ public partial class TAStudio public Action BranchLoadedCallback { get; set; } public Action BranchSavedCallback { get; set; } public Action BranchRemovedCallback { get; set; } + public Action BranchLoadUndoneCallback { get; set; } + public Action BranchUpdateUndoneCallback { get; set; } + public Action BranchRemoveUndoneCallback { get; set; } + public Action BranchesReorderedCallback { get; set; } private void GreenzoneInvalidated(int index) { @@ -33,5 +37,25 @@ private void BranchRemoved(int index) { BranchRemovedCallback?.Invoke(index); } + + private void BranchLoadUndone() + { + BranchLoadUndoneCallback?.Invoke(); + } + + private void BranchUpdateUndone(int index) + { + BranchUpdateUndoneCallback?.Invoke(index); + } + + private void BranchRemoveUndone(int index) + { + BranchRemoveUndoneCallback?.Invoke(index); + } + + private void BranchesReordered(int oldIndex, int newIndex) + { + BranchesReorderedCallback?.Invoke(oldIndex, newIndex); + } } } diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index ac7988b824d..949a103e553 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -148,6 +148,10 @@ public TAStudio() BookMarkControl.LoadedCallback = BranchLoaded; BookMarkControl.SavedCallback = BranchSaved; BookMarkControl.RemovedCallback = BranchRemoved; + BookMarkControl.LoadUndoneCallback = BranchLoadUndone; + BookMarkControl.UpdateUndoneCallback = BranchUpdateUndone; + BookMarkControl.RemoveUndoneCallback = BranchRemoveUndone; + BookMarkControl.ReorderedCallback = BranchesReordered; TasView.MouseLeave += TAStudio_MouseLeave; TasView.CellHovered += (_, e) => { @@ -436,6 +440,7 @@ public void AddColumn(string name, string text, int widthUnscaled) public void SelectAllExternal() => SelectAllMenuItem_Click(null, null); public void ReselectClipboardExternal() => ReselectClipboardMenuItem_Click(null, null); + public int? GetSelectedBranch() => BookMarkControl.GetSelectedBranch(); public IMovieController GetBranchInput(string branchId, int frame) { var branch = CurrentTasMovie.Branches.FirstOrDefault(b => b.Uuid.ToString() == branchId);