From 8c064875c26da0668190573895004fc07cdc5e1d Mon Sep 17 00:00:00 2001 From: adelikat Date: Tue, 15 Jul 2014 23:43:17 +0000 Subject: [PATCH] TAStudio - ability to add markers, very crude implementation for now --- .../movie/tasproj/TasMovie.cs | 3 +++ .../movie/tasproj/TasMovieMarker.cs | 16 +++-------- .../tools/HexEditor/HexEditor.cs | 4 +-- BizHawk.Client.EmuHawk/tools/InputPrompt.cs | 6 ++--- .../tools/TAStudio/MarkerControl.Designer.cs | 16 ++++++++++- .../tools/TAStudio/MarkerControl.cs | 26 +++++++++++++++++- .../tools/TAStudio/TAStudio.Designer.cs | 2 +- .../tools/TAStudio/TAStudio.cs | 27 ++++++++++++++++++- BizHawk.Client.EmuHawk/tools/TraceLogger.cs | 4 +-- .../tools/Watch/RamSearch.cs | 4 +-- 10 files changed, 81 insertions(+), 27 deletions(-) diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs index 527afe1d96..15f1ea42bc 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs @@ -21,6 +21,7 @@ namespace BizHawk.Client.Common { Header[HeaderKeys.MOVIEVERSION] = "BizHawk v2.0 Tasproj v1.0"; Markers = new TasMovieMarkerList(); + Markers.Add(0, StartsFromSavestate ? "Savestate" : "Power on"); } public override string PreferredExtension @@ -56,6 +57,8 @@ namespace BizHawk.Client.Common StateManager.Clear(); Markers.Clear(); base.StartNewRecording(); + + Markers.Add(0, StartsFromSavestate ? "Savestate" : "Power on"); } /// diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovieMarker.cs b/BizHawk.Client.Common/movie/tasproj/TasMovieMarker.cs index 86d318715d..d536d5df8e 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovieMarker.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovieMarker.cs @@ -61,16 +61,6 @@ namespace BizHawk.Client.Common } } - public static bool operator ==(TasMovieMarker a, TasMovieMarker b) - { - return a.Frame == b.Frame; - } - - public static bool operator !=(TasMovieMarker a, TasMovieMarker b) - { - return a.Frame != b.Frame; - } - public static bool operator ==(TasMovieMarker marker, int frame) { return marker.Frame == frame; @@ -125,9 +115,9 @@ namespace BizHawk.Client.Common public TasMovieMarker Previous(int currentFrame) { return this - .Where(m => m.Frame < currentFrame) + .Where(m => m.Frame <= currentFrame) .OrderBy(m => m.Frame) - .Last(); + .LastOrDefault(); } public TasMovieMarker Next(int currentFrame) @@ -135,7 +125,7 @@ namespace BizHawk.Client.Common return this .Where(m => m.Frame > currentFrame) .OrderBy(m => m.Frame) - .First(); + .FirstOrDefault(); } } } diff --git a/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs b/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs index 9a5ba4e578..d1a1bdc875 100644 --- a/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs +++ b/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs @@ -1479,9 +1479,9 @@ namespace BizHawk.Client.EmuHawk { var inputPrompt = new InputPrompt { Text = "Go to Address", StartLocation = GetPromptPoint() }; inputPrompt.SetMessage("Enter a hexadecimal value"); - inputPrompt.ShowHawkDialog(); + var result = inputPrompt.ShowHawkDialog(); - if (inputPrompt.UserOk && inputPrompt.UserText.IsHex()) + if (result == DialogResult.OK && inputPrompt.UserText.IsHex()) { GoToAddress(int.Parse(inputPrompt.UserText, NumberStyles.HexNumber)); } diff --git a/BizHawk.Client.EmuHawk/tools/InputPrompt.cs b/BizHawk.Client.EmuHawk/tools/InputPrompt.cs index 07f33b4dc6..da57d77519 100644 --- a/BizHawk.Client.EmuHawk/tools/InputPrompt.cs +++ b/BizHawk.Client.EmuHawk/tools/InputPrompt.cs @@ -14,12 +14,10 @@ namespace BizHawk.Client.EmuHawk public InputPrompt() { InitializeComponent(); - UserText = string.Empty; StartLocation = new Point(-1, -1); } public enum InputType { Hex, Unsigned, Signed, Text } - public bool UserOk { get; set; } // Will be true if the user selects Ok public string UserText { get; set; } // What the user selected public Point StartLocation { get; set; } public InputType TextInputType { get; set; } @@ -54,14 +52,14 @@ namespace BizHawk.Client.EmuHawk private void Ok_Click(object sender, EventArgs e) { - UserOk = true; + DialogResult = DialogResult.OK; UserText = PromptBox.Text; Close(); } private void Cancel_Click(object sender, EventArgs e) { - UserOk = false; + DialogResult = DialogResult.Cancel; Close(); } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.Designer.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.Designer.cs index e696e06e9e..1d8cec1eb8 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.Designer.cs @@ -28,11 +28,23 @@ /// private void InitializeComponent() { + this.AddBtn = new System.Windows.Forms.Button(); this.MarkerView = new BizHawk.Client.EmuHawk.VirtualListView(); this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.SuspendLayout(); // + // AddBtn + // + this.AddBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.AddBtn.Location = new System.Drawing.Point(157, 214); + this.AddBtn.Name = "AddBtn"; + this.AddBtn.Size = new System.Drawing.Size(44, 23); + this.AddBtn.TabIndex = 6; + this.AddBtn.Text = "Add"; + this.AddBtn.UseVisualStyleBackColor = true; + this.AddBtn.Click += new System.EventHandler(this.AddBtn_Click); + // // MarkerView // this.MarkerView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -72,9 +84,10 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.AddBtn); this.Controls.Add(this.MarkerView); this.Name = "MarkerControl"; - this.Size = new System.Drawing.Size(204, 215); + this.Size = new System.Drawing.Size(204, 241); this.Load += new System.EventHandler(this.MarkerControl_Load); this.ResumeLayout(false); @@ -85,6 +98,7 @@ private VirtualListView MarkerView; public System.Windows.Forms.ColumnHeader columnHeader1; private System.Windows.Forms.ColumnHeader columnHeader2; + private System.Windows.Forms.Button AddBtn; } } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs index a4f69adfdf..76539705f4 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs @@ -14,6 +14,7 @@ namespace BizHawk.Client.EmuHawk public partial class MarkerControl : UserControl { public TasMovieMarkerList Markers {get; set; } + public Action AddCallback { get; set; } public MarkerControl() { @@ -34,7 +35,15 @@ namespace BizHawk.Client.EmuHawk private void MarkerView_QueryItemBkColor(int index, int column, ref Color color) { - + var prev = Markers.Previous(Global.Emulator.Frame); + + if (prev != null) + { + if (index == Markers.IndexOf(prev)) + { + color = Color.LightGreen; + } + } } private void MarkerView_QueryItemText(int index, int column, out string text) @@ -50,5 +59,20 @@ namespace BizHawk.Client.EmuHawk text = Markers[index].Message; } } + + private void AddBtn_Click(object sender, EventArgs e) + { + AddCallback(); + } + + public new void Refresh() + { + if (MarkerView != null && Markers != null) + { + MarkerView.ItemCount = Markers.Count; + } + + base.Refresh(); + } } } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs index 6655e91d1c..d9759dd2c7 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Designer.cs @@ -692,8 +692,8 @@ namespace BizHawk.Client.EmuHawk this.TasView.View = System.Windows.Forms.View.Details; this.TasView.SelectedIndexChanged += new System.EventHandler(this.TasView_SelectedIndexChanged); this.TasView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.TasView_MouseDown); - this.TasView.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.TasView_MouseWheel); this.TasView.MouseUp += new System.Windows.Forms.MouseEventHandler(this.TasView_MouseUp); + this.TasView.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.TasView_MouseWheel); // // Frame // diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index 6e00201a48..a4cc039045 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -68,6 +68,7 @@ namespace BizHawk.Client.EmuHawk public TAStudio() { InitializeComponent(); + MarkerControl.AddCallback = CallAddMarkerPopUp; TasView.QueryItemText += TasView_QueryItemText; TasView.QueryItemBkColor += TasView_QueryItemBkColor; TasView.VirtualMode = true; @@ -212,6 +213,10 @@ namespace BizHawk.Client.EmuHawk private void RefreshDialog() { TasView.ItemCount = _tas.InputLogLength; + if (MarkerControl != null) + { + MarkerControl.Refresh(); + } } // TODO: a better name @@ -288,7 +293,7 @@ namespace BizHawk.Client.EmuHawk Global.Emulator.FrameAdvance(true); GlobalWin.DisplayManager.NeedsToPaint = true; TasView.ensureVisible(frame); - TasView.Refresh(); + RefreshDialog(); } else { @@ -322,6 +327,26 @@ namespace BizHawk.Client.EmuHawk Owner = Global.Config.TAStudioSettings.FloatingWindow ? null : GlobalWin.MainForm; } + private void CallAddMarkerPopUp() + { + InputPrompt i = new InputPrompt + { + Text = "Marker for frame " + Global.Emulator.Frame, + TextInputType = InputPrompt.InputType.Text + }; + + i.SetMessage("Enter a message"); + var result = i.ShowHawkDialog(); + + if (result == DialogResult.OK) + { + _tas.Markers.Add(Global.Emulator.Frame, i.UserText); + MarkerControl.Refresh(); + } + + MarkerControl.Refresh(); + } + private void UpdateChangesIndicator() { // TODO diff --git a/BizHawk.Client.EmuHawk/tools/TraceLogger.cs b/BizHawk.Client.EmuHawk/tools/TraceLogger.cs index 1100f5901f..1f8c8da78e 100644 --- a/BizHawk.Client.EmuHawk/tools/TraceLogger.cs +++ b/BizHawk.Client.EmuHawk/tools/TraceLogger.cs @@ -286,8 +286,8 @@ namespace BizHawk.Client.EmuHawk prompt.SetInitialValue(Global.Config.TraceLoggerMaxLines.ToString()); prompt.TextInputType = InputPrompt.InputType.Unsigned; prompt.StartLocation = GetPromptPoint(); - prompt.ShowDialog(); - if (prompt.UserOk) + var result = prompt.ShowHawkDialog(); + if (result == DialogResult.OK) { var max = int.Parse(prompt.UserText); if (max > 0) diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs index cb05f31090..1358c2b5ea 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs @@ -914,9 +914,9 @@ namespace BizHawk.Client.EmuHawk WatchListView.SelectedIndices.Clear(); var prompt = new InputPrompt { Text = "Go to Address", StartLocation = GetPromptPoint() }; prompt.SetMessage("Enter a hexadecimal value"); - prompt.ShowHawkDialog(); + var result = prompt.ShowHawkDialog(); - if (prompt.UserOk) + if (result == DialogResult.OK) { if (prompt.UserText.IsHex()) {