mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 23:12:56 +08:00
Add SelectNext and SelectPrevious global actions
This commit is contained in:
parent
ee73f3e2b2
commit
489bf16bea
@ -39,6 +39,9 @@ namespace osu.Game.Input.Bindings
|
||||
new KeyBinding(InputKey.Escape, GlobalAction.Back),
|
||||
new KeyBinding(InputKey.ExtraMouseButton1, GlobalAction.Back),
|
||||
|
||||
new KeyBinding(InputKey.Up, GlobalAction.SelectPrevious),
|
||||
new KeyBinding(InputKey.Down, GlobalAction.SelectNext),
|
||||
|
||||
new KeyBinding(InputKey.Space, GlobalAction.Select),
|
||||
new KeyBinding(InputKey.Enter, GlobalAction.Select),
|
||||
new KeyBinding(InputKey.KeypadEnter, GlobalAction.Select),
|
||||
@ -142,5 +145,11 @@ namespace osu.Game.Input.Bindings
|
||||
|
||||
[Description("Toggle now playing overlay")]
|
||||
ToggleNowPlaying,
|
||||
|
||||
[Description("Previous Selection")]
|
||||
SelectPrevious,
|
||||
|
||||
[Description("Next Selection")]
|
||||
SelectNext,
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ using osu.Game.Graphics;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osuTK.Input;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Input.Bindings;
|
||||
@ -204,35 +203,24 @@ namespace osu.Game.Screens.Play
|
||||
InternalButtons[selectionIndex].Selected.Value = true;
|
||||
}
|
||||
|
||||
protected override bool OnKeyDown(KeyDownEvent e)
|
||||
{
|
||||
if (!e.Repeat)
|
||||
{
|
||||
switch (e.Key)
|
||||
{
|
||||
case Key.Up:
|
||||
if (selectionIndex == -1 || selectionIndex == 0)
|
||||
setSelected(InternalButtons.Count - 1);
|
||||
else
|
||||
setSelected(selectionIndex - 1);
|
||||
return true;
|
||||
|
||||
case Key.Down:
|
||||
if (selectionIndex == -1 || selectionIndex == InternalButtons.Count - 1)
|
||||
setSelected(0);
|
||||
else
|
||||
setSelected(selectionIndex + 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return base.OnKeyDown(e);
|
||||
}
|
||||
|
||||
public bool OnPressed(GlobalAction action)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case GlobalAction.SelectPrevious:
|
||||
if (selectionIndex == -1 || selectionIndex == 0)
|
||||
setSelected(InternalButtons.Count - 1);
|
||||
else
|
||||
setSelected(selectionIndex - 1);
|
||||
return true;
|
||||
|
||||
case GlobalAction.SelectNext:
|
||||
if (selectionIndex == -1 || selectionIndex == InternalButtons.Count - 1)
|
||||
setSelected(0);
|
||||
else
|
||||
setSelected(selectionIndex + 1);
|
||||
return true;
|
||||
|
||||
case GlobalAction.Back:
|
||||
BackAction.Invoke();
|
||||
return true;
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user