Skip to content

Commit

Permalink
overshoot navigation: add overshooting for history navigation
Browse files Browse the repository at this point in the history
- makes it a bit less jarring when jumping around all over the place
- decrease defaults from 20 to 10
- allow overshooting when moving backwards too (previously only worked moving forwards)
  • Loading branch information
binary1230 committed Dec 1, 2024
1 parent 8ac3d14 commit ce2b268
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ public class HistoryArgs
/// <param name="pcOffset">PC [not SNES] offset</param>
/// <param name="historyArgs">if non-null, record this event in the project history</param>
void SelectOffset(int pcOffset, HistoryArgs historyArgs = null);
void SelectOffsetWithOvershoot(int pcOffset, int overshootAmount = 0);
}
}
24 changes: 14 additions & 10 deletions DiztinGUIsh/window/MainWindow.Actions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using Diz.Controllers.controllers;
Expand All @@ -9,12 +8,17 @@
using Diz.Core.util;
using Diz.Cpu._65816;
using Diz.Ui.Winforms.dialogs;
using DiztinGUIsh.Properties;

namespace DiztinGUIsh.window;

public partial class MainWindow
{
// when navigating near the edge of the grid, this controls how close we'll allow getting to the bottom row before
// scrolling the screen a bit (because it's helpful to be able to see where you're going and not always be operating on
// the edge of the grid)
// arbitrary: increase if using bigger grid sizes. ideally, this would be dynamically generated in the future based on a % of the grid
private const int standardOvershootAmount = 12;

private void OpenLastProject()
{
if (Document.LastProjectFilename == "")
Expand Down Expand Up @@ -86,7 +90,7 @@ private void Step(int offset)

ProjectController.MarkChanged();
var newOffset = snesData.Step(offset, false, false, offset - 1);
SelectOffset(newOffset, -1, new ISnesNavigation.HistoryArgs {Description = "Step Over"}, overshootAmount: 20);
SelectOffset(newOffset, -1, new ISnesNavigation.HistoryArgs {Description = "Step Over"}, overshootAmount: standardOvershootAmount);
UpdateUi_TimerAndPercent();
}

Expand All @@ -97,7 +101,7 @@ private void StepIn(int offset)

ProjectController.MarkChanged();
var newOffset = Project.Data.GetSnesApi().Step(offset, true, false, offset - 1);
SelectOffset(newOffset, -1, new ISnesNavigation.HistoryArgs {Description = "Step Into"}, overshootAmount: 20);
SelectOffset(newOffset, -1, new ISnesNavigation.HistoryArgs {Description = "Step Into"}, overshootAmount: standardOvershootAmount);
UpdateUi_TimerAndPercent();
}

Expand All @@ -109,7 +113,7 @@ private void AutoStepSafe(int offset)
ProjectController.MarkChanged();
var destination = Project.Data.GetSnesApi().AutoStepSafe(offset);
if (moveWithStep)
SelectOffset(destination, -1, new ISnesNavigation.HistoryArgs {Description = "AutoStep (Safe)"}, overshootAmount: 20);
SelectOffset(destination, -1, new ISnesNavigation.HistoryArgs {Description = "AutoStep (Safe)"}, overshootAmount: standardOvershootAmount);

UpdateUi_TimerAndPercent();
}
Expand All @@ -126,7 +130,7 @@ private void AutoStepHarsh(int offset)
var destination = Project.Data.GetSnesApi().AutoStepHarsh(newOffset, count);

if (moveWithStep)
SelectOffset(destination, -1, new ISnesNavigation.HistoryArgs {Description = "AutoStep (Harsh)"}, overshootAmount:20);
SelectOffset(destination, -1, new ISnesNavigation.HistoryArgs {Description = "AutoStep (Harsh)"}, overshootAmount: standardOvershootAmount);

UpdateUi_TimerAndPercent();
}
Expand All @@ -139,7 +143,7 @@ private void Mark(int offset)
ProjectController.MarkChanged();
var newOffset = Project.Data.GetSnesApi().MarkTypeFlag(offset, markFlag, RomUtil.GetByteLengthForFlag(markFlag));

SelectOffset(newOffset, -1, new ISnesNavigation.HistoryArgs {Description = "Mark (single)"}, overshootAmount: 20);
SelectOffset(newOffset, -1, new ISnesNavigation.HistoryArgs {Description = "Mark (single)"}, overshootAmount: standardOvershootAmount);

UpdateUi_TimerAndPercent();
}
Expand Down Expand Up @@ -193,7 +197,7 @@ private void GoToIntermediateAddress(int offset)
public void GoTo(int offset)
{
if (IsOffsetInRange(offset))
SelectOffset(offset, -1, new ISnesNavigation.HistoryArgs {Description = "Goto"}, overshootAmount: 20);
SelectOffset(offset, -1, new ISnesNavigation.HistoryArgs {Description = "Goto"}, overshootAmount: standardOvershootAmount);
else
ShowOffsetOutOfRangeMsg();
}
Expand Down Expand Up @@ -263,7 +267,7 @@ private void GoToNextUnreachedInPoint(int offset)
}

// now do the real thing
SelectOffset(foundOffset, -1, new ISnesNavigation.HistoryArgs { Description = "Find next unreached in-point" }, overshootAmount: 20);
SelectOffset(foundOffset, -1, new ISnesNavigation.HistoryArgs { Description = "Find next unreached in-point" }, overshootAmount: standardOvershootAmount);
}

