Skip to content

Commit

Permalink
Merge pull request ppy#29860 from bdach/fix-nudging
Browse files Browse the repository at this point in the history
 Only allow seek to next/previous object via keybinding if there is no selection
  • Loading branch information
peppy authored Oct 7, 2024
2 parents 77f3270 + 7f71ef4 commit 5c826be
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 3 deletions.
48 changes: 47 additions & 1 deletion osu.Game.Tests/Visual/Editing/TestSceneComposerSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets;
Expand Down Expand Up @@ -82,7 +83,7 @@ public void TestSelectAndShowContextMenuOutsideBounds()
}

[Test]
public void TestNudgeSelection()
public void TestNudgeSelectionTime()
{
HitCircle[] addedObjects = null!;

Expand All @@ -103,6 +104,51 @@ public void TestNudgeSelection()
AddAssert("objects reverted to original position", () => addedObjects[0].StartTime == 100);
}

[Test]
public void TestNudgeSelectionPosition()
{
HitCircle addedObject = null!;

AddStep("add hitobjects", () => EditorBeatmap.AddRange(new[]
{
addedObject = new HitCircle { StartTime = 200, Position = new Vector2(100) },
}));

AddStep("select object", () => EditorBeatmap.SelectedHitObjects.Add(addedObject));

AddStep("nudge up", () =>
{
InputManager.PressKey(Key.ControlLeft);
InputManager.Key(Key.Up);
InputManager.ReleaseKey(Key.ControlLeft);
});
AddAssert("object position moved up", () => addedObject.Position.Y, () => Is.EqualTo(99).Within(Precision.FLOAT_EPSILON));

AddStep("nudge down", () =>
{
InputManager.PressKey(Key.ControlLeft);
InputManager.Key(Key.Down);
InputManager.ReleaseKey(Key.ControlLeft);
});
AddAssert("object position moved down", () => addedObject.Position.Y, () => Is.EqualTo(100).Within(Precision.FLOAT_EPSILON));

AddStep("nudge left", () =>
{
InputManager.PressKey(Key.ControlLeft);
InputManager.Key(Key.Left);
InputManager.ReleaseKey(Key.ControlLeft);
});
AddAssert("object position moved left", () => addedObject.Position.X, () => Is.EqualTo(99).Within(Precision.FLOAT_EPSILON));

AddStep("nudge right", () =>
{
InputManager.PressKey(Key.ControlLeft);
InputManager.Key(Key.Right);
InputManager.ReleaseKey(Key.ControlLeft);
});
AddAssert("object position moved right", () => addedObject.Position.X, () => Is.EqualTo(100).Within(Precision.FLOAT_EPSILON));
}

[Test]
public void TestRotateHotkeys()
{
Expand Down
39 changes: 37 additions & 2 deletions osu.Game.Tests/Visual/Editing/TestSceneEditorSeeking.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Linq;
using NUnit.Framework;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Objects;
using osuTK.Input;

namespace osu.Game.Tests.Visual.Editing
Expand Down Expand Up @@ -135,9 +137,42 @@ public void TestSeekBetweenControlPoints()
pressAndCheckTime(Key.Up, 0);
}

private void pressAndCheckTime(Key key, double expectedTime)
[Test]
public void TestSeekBetweenObjects()
{
AddStep("add objects", () =>
{
EditorBeatmap.Clear();
EditorBeatmap.AddRange(new[]
{
new HitCircle { StartTime = 1000, },
new HitCircle { StartTime = 2250, },
new HitCircle { StartTime = 3600, },
});
});
AddStep("seek to 0", () => EditorClock.Seek(0));

pressAndCheckTime(Key.Right, 1000, Key.ControlLeft);
pressAndCheckTime(Key.Right, 2250, Key.ControlLeft);
pressAndCheckTime(Key.Right, 3600, Key.ControlLeft);
pressAndCheckTime(Key.Right, 3600, Key.ControlLeft);
pressAndCheckTime(Key.Left, 2250, Key.ControlLeft);
pressAndCheckTime(Key.Left, 1000, Key.ControlLeft);
pressAndCheckTime(Key.Left, 1000, Key.ControlLeft);
}

private void pressAndCheckTime(Key key, double expectedTime, params Key[] modifiers)
{
AddStep($"press {key}", () => InputManager.Key(key));
AddStep($"press {key} with {(modifiers.Any() ? string.Join(',', modifiers) : "no modifiers")}", () =>
{
foreach (var modifier in modifiers)
InputManager.PressKey(modifier);
InputManager.Key(key);
foreach (var modifier in modifiers)
InputManager.ReleaseKey(modifier);
});
AddUntilStep($"time is {expectedTime}", () => EditorClock.CurrentTime, () => Is.EqualTo(expectedTime).Within(1));
}
}
Expand Down
6 changes: 6 additions & 0 deletions osu.Game/Screens/Edit/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -721,10 +721,16 @@ public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
switch (e.Action)
{
case GlobalAction.EditorSeekToPreviousHitObject:
if (editorBeatmap.SelectedHitObjects.Any())
return false;

seekHitObject(-1);
return true;

case GlobalAction.EditorSeekToNextHitObject:
if (editorBeatmap.SelectedHitObjects.Any())
return false;

seekHitObject(1);
return true;

Expand Down

0 comments on commit 5c826be

Please sign in to comment.