Add SelectNext and SelectPrevious global actions

This commit is contained in:
Dean Herbert
2020-03-02 18:55:28 +09:00
parent ee73f3e2b2
commit 489bf16bea
3 changed files with 50 additions and 54 deletions

View File

@ -16,15 +16,17 @@ using osu.Framework.Bindables;
using osu.Framework.Caching;
using osu.Framework.Threading;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Cursor;
using osu.Game.Input.Bindings;
using osu.Game.Screens.Select.Carousel;
namespace osu.Game.Screens.Select
{
public class BeatmapCarousel : CompositeDrawable
public class BeatmapCarousel : CompositeDrawable, IKeyBindingHandler<GlobalAction>
{
private const float bleed_top = FilterControl.HEIGHT;
private const float bleed_bottom = Footer.HEIGHT;
@ -435,41 +437,38 @@ namespace osu.Game.Screens.Select
protected override bool OnKeyDown(KeyDownEvent e)
{
// allow for controlling volume when alt is held.
// this is required as the VolumeControlReceptor uses OnPressed, which is
// executed after all OnKeyDown events.
if (e.AltPressed)
return base.OnKeyDown(e);
int direction = 0;
bool skipDifficulties = false;
switch (e.Key)
{
case Key.Up:
direction = -1;
break;
case Key.Down:
direction = 1;
break;
case Key.Left:
direction = -1;
skipDifficulties = true;
break;
SelectNext(-1, true);
return true;
case Key.Right:
direction = 1;
skipDifficulties = true;
break;
SelectNext(1, true);
return true;
}
if (direction == 0)
return base.OnKeyDown(e);
return false;
}
SelectNext(direction, skipDifficulties);
return true;
public bool OnPressed(GlobalAction action)
{
switch (action)
{
case GlobalAction.SelectNext:
SelectNext(1, false);
return true;
case GlobalAction.SelectPrevious:
SelectNext(-1, false);
return true;
}
return false;
}
public void OnReleased(GlobalAction action)
{
}
protected override void Update()