private static ISnesNavigation.HistoryArgs BuildUnreachedHistoryArgs(bool fromStartOrEnd, bool forwardDirection)
Expand Down
19 changes: 18 additions & 1 deletion DiztinGUIsh/window/MainWindow.MainTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,9 @@ public void MarkHistoryPoint(int pcOffset, ISnesNavigation.HistoryArgs historyAr
RememberNavigationPoint(SelectedOffset, historyArgs); // save old position
}

public void SelectOffsetWithOvershoot(int pcOffset, int overshootAmount = 0)
=> SelectOffset(pcOffset, -1, null, overshootAmount);

public void SelectOffset(int pcOffset, ISnesNavigation.HistoryArgs historyArgs = null)
=> SelectOffset(pcOffset, -1, historyArgs);

Expand All @@ -487,10 +490,24 @@ public void SelectOffset(int pcOffset, int column = -1, ISnesNavigation.HistoryA
// THIS IS 100% OPTIONAL.
if (overshootAmount > 0)
{
// NEW
// which way are we jumping?
var direction = SelectedOffset < pcOffset ? 1 : -1;

// ideally, we'd calculate this number to be at the center or top. for now, we'll just pick an arbitrary amount
var overshotOffset = Math.Min(Project.Data.GetRomSize()-1, pcOffset + overshootAmount);
var proposedNewOffset = pcOffset + overshootAmount * direction; // note: may be out of range

// clamp to actual range
var overshotOffset = Util.Clamp(proposedNewOffset, 0, Project.Data.GetRomSize() - 1);
InternalSelectOffset(overshotOffset, column);

// ----

// ORIGINAL
// ideally, we'd calculate this number to be at the center or top. for now, we'll just pick an arbitrary amount
// var overshotOffset = Math.Min(Project.Data.GetRomSize()-1, pcOffset + overshootAmount);
// InternalSelectOffset(overshotOffset, column);

// now, the view is scrolled so we've overshot where we really want to go.
// when we next call InternalSelectOffset() with the real address, it won't need to scroll, it'll just select something already in view.
}
Expand Down
8 changes: 6 additions & 2 deletions DiztinGUIsh/window/MainWindow.SimpleUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,14 @@ private void showHistoryToolStripMenuItem_Click(object sender, EventArgs e)
}

private void goBackToolStripMenuItem_Click(object sender, EventArgs e) =>
NavigationForm.Navigate(forwardDirection: false);
NavigationForm.Navigate(forwardDirection: false,
overshootAmount: standardOvershootAmount
);

private void goForwardToolStripMenuItem_Click(object sender, EventArgs e) =>
NavigationForm.Navigate(forwardDirection: true);
NavigationForm.Navigate(forwardDirection: true,
overshootAmount: standardOvershootAmount
);

private void LabelsOnOnLabelChanged(object? sender, EventArgs e)
{
Expand Down
4 changes: 2 additions & 2 deletions DiztinGUIsh/window/NavigationForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ private void Navigation_Load(object sender, EventArgs e)

}

public void Navigate(bool forwardDirection)
public void Navigate(bool forwardDirection, int overshootAmount = 0)
{
navigationCtrl.Navigate(forwardDirection);
navigationCtrl.Navigate(forwardDirection, overshootAmount);
}

private void navigationCtrl_Load(object sender, EventArgs e)
Expand Down
12 changes: 6 additions & 6 deletions DiztinGUIsh/window/usercontrols/NavigationUserControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public NavigationUserControl()

public int SelectedIndex => navigationEntryBindingSource.Position; // dataGridView1.SelectedRows[0].Index;

public void Navigate(bool forwardDirection)
public void Navigate(bool forwardDirection, int overshootAmount = 0)
{
if (navigationEntryBindingSource == null || navigationEntryBindingSource.Count == 0)
return;
Expand All @@ -70,16 +70,16 @@ public void Navigate(bool forwardDirection)
Util.ClampIndex(SelectedIndex + (forwardDirection ? 1 : -1),
navigationEntryBindingSource.Count);

NavigateToEntry(navigationEntryToUse);
NavigateToEntry(navigationEntryToUse, overshootAmount);
SelectDataGridRow(navigationEntryToUse);
}

private void NavigateToEntry(int indexToUse)
private void NavigateToEntry(int indexToUse, int overshootAmount = 0)
{
NavigateToEntry(GetNavigationEntry(indexToUse));
NavigateToEntry(GetNavigationEntry(indexToUse), overshootAmount);
}

private void NavigateToEntry(NavigationEntry navigationEntry)
private void NavigateToEntry(NavigationEntry navigationEntry, int overshootAmount = 0)
{
var newSnesAddress = navigationEntry?.SnesOffset ?? -1;
if (newSnesAddress == -1)
Expand All @@ -89,7 +89,7 @@ private void NavigateToEntry(NavigationEntry navigationEntry)
if (pcOffset == -1)
return;

SnesNavigation.SelectOffset(pcOffset);
SnesNavigation.SelectOffsetWithOvershoot(pcOffset, overshootAmount);
}

private NavigationEntry GetNavigationEntry(int index)
Expand Down

0 comments on commit ce2b268

Please sign in to comment.