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
20 changes: 18 additions & 2 deletions src/BizHawk.Client.Common/movie/tasproj/TasMovie.History.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ public interface IMovieChangeLog
/// <summary>
/// Undoes the most recent action batch, if any exist.
/// </summary>
void Undo();
/// <param name="untilId">If given, as many actions will be undone as needed to make the action
/// of the given ID the most recent action. The action with the given ID will not be undone.
/// </param>
void Undo(int? untilId = null);

/// <summary>
/// Redoes the most recent undo, if any exist.
Expand Down Expand Up @@ -248,13 +251,26 @@ public bool MergeActions(int action1, int action2)
return true;
}

public void Undo()
public void Undo(int? untilId = null)
{
if (UndoIndex == -1)
{
return;
}

if (untilId != null)
{
int id = untilId.Value;
_movie.SingleInvalidation(() =>
{
while (UndoIndex >= 0 && id < _history[UndoIndex].id)
{
Undo();
}
});
return;
}

List<IMovieAction> batch = _history[UndoIndex].actions;
UndoIndex--;

Expand Down
4 changes: 2 additions & 2 deletions src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/Cell.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#nullable enable

using System.Collections.Generic;
using System.Diagnostics;

using BizHawk.Common;
using BizHawk.Common.CollectionExtensions;
Expand Down Expand Up @@ -106,7 +105,8 @@ public override void Add(Cell item)
var i = _list.BinarySearch(item);
if (i >= 0)
{
Debug.Assert(false, $"{nameof(CellList)}'s distinctness invariant was almost broken! CellList.Add({(item is null ? "null" : item.ToString())})");
// We can end up adding cells that are already selected pretty easily, by combining Alt multi-selection with Shift range-selection.
// System.Diagnostics.Debug.Assert(false, $"{nameof(CellList)}'s distinctness invariant was almost broken! CellList.Add({(item is null ? "null" : item.ToString())})");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦
Fix the offending selection code. The usual selection actions respect the invariant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The offending selection code would, if "fixed", simply check if the cell was already selected prior to selecting it. There is no other way to do it. That doesn't seem any better, and I don't see any reason to but that burden on users of InputRoll or CellList. In terms of performance, that could easily be worse since users of InputRoll aren't going to perform that check with a binary search.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And to be clear, this change isn't related to axis editing. But I wanted it to stop nagging me while I was testing things.

return;
}
_list.Insert(~i, item);
Expand Down
46 changes: 36 additions & 10 deletions src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/InputRoll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,12 @@ public int HoverInterval
[Category("Virtual")]
public event QueryFrameLagHandler QueryFrameLag;

/// <summary>
/// Fires when a cell that can be selected is clicked. Return null to use default selection logic.
/// </summary>
[Category("Mouse")]
public event QueryShouldSelectCellHandler QueryShouldSelectCell;

/// <summary>
/// Fires when the mouse moves from one cell to another (including column header cells)
/// </summary>
Expand Down Expand Up @@ -502,6 +508,11 @@ public int HoverInterval
/// </summary>
public delegate bool QueryFrameLagHandler(int index, bool hideWasLag);

/// <summary>
/// Check if clicking the current cell should select it.
/// </summary>
public delegate bool? QueryShouldSelectCellHandler(MouseButtons button);

public delegate void CellChangeEventHandler(object sender, CellEventArgs e);

public delegate void HoverEventHandler(object sender, CellEventArgs e);
Expand Down Expand Up @@ -1115,7 +1126,6 @@ protected override void OnMouseLeave(EventArgs e)
base.OnMouseLeave(e);
}

// TODO add query callback of whether to select the cell or not
protected override void OnMouseDown(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
Expand All @@ -1140,17 +1150,37 @@ protected override void OnMouseDown(MouseEventArgs e)
{
RightButtonHeld = true;
}

// In the case that we have a context menu already open, we must manually update the CurrentCell as MouseMove isn't triggered while it is open.
if (AllowRightClickSelection && CurrentCell == null)
OnMouseMove(e);
}

bool shouldSelect = false;
bool useDefaultSelection = true;
if (IsHoveringOnDataCell)
{
if (QueryShouldSelectCell != null)
{
bool? result = QueryShouldSelectCell(e.Button);
shouldSelect = result != false;
useDefaultSelection = result == null;
}
else
{
shouldSelect = true;
}
}

if (e.Button == MouseButtons.Left)
{
if (IsHoveringOnDataCell)
if (shouldSelect)
{
if (ModifierKeys == Keys.Alt)
{
// do marker drag here
}
else if (ModifierKeys is Keys.Shift && CurrentCell.Column! is { Type: ColumnType.Text } col)
else if (ModifierKeys is Keys.Shift && (!useDefaultSelection || CurrentCell.Column!.Type is ColumnType.Text))
{
if (_selectedItems.Count is not 0)
{
Expand Down Expand Up @@ -1182,7 +1212,7 @@ protected override void OnMouseDown(MouseEventArgs e)
additionEndExcl = targetRow + 1;
}
}
for (var i = additionStart; i < additionEndExcl; i++) SelectCell(new() { RowIndex = i, Column = col });
for (var i = additionStart; i < additionEndExcl; i++) SelectCell(new() { RowIndex = i, Column = CurrentCell.Column });
}
}
else
Expand All @@ -1195,7 +1225,7 @@ protected override void OnMouseDown(MouseEventArgs e)
SelectCell(CurrentCell);
}
}
else if (ModifierKeys is Keys.Control && CurrentCell.Column!.Type is ColumnType.Text)
else if (ModifierKeys is Keys.Control && (!useDefaultSelection || CurrentCell.Column!.Type is ColumnType.Text))
{
SelectCell(CurrentCell, toggle: true);
}
Expand All @@ -1213,11 +1243,7 @@ protected override void OnMouseDown(MouseEventArgs e)

if (AllowRightClickSelection && e.Button == MouseButtons.Right)
{
// In the case that we have a context menu already open, we must manually update the CurrentCell as MouseMove isn't triggered while it is open.
if (CurrentCell == null)
OnMouseMove(e);

if (!IsHoveringOnColumnCell)
if (shouldSelect)
{
// If this cell is not currently selected, clear and select
if (!_selectedItems.Contains(CurrentCell))
Expand Down
Loading