Handle back action in `OsuDropdown` rather than menu

This commit is contained in:
Salman Ahmed 2023-12-05 22:45:46 +03:00
parent a0813d18ca
commit b8b82f8901
1 changed files with 16 additions and 19 deletions

View File

@ -22,7 +22,7 @@
namespace osu.Game.Graphics.UserInterface
{
public partial class OsuDropdown<T> : Dropdown<T>
public partial class OsuDropdown<T> : Dropdown<T>, IKeyBindingHandler<GlobalAction>
{
private const float corner_radius = 5;
@ -30,9 +30,23 @@ public partial class OsuDropdown<T> : Dropdown<T>
protected override DropdownMenu CreateMenu() => new OsuDropdownMenu();
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
if (e.Repeat) return false;
if (e.Action == GlobalAction.Back)
return Back();
return false;
}
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
{
}
#region OsuDropdownMenu
protected partial class OsuDropdownMenu : DropdownMenu, IKeyBindingHandler<GlobalAction>
protected partial class OsuDropdownMenu : DropdownMenu
{
public override bool HandleNonPositionalInput => State == MenuState.Open;
@ -276,23 +290,6 @@ public bool Hovering
}
#endregion
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
if (e.Repeat) return false;
if (e.Action == GlobalAction.Back)
{
State = MenuState.Closed;
return true;
}
return false;
}
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
{
}
}
#endregion