Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions src/BizHawk.Client.Common/movie/tasproj/TasBranch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,7 @@ public void Load(ZipStateLoader bl, ITasMovie movie)
});

b.Markers = new TasMovieMarkerList(movie);
bl.GetLump(nmarkers, abort: false, tr =>
{
string line;
while ((line = tr.ReadLine()) != null)
{
if (!string.IsNullOrWhiteSpace(line))
{
b.Markers.Add(new TasMovieMarker(line));
}
}
});
bl.GetLump(nmarkers, abort: false, b.Markers.LoadFromFile);

bl.GetLump(nusertext, abort: false, tr =>
{
Expand Down
12 changes: 1 addition & 11 deletions src/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,7 @@ private void LoadTasprojExtras(ZipStateLoader bl)
{
bl.GetLump(BinaryStateLump.LagLog, abort: false, tr => LagLog.Load(tr));

bl.GetLump(BinaryStateLump.Markers, abort: false, tr =>
{
string line;
while ((line = tr.ReadLine()) != null)
{
if (!string.IsNullOrWhiteSpace(line))
{
Markers.Add(new TasMovieMarker(line));
}
}
});
bl.GetLump(BinaryStateLump.Markers, abort: false, Markers.LoadFromFile);

bl.GetLump(BinaryStateLump.ClientSettings, abort: false, tr =>
{
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public bool IsReserved(int frame)
// Why the frame before?
// because we always navigate to the frame before and emulate 1 frame so that we ensure a proper frame buffer on the screen
// users want instant navigation to markers, so to do this, we need to reserve the frame before the marker, not the marker itself
return Markers.Exists(m => m.Frame - 1 == frame)
return Markers.Exists(m => m.WantsState && m.Frame - 1 == frame)
|| Branches.Any(b => b.Frame == frame); // Branches should already be in the reserved list, but it doesn't hurt to check
}

Expand Down
46 changes: 43 additions & 3 deletions src/BizHawk.Client.Common/movie/tasproj/TasMovieMarker.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using BizHawk.Common.CollectionExtensions;
Expand All @@ -22,18 +23,32 @@ public TasMovieMarker(int frame, string message = "")
/// <summary>
/// Initializes a new instance of the <see cref="TasMovieMarker"/> class from a line of text
/// </summary>
public TasMovieMarker(string line)
public TasMovieMarker(string line, int version)
{
var split = line.Split('\t');
Frame = int.Parse(split[0]);
Message = split[1];
if (version == 1)
{
Message = split[1];
}
else if (version == 2)
{
WantsState = bool.Parse(split[1]);
Message = split[2];
}
else
{
throw new Exception("Invalid version.");
}
}

public int Frame { get; private set; }

public string Message { get; set; }

public override string ToString() => Frame.ToString() + '\t' + Message;
public bool WantsState { get; set; } = true;

public override string ToString() => $"{Frame}\t{WantsState}\t{Message}";

public override int GetHashCode() => Frame.GetHashCode();

Expand Down Expand Up @@ -111,6 +126,7 @@ private void OnListChanged(NotifyCollectionChangedAction action)
public override string ToString()
{
var sb = new StringBuilder();
sb.AppendLine("2"); // version
foreach (var marker in this)
{
sb.AppendLine(marker.ToString());
Expand All @@ -119,6 +135,30 @@ public override string ToString()
return sb.ToString();
}

public void LoadFromFile(TextReader tr)
{
string line;
int version = -1;
while ((line = tr.ReadLine()) != null)
{
if (string.IsNullOrWhiteSpace(line)) continue;
if (version == -1)
{
if (line.Contains('\t'))
{
version = 1;
}
else
{
version = int.Parse(line);
line = tr.ReadLine();
if (line == null) break;
}
}
Add(new TasMovieMarker(line, version));
}
}

// the inherited one
public new void Add(TasMovieMarker item)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ private void DrawData(List<RollColumn> visibleColumns, int firstVisibleRow, int

int startRow = firstVisibleRow;
int range = Math.Min(lastVisibleRow, RowCount - 1) - startRow + 1;
_renderer.PrepDrawString(Font, _foreColor);

Cell currentCell = new();
if (HorizontalOrientation)
Expand Down Expand Up @@ -221,20 +220,17 @@ private void DrawData(List<RollColumn> visibleColumns, int firstVisibleRow, int
int strOffsetY = 0;
QueryItemText(this, f + startRow, col, out var text, ref strOffsetX, ref strOffsetY);

bool rePrep = false;
Color foreColor = _foreColor;
currentCell.Column = col;
currentCell.RowIndex = f + startRow;
if (_selectedItems.Contains(currentCell))
{
foreColor = SystemColors.HighlightText;
rePrep = true;
}
if (col.Rotatable || rePrep)
Color? foreColor = QueryItemForeColor?.Invoke(this, f + startRow, col);
if (foreColor == null)
{
_renderer.PrepDrawString(Font, foreColor, rotate: col.Rotatable);
rePrep = true;
currentCell.Column = col;
currentCell.RowIndex = f + startRow;
if (_selectedItems.Contains(currentCell))
{
foreColor = SystemColors.HighlightText;
}
}
_renderer.PrepDrawString(Font, foreColor ?? _foreColor, rotate: col.Rotatable);

int textWidth = (int)_renderer.MeasureString(text, Font).Width;
if (col.Rotatable)
Expand All @@ -253,11 +249,6 @@ private void DrawData(List<RollColumn> visibleColumns, int firstVisibleRow, int

DrawString(text, new Rectangle(baseX + textX, baseY + textY, MaxColumnWidth, CellHeight));
}

if (rePrep)
{
_renderer.PrepDrawString(Font, _foreColor);
}
}
}
}
Expand Down Expand Up @@ -285,22 +276,20 @@ private void DrawData(List<RollColumn> visibleColumns, int firstVisibleRow, int
}

QueryItemText(this, f + startRow, column, out var text, ref strOffsetX, ref strOffsetY);
Color? foreColor = QueryItemForeColor?.Invoke(this, f + startRow, column);

bool rePrep = false;
currentCell.Column = column;
currentCell.RowIndex = f + startRow;
if (_selectedItems.Contains(currentCell))
if (foreColor == null)
{
_renderer.PrepDrawString(Font, SystemColors.HighlightText);
rePrep = true;
currentCell.Column = column;
currentCell.RowIndex = f + startRow;
if (_selectedItems.Contains(currentCell))
{
foreColor = SystemColors.HighlightText;
}
}

_renderer.PrepDrawString(Font, foreColor ?? _foreColor);
DrawString(text, new Rectangle(point.X + strOffsetX, point.Y + strOffsetY, column.Width, ColumnHeight));

if (rePrep)
{
_renderer.PrepDrawString(Font, _foreColor);
}
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,12 @@ public int HoverInterval
[Category("Virtual")]
public event QueryItemBkColorHandler QueryItemBkColor;

/// <summary>
/// Fire the <see cref="QueryItemForeColor"/> event which requests the color of text for the passed cell
/// </summary>
[Category("Virtual")]
public event QueryItemForeColorHandler QueryItemForeColor;

[Category("Virtual")]
public event QueryRowBkColorHandler QueryRowBkColor;

Expand Down Expand Up @@ -520,10 +526,16 @@ public int HoverInterval
/// </summary>
public delegate void QueryItemTextHandler(InputRoll sender, int index, RollColumn column, out string text, ref int offsetX, ref int offsetY);

/// <summary>
/// Retrieve the foreground color for a cell. Return null to use the default.
/// </summary>
public delegate Color? QueryItemForeColorHandler(InputRoll sender, int index, RollColumn column);

/// <summary>
/// Retrieve the background color for a cell
/// </summary>
public delegate void QueryItemBkColorHandler(InputRoll sender, int index, RollColumn column, ref Color color);

public delegate void QueryRowBkColorHandler(InputRoll sender, int index, ref Color color);

/// <summary>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 60 additions & 8 deletions src/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
using System.ComponentModel;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;

using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.Properties;
using BizHawk.Emulation.Common;

namespace BizHawk.Client.EmuHawk
{
public partial class MarkerControl : UserControl, IDialogParent
{
private static string SAVESTATE_COL_NAME = "Savestate";

public TAStudio Tastudio { get; set; }
public TasMovieMarkerList Markers => Tastudio.CurrentTasMovie.Markers;

Expand Down Expand Up @@ -37,6 +40,7 @@ public MarkerControl()
SetupColumns();
MarkerView.QueryItemBkColor += MarkerView_QueryItemBkColor;
MarkerView.QueryItemText += MarkerView_QueryItemText;
MarkerView.QueryItemForeColor += MarkerView_QueryItemForeColor;
}

public void UpdateHotkeyTooltips(Config config)
Expand All @@ -50,6 +54,7 @@ private void SetupColumns()
{
MarkerView.AllColumns.Clear();
MarkerView.AllColumns.Add(new(name: "FrameColumn", widthUnscaled: 52, text: "Frame"));
MarkerView.AllColumns.Add(new(name: SAVESTATE_COL_NAME, widthUnscaled: 24, text: "State"));
MarkerView.AllColumns.Add(new(name: "LabelColumn", widthUnscaled: 125, text: string.Empty));
}

Expand All @@ -72,16 +77,16 @@ private void MarkerView_QueryItemBkColor(InputRoll sender, int index, RollColumn
}
else if (Tastudio.CurrentTasMovie.LagLog[marker.Frame + 1] is bool lagged)
{
if (lagged)
if (column.Name == "FrameColumn")
{
color = column.Name == "FrameColumn"
color = lagged
? Tastudio.Palette.LagZone_FrameCol
: Tastudio.Palette.LagZone_InputLog;
: Tastudio.Palette.GreenZone_FrameCol;
}
else
{
color = column.Name == "LabelColumn"
? Tastudio.Palette.GreenZone_FrameCol
color = lagged
? Tastudio.Palette.LagZone_InputLog
: Tastudio.Palette.GreenZone_InputLog;
}
}
Expand All @@ -97,14 +102,41 @@ private void MarkerView_QueryItemText(InputRoll sender, int index, RollColumn co
return;
}

TasMovieMarker marker = Markers[index];
if (column.Name == "FrameColumn")
{
text = Markers[index].Frame.ToString();
text = marker.Frame.ToString();
}
else if (column.Name == "LabelColumn")
{
text = Markers[index].Message;
text = marker.Message;
}
else if (column.Name == SAVESTATE_COL_NAME)
{
if (marker.WantsState)
{
bool hasState = marker.Frame == 0 || Tastudio.CurrentTasMovie.TasStateManager.HasState(marker.Frame - 1);
text = hasState ? "✔" : "-";
}
else
{
text = "x";
}
}
}

private Color? MarkerView_QueryItemForeColor(InputRoll sender, int index, RollColumn column)
{
if (column.Name == SAVESTATE_COL_NAME)
{
TasMovieMarker marker = Markers[index];
if (!marker.WantsState)
{
return Color.OrangeRed;
}
}

return null;
}

private void MarkerContextMenu_Opening(object sender, CancelEventArgs e)
Expand Down Expand Up @@ -188,6 +220,7 @@ public void AddMarker(int frame, bool editText = false)
{
marker = new TasMovieMarker(frame);
}
marker.WantsState = Tastudio.Settings.StatesForMarkers;

UpdateValues();
Markers.Add(marker);
Expand Down Expand Up @@ -285,5 +318,24 @@ private void MarkerView_MouseDoubleClick(object sender, EventArgs e)
{
if (MarkerView.AnyRowsSelected) Tastudio.GoToFrame(FirstSelectedMarker.Frame);
}

private void MarkerView_MouseDown(object sender, MouseEventArgs e)
{
Cell cell = MarkerView.CurrentCell;
if (cell == null || cell.RowIndex < 0 || cell.RowIndex >= Markers.Count) return;
if (cell.Column.Name != SAVESTATE_COL_NAME) return;

TasMovieMarker marker = Markers[cell.RowIndex.Value];
marker.WantsState = !marker.WantsState;
if (!marker.WantsState)
{
Tastudio.CurrentTasMovie.TasStateManager.Unreserve(marker.Frame - 1);
}
else if (Tastudio.Emulator.Frame == marker.Frame - 1)
{
Tastudio.CurrentTasMovie.TasStateManager.Capture(marker.Frame - 1, Tastudio.Emulator.AsStatable());
}
Tastudio.RefreshDialog();
}
}
}
1 change: 1 addition & 0 deletions src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public TAStudioSettings()
public int RewindStep { get; set; } = 1;
public int RewindStepFast { get; set; } = 4;
public bool ScrollSync { get; set; } = true;
public bool StatesForMarkers { get; set; } = true;
public PatternPaintModeEnum PatternPaintMode { get; set; } = TAStudioSettings.PatternPaintModeEnum.Never;
public PatternSelectionEnum PatternSelection { get; set; } = TAStudioSettings.PatternSelectionEnum.Hold;
public Font TasViewFont { get; set; } = new Font("Arial", 8.25F, FontStyle.Bold, GraphicsUnit.Point, 0);
Expand Down
Loading
Loading