From e49754b705b2b23d5a6cc09d6f3b9040a9694b49 Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 11 Jul 2014 23:54:18 +0000 Subject: [PATCH] TAStudio - implement paste and paste insert --- .../movie/tasproj/TasMovie.Editing.cs | 29 +++++++++ .../tools/TAStudio/TAStudio.Designer.cs | 4 +- .../tools/TAStudio/TAStudio.cs | 60 ++++++++++++++++++- 3 files changed, 90 insertions(+), 3 deletions(-) diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs index b81d66d8d4..541165ecb6 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs @@ -70,6 +70,35 @@ namespace BizHawk.Client.Common InvalidateAfter(frame); } + public void InsertInput(int frame, IEnumerable inputStates) + { + var lg = LogGeneratorInstance(); + + var inputLog = new List(); + + foreach (var input in inputStates) + { + lg.SetSource(input); + inputLog.Add(lg.GenerateLogEntry()); + } + + InsertInput(frame, inputLog); + } + + public void CopyOverInput(int frame, IEnumerable inputStates) + { + var lg = LogGeneratorInstance(); + var states = inputStates.ToList(); + for (int i = 0; i < states.Count; i++) + { + lg.SetSource(states[i]); + _log[frame + i] = lg.GenerateLogEntry(); + } + + Changes = true; + InvalidateAfter(frame); + } + public void InsertEmptyFrame(int frame) { var lg = LogGeneratorInstance(); diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs index 60fc2b57ae..46da547f2d 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs @@ -330,20 +330,20 @@ namespace BizHawk.Client.EmuHawk // // PasteMenuItem // - this.PasteMenuItem.Enabled = false; this.PasteMenuItem.Name = "PasteMenuItem"; this.PasteMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.V))); this.PasteMenuItem.Size = new System.Drawing.Size(240, 22); this.PasteMenuItem.Text = "&Paste"; + this.PasteMenuItem.Click += new System.EventHandler(this.PasteMenuItem_Click); // // PasteInsertMenuItem // - this.PasteInsertMenuItem.Enabled = false; this.PasteInsertMenuItem.Name = "PasteInsertMenuItem"; this.PasteInsertMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Shift) | System.Windows.Forms.Keys.V))); this.PasteInsertMenuItem.Size = new System.Drawing.Size(240, 22); this.PasteInsertMenuItem.Text = "&Paste Insert"; + this.PasteInsertMenuItem.Click += new System.EventHandler(this.PasteInsertMenuItem_Click); // // CutMenuItem // diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index f3321834ee..99e2ae179b 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Drawing; using System.IO; @@ -31,6 +32,39 @@ namespace BizHawk.Client.EmuHawk return (lg as Bk2LogEntryGenerator).Map(); } + // Indices Helpers + private int FirstSelectedIndex + { + get + { + return TasView.SelectedIndices + .OfType() + .OrderBy(frame => frame) + .First(); + } + } + + private int LastSelectedIndex + { + get + { + return TasView.SelectedIndices + .OfType() + .OrderBy(frame => frame) + .Last(); + } + } + + private IEnumerable SelectedIndices + { + get + { + return TasView.SelectedIndices + .OfType() + .OrderBy(frame => frame); + } + } + public TAStudio() { InitializeComponent(); @@ -388,7 +422,7 @@ namespace BizHawk.Client.EmuHawk var sb = new StringBuilder(); for (var i = 0; i < list.Count; i++) { - var input = _tas.GetInputState(i); + var input = _tas.GetInputState(list[i]); _tasClipboard.Add(new TasClipboardEntry(list[i], input)); var lg = _tas.LogGeneratorInstance(); lg.SetSource(input); @@ -400,6 +434,30 @@ namespace BizHawk.Client.EmuHawk SetSplicer(); } + private void PasteMenuItem_Click(object sender, EventArgs e) + { + // TODO: if highlighting 2 rows and pasting 3, only paste 2 of them + // FCEUX Taseditor does't do this, but I think it is the expected behavior in editor programs + if (_tasClipboard.Any()) + { + _tas.CopyOverInput(FirstSelectedIndex, _tasClipboard.Select(x => x.ControllerState)); + } + + RefreshDialog(); + } + + private void PasteInsertMenuItem_Click(object sender, EventArgs e) + { + // TODO: if highlighting 2 rows and pasting 3, only paste 2 of them + // FCEUX Taseditor does't do this, but I think it is the expected behavior in editor programs + if (_tasClipboard.Any()) + { + _tas.InsertInput(FirstSelectedIndex, _tasClipboard.Select(x => x.ControllerState)); + } + + RefreshDialog(); + } + private void CutMenuItem_Click(object sender, EventArgs e) { _tasClipboard.Clear();