Fix volume controls not supporting key repeat

This commit is contained in:
Dean Herbert
2021-04-14 13:10:45 +09:00
parent d076be82a5
commit 8282f38eb7
2 changed files with 32 additions and 8 deletions

View File

@ -6,6 +6,8 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Threading;
using osu.Game.Extensions;
using osu.Game.Input.Bindings;
namespace osu.Game.Overlays.Volume
@ -15,8 +17,30 @@ namespace osu.Game.Overlays.Volume
public Func<GlobalAction, bool> ActionRequested;
public Func<GlobalAction, float, bool, bool> ScrollActionRequested;
public bool OnPressed(GlobalAction action) =>
ActionRequested?.Invoke(action) ?? false;
private ScheduledDelegate keyRepeat;
public bool OnPressed(GlobalAction action)
{
switch (action)
{
case GlobalAction.DecreaseVolume:
case GlobalAction.IncreaseVolume:
keyRepeat?.Cancel();
keyRepeat = this.BeginKeyRepeat(Scheduler, () => ActionRequested?.Invoke(action), 150);
return true;
case GlobalAction.ToggleMute:
ActionRequested?.Invoke(action);
return true;
}
return false;
}
public void OnReleased(GlobalAction action)
{
keyRepeat?.Cancel();
}
protected override bool OnScroll(ScrollEvent e)
{
@ -27,9 +51,5 @@ namespace osu.Game.Overlays.Volume
public bool OnScroll(GlobalAction action, float amount, bool isPrecise) =>
ScrollActionRequested?.Invoke(action, amount, isPrecise) ?? false;
public void OnReleased(GlobalAction action)
{
}
}
}