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
This commit is contained in:
David Ackroyd 2020-07-24 16:18:15 +01:00 committed by GitHub
parent e36098becf
commit a416841770
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 17 deletions

View File

@ -10,6 +10,14 @@ namespace BizHawk.Client.EmuHawk
InitializeComponent(); InitializeComponent();
} }
public FramesPrompt(string headMessage, string bodyMessage)
{
InitializeComponent();
this.Text = headMessage;
this.label1.Text = bodyMessage;
}
public int Frames => NumFramesBox.ToRawInt() ?? 0; public int Frames => NumFramesBox.ToRawInt() ?? 0;
private void FramesPrompt_Load(object sender, EventArgs e) private void FramesPrompt_Load(object sender, EventArgs e)

View File

@ -74,6 +74,7 @@ namespace BizHawk.Client.EmuHawk
this.InsertFrameMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx(); this.InsertFrameMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
this.DeleteFramesMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx(); this.DeleteFramesMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
this.CloneFramesMenuItem = 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.InsertNumFramesMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
this.toolStripSeparator6 = new BizHawk.WinForms.Controls.ToolStripSeparatorEx(); this.toolStripSeparator6 = new BizHawk.WinForms.Controls.ToolStripSeparatorEx();
this.TruncateMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx(); this.TruncateMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
@ -180,6 +181,7 @@ namespace BizHawk.Client.EmuHawk
this.InsertFrameContextMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx(); this.InsertFrameContextMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
this.DeleteFramesContextMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx(); this.DeleteFramesContextMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
this.CloneContextMenuItem = 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.InsertNumFramesContextMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
this.toolStripSeparator18 = new BizHawk.WinForms.Controls.ToolStripSeparatorEx(); this.toolStripSeparator18 = new BizHawk.WinForms.Controls.ToolStripSeparatorEx();
this.TruncateContextMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx(); this.TruncateContextMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
@ -352,7 +354,8 @@ namespace BizHawk.Client.EmuHawk
this.InsertFrameMenuItem, this.InsertFrameMenuItem,
this.DeleteFramesMenuItem, this.DeleteFramesMenuItem,
this.CloneFramesMenuItem, this.CloneFramesMenuItem,
this.InsertNumFramesMenuItem, this.CloneFramesXTimesMenuItem,
this.InsertNumFramesMenuItem,
this.toolStripSeparator6, this.toolStripSeparator6,
this.TruncateMenuItem, this.TruncateMenuItem,
this.ClearGreenzoneMenuItem, this.ClearGreenzoneMenuItem,
@ -454,6 +457,11 @@ namespace BizHawk.Client.EmuHawk
this.CloneFramesMenuItem.Text = "&Clone"; this.CloneFramesMenuItem.Text = "&Clone";
this.CloneFramesMenuItem.Click += new System.EventHandler(this.CloneFramesMenuItem_Click); 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 // InsertNumFramesMenuItem
// //
this.InsertNumFramesMenuItem.ShortcutKeyDisplayString = ""; this.InsertNumFramesMenuItem.ShortcutKeyDisplayString = "";
@ -996,7 +1004,8 @@ namespace BizHawk.Client.EmuHawk
this.InsertFrameContextMenuItem, this.InsertFrameContextMenuItem,
this.DeleteFramesContextMenuItem, this.DeleteFramesContextMenuItem,
this.CloneContextMenuItem, this.CloneContextMenuItem,
this.InsertNumFramesContextMenuItem, this.CloneXTimesContextMenuItem,
this.InsertNumFramesContextMenuItem,
this.toolStripSeparator18, this.toolStripSeparator18,
this.TruncateContextMenuItem, this.TruncateContextMenuItem,
this.BranchContextMenuItem, this.BranchContextMenuItem,
@ -1086,6 +1095,11 @@ namespace BizHawk.Client.EmuHawk
this.CloneContextMenuItem.Text = "Clone"; this.CloneContextMenuItem.Text = "Clone";
this.CloneContextMenuItem.Click += new System.EventHandler(this.CloneFramesMenuItem_Click); 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 // InsertNumFramesContextMenuItem
// //
this.InsertNumFramesContextMenuItem.Text = "Insert # of Frames"; 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 toolStripSeparator4;
private BizHawk.WinForms.Controls.ToolStripSeparatorEx toolStripSeparator7; private BizHawk.WinForms.Controls.ToolStripSeparatorEx toolStripSeparator7;
private BizHawk.WinForms.Controls.ToolStripMenuItemEx CloneFramesMenuItem; private BizHawk.WinForms.Controls.ToolStripMenuItemEx CloneFramesMenuItem;
private BizHawk.WinForms.Controls.ToolStripMenuItemEx CloneFramesXTimesMenuItem;
private BizHawk.WinForms.Controls.ToolStripMenuItemEx DeleteFramesMenuItem; private BizHawk.WinForms.Controls.ToolStripMenuItemEx DeleteFramesMenuItem;
private BizHawk.WinForms.Controls.ToolStripMenuItemEx ClearFramesMenuItem; private BizHawk.WinForms.Controls.ToolStripMenuItemEx ClearFramesMenuItem;
private BizHawk.WinForms.Controls.ToolStripMenuItemEx InsertNumFramesMenuItem; 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 InsertFrameContextMenuItem;
private BizHawk.WinForms.Controls.ToolStripMenuItemEx InsertNumFramesContextMenuItem; private BizHawk.WinForms.Controls.ToolStripMenuItemEx InsertNumFramesContextMenuItem;
private BizHawk.WinForms.Controls.ToolStripMenuItemEx CloneContextMenuItem; private BizHawk.WinForms.Controls.ToolStripMenuItemEx CloneContextMenuItem;
private BizHawk.WinForms.Controls.ToolStripMenuItemEx CloneXTimesContextMenuItem;
private BizHawk.WinForms.Controls.ToolStripSeparatorEx toolStripSeparator18; private BizHawk.WinForms.Controls.ToolStripSeparatorEx toolStripSeparator18;
private BizHawk.WinForms.Controls.ToolStripMenuItemEx TruncateContextMenuItem; private BizHawk.WinForms.Controls.ToolStripMenuItemEx TruncateContextMenuItem;
private BizHawk.WinForms.Controls.ToolStripMenuItemEx ClearGreenzoneMenuItem; private BizHawk.WinForms.Controls.ToolStripMenuItemEx ClearGreenzoneMenuItem;

