From a416841770020da4278fa96bb616d55e85813e4c Mon Sep 17 00:00:00 2001 From: David Ackroyd Date: Fri, 24 Jul 2020 16:18:15 +0100 Subject: [PATCH] clone x times (#2242) * tasstudio: clone sequence of inputs x times * extend frameprompt so that you can put in a custom messagfe * making FramesPrompt designer compatible --- .../tools/TAStudio/FramesPrompt.cs | 8 +++ .../tools/TAStudio/TAStudio.Designer.cs | 20 +++++++- .../tools/TAStudio/TAStudio.MenuItems.cs | 49 +++++++++++++------ .../tools/TAStudio/TAStudio.cs | 1 + 4 files changed, 61 insertions(+), 17 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/FramesPrompt.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/FramesPrompt.cs index 6f8e6b12f0..25127ef6d0 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/FramesPrompt.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/FramesPrompt.cs @@ -10,6 +10,14 @@ namespace BizHawk.Client.EmuHawk InitializeComponent(); } + public FramesPrompt(string headMessage, string bodyMessage) + { + InitializeComponent(); + + this.Text = headMessage; + this.label1.Text = bodyMessage; + } + public int Frames => NumFramesBox.ToRawInt() ?? 0; private void FramesPrompt_Load(object sender, EventArgs e) diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs index 0a27906217..10b03d1b2b 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs @@ -74,6 +74,7 @@ namespace BizHawk.Client.EmuHawk this.InsertFrameMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx(); this.DeleteFramesMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx(); this.CloneFramesMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx(); + this.CloneFramesXTimesMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx(); this.InsertNumFramesMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx(); this.toolStripSeparator6 = new BizHawk.WinForms.Controls.ToolStripSeparatorEx(); this.TruncateMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx(); @@ -180,6 +181,7 @@ namespace BizHawk.Client.EmuHawk this.InsertFrameContextMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx(); this.DeleteFramesContextMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx(); this.CloneContextMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx(); + this.CloneXTimesContextMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx(); this.InsertNumFramesContextMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx(); this.toolStripSeparator18 = new BizHawk.WinForms.Controls.ToolStripSeparatorEx(); this.TruncateContextMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx(); @@ -352,7 +354,8 @@ namespace BizHawk.Client.EmuHawk this.InsertFrameMenuItem, this.DeleteFramesMenuItem, this.CloneFramesMenuItem, - this.InsertNumFramesMenuItem, + this.CloneFramesXTimesMenuItem, + this.InsertNumFramesMenuItem, this.toolStripSeparator6, this.TruncateMenuItem, this.ClearGreenzoneMenuItem, @@ -454,6 +457,11 @@ namespace BizHawk.Client.EmuHawk this.CloneFramesMenuItem.Text = "&Clone"; this.CloneFramesMenuItem.Click += new System.EventHandler(this.CloneFramesMenuItem_Click); // + // CloneFramesXTimesMenuItem + // + this.CloneFramesXTimesMenuItem.Text = "Clone # Times"; + this.CloneFramesXTimesMenuItem.Click += new System.EventHandler(this.CloneFramesXTimesMenuItem_Click); + // // InsertNumFramesMenuItem // this.InsertNumFramesMenuItem.ShortcutKeyDisplayString = ""; @@ -996,7 +1004,8 @@ namespace BizHawk.Client.EmuHawk this.InsertFrameContextMenuItem, this.DeleteFramesContextMenuItem, this.CloneContextMenuItem, - this.InsertNumFramesContextMenuItem, + this.CloneXTimesContextMenuItem, + this.InsertNumFramesContextMenuItem, this.toolStripSeparator18, this.TruncateContextMenuItem, this.BranchContextMenuItem, @@ -1086,6 +1095,11 @@ namespace BizHawk.Client.EmuHawk this.CloneContextMenuItem.Text = "Clone"; this.CloneContextMenuItem.Click += new System.EventHandler(this.CloneFramesMenuItem_Click); // + // CloneXTimesContextMenuItem + // + this.CloneXTimesContextMenuItem.Text = "Clone # Times"; + this.CloneXTimesContextMenuItem.Click += new System.EventHandler(this.CloneFramesXTimesMenuItem_Click); + // // InsertNumFramesContextMenuItem // this.InsertNumFramesContextMenuItem.Text = "Insert # of Frames"; @@ -1230,6 +1244,7 @@ namespace BizHawk.Client.EmuHawk private BizHawk.WinForms.Controls.ToolStripSeparatorEx toolStripSeparator4; private BizHawk.WinForms.Controls.ToolStripSeparatorEx toolStripSeparator7; private BizHawk.WinForms.Controls.ToolStripMenuItemEx CloneFramesMenuItem; + private BizHawk.WinForms.Controls.ToolStripMenuItemEx CloneFramesXTimesMenuItem; private BizHawk.WinForms.Controls.ToolStripMenuItemEx DeleteFramesMenuItem; private BizHawk.WinForms.Controls.ToolStripMenuItemEx ClearFramesMenuItem; private BizHawk.WinForms.Controls.ToolStripMenuItemEx InsertNumFramesMenuItem; @@ -1288,6 +1303,7 @@ namespace BizHawk.Client.EmuHawk private BizHawk.WinForms.Controls.ToolStripMenuItemEx InsertFrameContextMenuItem; private BizHawk.WinForms.Controls.ToolStripMenuItemEx InsertNumFramesContextMenuItem; private BizHawk.WinForms.Controls.ToolStripMenuItemEx CloneContextMenuItem; + private BizHawk.WinForms.Controls.ToolStripMenuItemEx CloneXTimesContextMenuItem; private BizHawk.WinForms.Controls.ToolStripSeparatorEx toolStripSeparator18; private BizHawk.WinForms.Controls.ToolStripMenuItemEx TruncateContextMenuItem; private BizHawk.WinForms.Controls.ToolStripMenuItemEx ClearGreenzoneMenuItem; diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs index 63e25afeb7..717bbb35a3 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs @@ -309,6 +309,7 @@ namespace BizHawk.Client.EmuHawk ClearFramesMenuItem.Enabled = DeleteFramesMenuItem.Enabled = CloneFramesMenuItem.Enabled = + CloneFramesXTimesMenuItem.Enabled = TruncateMenuItem.Enabled = InsertFrameMenuItem.Enabled = InsertNumFramesMenuItem.Enabled = @@ -623,25 +624,42 @@ namespace BizHawk.Client.EmuHawk private void CloneFramesMenuItem_Click(object sender, EventArgs e) { - if (TasView.AnyRowsSelected) + CloneFramesXTimes(1); + } + + private void CloneFramesXTimesMenuItem_Click(object sender, EventArgs e) + { + using var framesPrompt = new FramesPrompt("Clone # Times", "Insert times to clone:"); + if (framesPrompt.ShowDialog().IsOk()) { - var framesToInsert = TasView.SelectedRows; - var insertionFrame = Math.Min((TasView.LastSelectedIndex ?? 0) + 1, CurrentTasMovie.InputLogLength); - var needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame; + CloneFramesXTimes(framesPrompt.Frames); + } + } - var inputLog = framesToInsert - .Select(frame => CurrentTasMovie.GetInputLogEntry(frame)) - .ToList(); - - CurrentTasMovie.InsertInput(insertionFrame, inputLog); - - if (needsToRollback) + private void CloneFramesXTimes(int timesToClone) + { + for (int i = 0; i < timesToClone; i++) + { + if (TasView.AnyRowsSelected) { - GoToLastEmulatedFrameIfNecessary(insertionFrame); - DoAutoRestore(); - } + var framesToInsert = TasView.SelectedRows; + var insertionFrame = Math.Min((TasView.LastSelectedIndex ?? 0) + 1, CurrentTasMovie.InputLogLength); + var needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame; - FullRefresh(); + var inputLog = framesToInsert + .Select(frame => CurrentTasMovie.GetInputLogEntry(frame)) + .ToList(); + + CurrentTasMovie.InsertInput(insertionFrame, inputLog); + + if (needsToRollback) + { + GoToLastEmulatedFrameIfNecessary(insertionFrame); + DoAutoRestore(); + } + + FullRefresh(); + } } } @@ -1318,6 +1336,7 @@ namespace BizHawk.Client.EmuHawk ClearContextMenuItem.Enabled = DeleteFramesContextMenuItem.Enabled = CloneContextMenuItem.Enabled = + CloneXTimesContextMenuItem.Enabled = InsertFrameContextMenuItem.Enabled = InsertNumFramesContextMenuItem.Enabled = TruncateContextMenuItem.Enabled = diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index fe9a18a6c6..68ff7f49e5 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -500,6 +500,7 @@ namespace BizHawk.Client.EmuHawk public void InsertNumFramesExternal() => InsertNumFramesMenuItem_Click(null, null); public void DeleteFramesExternal() => DeleteFramesMenuItem_Click(null, null); public void CloneFramesExternal() => CloneFramesMenuItem_Click(null, null); + public void CloneFramesXTimesExternal() => CloneFramesXTimesMenuItem_Click(null, null); public void UndoExternal() => UndoMenuItem_Click(null, null); public void RedoExternal() => RedoMenuItem_Click(null, null); public void SelectBetweenMarkersExternal() => SelectBetweenMarkersMenuItem_Click(null, null);