mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 15:52:54 +08:00
Merge pull request #12531 from peppy/editor-add-nudge-shortcuts
Add simple key based time nudging support to editor
This commit is contained in:
commit
93b53f54fa
@ -42,6 +42,28 @@ namespace osu.Game.Tests.Visual.Editing
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestNudgeSelection()
|
||||||
|
{
|
||||||
|
HitCircle[] addedObjects = null;
|
||||||
|
|
||||||
|
AddStep("add hitobjects", () => EditorBeatmap.AddRange(addedObjects = new[]
|
||||||
|
{
|
||||||
|
new HitCircle { StartTime = 100 },
|
||||||
|
new HitCircle { StartTime = 200, Position = new Vector2(50) },
|
||||||
|
new HitCircle { StartTime = 300, Position = new Vector2(100) },
|
||||||
|
new HitCircle { StartTime = 400, Position = new Vector2(150) },
|
||||||
|
}));
|
||||||
|
|
||||||
|
AddStep("select objects", () => EditorBeatmap.SelectedHitObjects.AddRange(addedObjects));
|
||||||
|
|
||||||
|
AddStep("nudge forwards", () => InputManager.Key(Key.K));
|
||||||
|
AddAssert("objects moved forwards in time", () => addedObjects[0].StartTime > 100);
|
||||||
|
|
||||||
|
AddStep("nudge backwards", () => InputManager.Key(Key.J));
|
||||||
|
AddAssert("objects reverted to original position", () => addedObjects[0].StartTime == 100);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestBasicSelect()
|
public void TestBasicSelect()
|
||||||
{
|
{
|
||||||
|
@ -71,6 +71,8 @@ namespace osu.Game.Input.Bindings
|
|||||||
new KeyBinding(new[] { InputKey.F3 }, GlobalAction.EditorTimingMode),
|
new KeyBinding(new[] { InputKey.F3 }, GlobalAction.EditorTimingMode),
|
||||||
new KeyBinding(new[] { InputKey.F4 }, GlobalAction.EditorSetupMode),
|
new KeyBinding(new[] { InputKey.F4 }, GlobalAction.EditorSetupMode),
|
||||||
new KeyBinding(new[] { InputKey.Control, InputKey.Shift, InputKey.A }, GlobalAction.EditorVerifyMode),
|
new KeyBinding(new[] { InputKey.Control, InputKey.Shift, InputKey.A }, GlobalAction.EditorVerifyMode),
|
||||||
|
new KeyBinding(new[] { InputKey.J }, GlobalAction.EditorNudgeLeft),
|
||||||
|
new KeyBinding(new[] { InputKey.K }, GlobalAction.EditorNudgeRight),
|
||||||
};
|
};
|
||||||
|
|
||||||
public IEnumerable<KeyBinding> InGameKeyBindings => new[]
|
public IEnumerable<KeyBinding> InGameKeyBindings => new[]
|
||||||
@ -251,5 +253,11 @@ namespace osu.Game.Input.Bindings
|
|||||||
|
|
||||||
[Description("Verify mode")]
|
[Description("Verify mode")]
|
||||||
EditorVerifyMode,
|
EditorVerifyMode,
|
||||||
|
|
||||||
|
[Description("Nudge selection left")]
|
||||||
|
EditorNudgeLeft,
|
||||||
|
|
||||||
|
[Description("Nudge selection right")]
|
||||||
|
EditorNudgeRight
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -519,6 +519,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
// Apply the start time at the newly snapped-to position
|
// Apply the start time at the newly snapped-to position
|
||||||
double offset = result.Time.Value - movementBlueprints.First().HitObject.StartTime;
|
double offset = result.Time.Value - movementBlueprints.First().HitObject.StartTime;
|
||||||
|
|
||||||
|
if (offset != 0)
|
||||||
Beatmap.PerformOnSelection(obj => obj.StartTime += offset);
|
Beatmap.PerformOnSelection(obj => obj.StartTime += offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,9 +12,11 @@ using osu.Framework.Graphics.Colour;
|
|||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Primitives;
|
using osu.Framework.Graphics.Primitives;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Framework.Input.Bindings;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Input.Bindings;
|
||||||
using osu.Game.Rulesets.Edit;
|
using osu.Game.Rulesets.Edit;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
using osu.Game.Screens.Edit.Components.Timelines.Summary.Parts;
|
using osu.Game.Screens.Edit.Components.Timelines.Summary.Parts;
|
||||||
@ -237,10 +239,48 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class TimelineSelectionHandler : SelectionHandler
|
internal class TimelineSelectionHandler : SelectionHandler, IKeyBindingHandler<GlobalAction>
|
||||||
{
|
{
|
||||||
// for now we always allow movement. snapping is provided by the Timeline's "distance" snap implementation
|
// for now we always allow movement. snapping is provided by the Timeline's "distance" snap implementation
|
||||||
public override bool HandleMovement(MoveSelectionEvent moveEvent) => true;
|
public override bool HandleMovement(MoveSelectionEvent moveEvent) => true;
|
||||||
|
|
||||||
|
public bool OnPressed(GlobalAction action)
|
||||||
|
{
|
||||||
|
switch (action)
|
||||||
|
{
|
||||||
|
case GlobalAction.EditorNudgeLeft:
|
||||||
|
nudgeSelection(-1);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case GlobalAction.EditorNudgeRight:
|
||||||
|
nudgeSelection(1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnReleased(GlobalAction action)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Nudge the current selection by the specified multiple of beat divisor lengths,
|
||||||
|
/// based on the timing at the first object in the selection.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="amount">The direction and count of beat divisor lengths to adjust.</param>
|
||||||
|
private void nudgeSelection(int amount)
|
||||||
|
{
|
||||||
|
var selected = EditorBeatmap.SelectedHitObjects;
|
||||||
|
|
||||||
|
if (selected.Count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var timingPoint = EditorBeatmap.ControlPointInfo.TimingPointAt(selected.First().StartTime);
|
||||||
|
double adjustment = timingPoint.BeatLength / EditorBeatmap.BeatDivisor * amount;
|
||||||
|
|
||||||
|
EditorBeatmap.PerformOnSelection(h => h.StartTime += adjustment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TimelineDragBox : DragBox
|
private class TimelineDragBox : DragBox
|
||||||
|
Loading…
Reference in New Issue
Block a user