View File

@ -309,6 +309,7 @@ namespace BizHawk.Client.EmuHawk
ClearFramesMenuItem.Enabled = ClearFramesMenuItem.Enabled =
DeleteFramesMenuItem.Enabled = DeleteFramesMenuItem.Enabled =
CloneFramesMenuItem.Enabled = CloneFramesMenuItem.Enabled =
CloneFramesXTimesMenuItem.Enabled =
TruncateMenuItem.Enabled = TruncateMenuItem.Enabled =
InsertFrameMenuItem.Enabled = InsertFrameMenuItem.Enabled =
InsertNumFramesMenuItem.Enabled = InsertNumFramesMenuItem.Enabled =
@ -623,25 +624,42 @@ namespace BizHawk.Client.EmuHawk
private void CloneFramesMenuItem_Click(object sender, EventArgs e) 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; CloneFramesXTimes(framesPrompt.Frames);
var insertionFrame = Math.Min((TasView.LastSelectedIndex ?? 0) + 1, CurrentTasMovie.InputLogLength); }
var needsToRollback = TasView.FirstSelectedIndex < Emulator.Frame; }
var inputLog = framesToInsert private void CloneFramesXTimes(int timesToClone)
.Select(frame => CurrentTasMovie.GetInputLogEntry(frame)) {
.ToList(); for (int i = 0; i < timesToClone; i++)
{
CurrentTasMovie.InsertInput(insertionFrame, inputLog); if (TasView.AnyRowsSelected)
if (needsToRollback)
{ {
GoToLastEmulatedFrameIfNecessary(insertionFrame); var framesToInsert = TasView.SelectedRows;
DoAutoRestore(); 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 = ClearContextMenuItem.Enabled =
DeleteFramesContextMenuItem.Enabled = DeleteFramesContextMenuItem.Enabled =
CloneContextMenuItem.Enabled = CloneContextMenuItem.Enabled =
CloneXTimesContextMenuItem.Enabled =
InsertFrameContextMenuItem.Enabled = InsertFrameContextMenuItem.Enabled =
InsertNumFramesContextMenuItem.Enabled = InsertNumFramesContextMenuItem.Enabled =
TruncateContextMenuItem.Enabled = TruncateContextMenuItem.Enabled =

View File

@ -500,6 +500,7 @@ namespace BizHawk.Client.EmuHawk
public void InsertNumFramesExternal() => InsertNumFramesMenuItem_Click(null, null); public void InsertNumFramesExternal() => InsertNumFramesMenuItem_Click(null, null);
public void DeleteFramesExternal() => DeleteFramesMenuItem_Click(null, null); public void DeleteFramesExternal() => DeleteFramesMenuItem_Click(null, null);
public void CloneFramesExternal() => CloneFramesMenuItem_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 UndoExternal() => UndoMenuItem_Click(null, null);
public void RedoExternal() => RedoMenuItem_Click(null, null); public void RedoExternal() => RedoMenuItem_Click(null, null);
public void SelectBetweenMarkersExternal() => SelectBetweenMarkersMenuItem_Click(null, null); public void SelectBetweenMarkersExternal() => SelectBetweenMarkersMenuItem_Click(null, null);