diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs index baf6c23acc..f8ef6337b0 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs @@ -91,8 +91,8 @@ namespace BizHawk.Client.Common public TasBranch GetBranch(int index) { - if (index >= Branches.Count) - return null; // are we allowed? + if (index >= Branches.Count || index < 0) + return null; else return Branches[index]; } diff --git a/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs b/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs index 26ae9ff81c..9ad188dee1 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs @@ -341,6 +341,14 @@ namespace BizHawk.Client.EmuHawk GlobalWin.Tools.RamSearch.NextOperator(); break; + //TAStudio + case "Add Branch": + GlobalWin.Tools.TAStudio.BookMarkControl.AddBranchExternal(); + break; + case "Delete Branch": + GlobalWin.Tools.TAStudio.BookMarkControl.RemoveBranchExtrenal(); + break; + // SNES case "Toggle BG 1": SNES_ToggleBG1(); diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index 962794e399..43e3355e05 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -1569,6 +1569,7 @@ namespace BizHawk.Client.EmuHawk { if (GlobalWin.Tools.TAStudio != null) { + GlobalWin.Tools.TAStudio.BookMarkControl.SelectBranchExternal(num); return; } @@ -2194,6 +2195,7 @@ namespace BizHawk.Client.EmuHawk { if (GlobalWin.Tools.TAStudio != null) { + GlobalWin.Tools.TAStudio.BookMarkControl.SelectBranchExternal(false); return; } @@ -2221,6 +2223,7 @@ namespace BizHawk.Client.EmuHawk { if (GlobalWin.Tools.TAStudio != null) { + GlobalWin.Tools.TAStudio.BookMarkControl.SelectBranchExternal(true); return; } @@ -2698,6 +2701,11 @@ namespace BizHawk.Client.EmuHawk }); } + private int SlotToInt(string slot) + { + return int.Parse(slot.Substring(slot.Length - 1, 1)); + } + public void LoadState(string path, string userFriendlyStateName, bool fromLua = false, bool supressOSD = false) // Move to client.common { if (!Global.Emulator.HasSavestates()) @@ -2707,6 +2715,7 @@ namespace BizHawk.Client.EmuHawk if (GlobalWin.Tools.TAStudio != null) { + GlobalWin.Tools.TAStudio.BookMarkControl.LoadBranchExternal(); return; } @@ -2754,6 +2763,7 @@ namespace BizHawk.Client.EmuHawk if (GlobalWin.Tools.TAStudio != null) { + GlobalWin.Tools.TAStudio.BookMarkControl.LoadBranchExternal(SlotToInt(quickSlotName)); return; } @@ -2777,6 +2787,7 @@ namespace BizHawk.Client.EmuHawk if (GlobalWin.Tools.TAStudio != null) { + GlobalWin.Tools.TAStudio.BookMarkControl.UpdateBranchExternal(); return; } @@ -3717,6 +3728,7 @@ namespace BizHawk.Client.EmuHawk if (GlobalWin.Tools.TAStudio != null) { + GlobalWin.Tools.TAStudio.BookMarkControl.UpdateBranchExternal(SlotToInt(quickSlotName)); return; } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs index f4f8193ec2..6de76a7445 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs @@ -174,8 +174,8 @@ namespace BizHawk.Client.EmuHawk private void UpdateBranch(TasBranch branch) { Movie.UpdateBranch(branch, CreateBranch()); - BranchView.Refresh(); Tastudio.RefreshDialog(); + //BranchView.Refresh(); } private void LoadSelectedBranch() @@ -220,8 +220,8 @@ namespace BizHawk.Client.EmuHawk { if (SelectedBranch != null) { - UpdateBranch(SelectedBranch); Movie.CurrentBranch = BranchView.SelectedRows.First(); + UpdateBranch(SelectedBranch); } } @@ -251,16 +251,98 @@ namespace BizHawk.Client.EmuHawk Movie.RemoveBranch(SelectedBranch); BranchView.RowCount = Movie.BranchCount; - if (index == BranchView.SelectedRows.FirstOrDefault()) + if (index == Movie.BranchCount) { BranchView.ClearSelectedRows(); + BranchView.SelectRow(Movie.BranchCount - 1, true); } - BranchView.Refresh(); + //BranchView.Refresh(); Tastudio.RefreshDialog(); } } + public void AddBranchExternal() + { + AddBranchToolStripMenuItem_Click(null, null); + BranchView.SelectRow(Movie.CurrentBranch, true); + BranchView.Refresh(); + } + + public void LoadBranchExternal(int slot = -1) + { + if (slot != -1) + { + if (GetBranch(slot) != null) + { + BranchView.SelectRow(slot, true); + } + else + { + return; + } + } + LoadBranchToolStripMenuItem_Click(null, null); + } + + public void UpdateBranchExternal(int slot = -1) + { + if (slot != -1) + { + if (GetBranch(slot) != null) + { + BranchView.SelectRow(slot, true); + } + else + { + return; + } + } + UpdateBranchToolStripMenuItem_Click(null, null); + } + + public void RemoveBranchExtrenal() + { + RemoveBranchToolStripMenuItem_Click(null, null); + } + + public void SelectBranchExternal(int slot) + { + if (GetBranch(slot) != null) + { + BranchView.SelectRow(slot, true); + BranchView.Refresh(); + } + } + + public void SelectBranchExternal(bool next) + { + if (SelectedBranch == null) + { + BranchView.SelectRow(Movie.CurrentBranch, true); + BranchView.Refresh(); + return; + } + int sel = BranchView.SelectedRows.First(); + if (next) + { + if (GetBranch(sel + 1) != null) + { + BranchView.SelectRow(sel, false); + BranchView.SelectRow(sel + 1, true); + } + } + else // previous + { + if (GetBranch(sel - 1) != null) + { + BranchView.SelectRow(sel, false); + BranchView.SelectRow(sel - 1, true); + } + } + BranchView.Refresh(); + } + public void UpdateValues() { BranchView.RowCount = Movie.BranchCount; diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs index d963c86926..8691a60c6c 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs @@ -1672,7 +1672,7 @@ namespace BizHawk.Client.EmuHawk private System.Windows.Forms.ToolStripMenuItem scrollToCenterToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem applyPatternToPaintedInputToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem onlyOnAutoFireColumnsToolStripMenuItem; - private BookmarksBranchesBox BookMarkControl; + public BookmarksBranchesBox BookMarkControl; private System.Windows.Forms.ToolStripMenuItem BranchContextMenuItem; private System.Windows.Forms.ToolStripSeparator toolStripSeparator25; private System.Windows.Forms.ToolStripMenuItem wheelScrollSpeedToolStripMenuItem;