1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 10:52:53 +08:00

Add ability to seek between control points in editor using down/up arrows

Matches stable. Addresses #21376.
This commit is contained in:
Dean Herbert 2022-11-23 15:59:31 +09:00
parent 23f91ec717
commit 9b9b8a5977
2 changed files with 39 additions and 0 deletions

View File

@ -25,6 +25,7 @@ namespace osu.Game.Tests.Visual.Editing
beatmap.ControlPointInfo.Clear();
beatmap.ControlPointInfo.Add(0, new TimingControlPoint { BeatLength = 1000 });
beatmap.ControlPointInfo.Add(2000, new TimingControlPoint { BeatLength = 500 });
beatmap.ControlPointInfo.Add(20000, new TimingControlPoint { BeatLength = 500 });
return beatmap;
}
@ -116,6 +117,26 @@ namespace osu.Game.Tests.Visual.Editing
pressAndCheckTime(Key.Right, 3000);
}
[Test]
public void TestSeekBetweenControlPoints()
{
AddStep("seek to 0", () => EditorClock.Seek(0));
AddAssert("time is 0", () => EditorClock.CurrentTime == 0);
// already at first control point, noop
pressAndCheckTime(Key.Down, 0);
pressAndCheckTime(Key.Up, 2000);
pressAndCheckTime(Key.Up, 20000);
// at last control point, noop
pressAndCheckTime(Key.Up, 20000);
pressAndCheckTime(Key.Down, 2000);
pressAndCheckTime(Key.Down, 0);
pressAndCheckTime(Key.Down, 0);
}
private void pressAndCheckTime(Key key, double expectedTime)
{
AddStep($"press {key}", () => InputManager.Key(key));

View File

@ -499,6 +499,14 @@ namespace osu.Game.Screens.Edit
seek(e, 1);
return true;
case Key.Down:
seekControlPoint(-1);
return true;
case Key.Up:
seekControlPoint(1);
return true;
// Track traversal keys.
// Matching osu-stable implementations.
case Key.Z:
@ -892,6 +900,16 @@ namespace osu.Game.Screens.Edit
}
}
private void seekControlPoint(int direction)
{
var found = direction < 1
? editorBeatmap.ControlPointInfo.AllControlPoints.LastOrDefault(p => p.Time < clock.CurrentTime)
: editorBeatmap.ControlPointInfo.AllControlPoints.FirstOrDefault(p => p.Time > clock.CurrentTime);
if (found != null)
clock.Seek(found.Time);
}
private void seek(UIEvent e, int direction)
{
double amount = e.ShiftPressed ? 4 : 1;