Add support for keyboard seeking in the editor

This commit is contained in:
Dean Herbert 2018-11-30 14:57:25 +09:00
parent 02ef187c04
commit 0ee5a5bdb4
2 changed files with 53 additions and 25 deletions

View File

@ -20,6 +20,7 @@ using osu.Game.Screens.Edit.Components;
using osu.Game.Screens.Edit.Components.Menus;
using osu.Game.Screens.Edit.Compose;
using osu.Game.Screens.Edit.Design;
using osuTK.Input;
namespace osu.Game.Screens.Edit
{
@ -157,29 +158,19 @@ namespace osu.Game.Screens.Edit
bottomBackground.Colour = colours.Gray2;
}
private void exportBeatmap()
protected override bool OnKeyDown(KeyDownEvent e)
{
host.OpenFileExternally(Beatmap.Value.Save());
}
private void onModeChanged(EditorScreenMode mode)
{
currentScreen?.Exit();
switch (mode)
switch (e.Key)
{
case EditorScreenMode.Compose:
currentScreen = new ComposeScreen();
break;
case EditorScreenMode.Design:
currentScreen = new DesignScreen();
break;
default:
currentScreen = new EditorScreen();
break;
case Key.Left:
seek(-1);
return true;
case Key.Right:
seek(1);
return true;
}
LoadComponentAsync(currentScreen, screenContainer.Add);
return base.OnKeyDown(e);
}
private double scrollAccumulation;
@ -193,9 +184,9 @@ namespace osu.Game.Screens.Edit
while (Math.Abs(scrollAccumulation) > precision)
{
if (scrollAccumulation > 0)
clock.SeekBackward(!clock.IsRunning);
seek(-1);
else
clock.SeekForward(!clock.IsRunning);
seek(1);
scrollAccumulation = scrollAccumulation < 0 ? Math.Min(0, scrollAccumulation + precision) : Math.Max(0, scrollAccumulation - precision);
}
@ -224,7 +215,40 @@ namespace osu.Game.Screens.Edit
Beatmap.Value.Track.Tempo.Value = 1;
Beatmap.Value.Track.Start();
}
return base.OnExiting(next);
}
private void exportBeatmap() => host.OpenFileExternally(Beatmap.Value.Save());
private void onModeChanged(EditorScreenMode mode)
{
currentScreen?.Exit();
switch (mode)
{
case EditorScreenMode.Compose:
currentScreen = new ComposeScreen();
break;
case EditorScreenMode.Design:
currentScreen = new DesignScreen();
break;
default:
currentScreen = new EditorScreen();
break;
}
LoadComponentAsync(currentScreen, screenContainer.Add);
}
private void seek(int direction)
{
double amount = GetContainingInputManager().CurrentState.Keyboard.ShiftPressed ? 2 : 1;
if (direction < 1)
clock.SeekBackward(!clock.IsRunning, amount);
else
clock.SeekForward(!clock.IsRunning, amount);
}
}
}

View File

@ -68,16 +68,20 @@ namespace osu.Game.Screens.Edit
/// Seeks backwards by one beat length.
/// </summary>
/// <param name="snapped">Whether to snap to the closest beat after seeking.</param>
public void SeekBackward(bool snapped = false) => seek(-1, snapped);
/// <param name="amount">The relative amount (magnitude) which should be seeked.</param>
public void SeekBackward(bool snapped = false, double amount = 1) => seek(-1, snapped, amount);
/// <summary>
/// Seeks forwards by one beat length.
/// </summary>
/// <param name="snapped">Whether to snap to the closest beat after seeking.</param>
public void SeekForward(bool snapped = false) => seek(1, snapped);
/// <param name="amount">The relative amount (magnitude) which should be seeked.</param>
public void SeekForward(bool snapped = false, double amount = 1) => seek(1, snapped, amount);
private void seek(int direction, bool snapped)
private void seek(int direction, bool snapped, double amount = 1)
{
if (amount <= 0) throw new ArgumentException("Value should be greater than zero", nameof(amount));
var timingPoint = ControlPointInfo.TimingPointAt(CurrentTime);
if (direction < 0 && timingPoint.Time == CurrentTime)
{
@ -87,7 +91,7 @@ namespace osu.Game.Screens.Edit
timingPoint = ControlPointInfo.TimingPoints[--activeIndex];
}
double seekAmount = timingPoint.BeatLength / beatDivisor;
double seekAmount = timingPoint.BeatLength / beatDivisor * amount;
double seekTime = CurrentTime + seekAmount * direction;
if (!snapped || ControlPointInfo.TimingPoints.Count == 0)