mirror of
https://github.com/ppy/osu
synced 2024-12-15 03:16:17 +00:00
Add debouncing to hover sounds (#6982)
Add debouncing to hover sounds Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
commit
aee32a4ebe
@ -1,4 +1,4 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Linq;
|
||||
|
@ -9,6 +9,7 @@ using osu.Framework.Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Threading;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
@ -20,6 +21,11 @@ namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
private SampleChannel sampleHover;
|
||||
|
||||
/// <summary>
|
||||
/// Length of debounce for hover sound playback, in milliseconds. Default is 50ms.
|
||||
/// </summary>
|
||||
public double HoverDebounceTime { get; set; } = 50;
|
||||
|
||||
protected readonly HoverSampleSet SampleSet;
|
||||
|
||||
public HoverSounds(HoverSampleSet sampleSet = HoverSampleSet.Normal)
|
||||
@ -28,9 +34,17 @@ namespace osu.Game.Graphics.UserInterface
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
}
|
||||
|
||||
private ScheduledDelegate playDelegate;
|
||||
|
||||
protected override bool OnHover(HoverEvent e)
|
||||
{
|
||||
sampleHover?.Play();
|
||||
playDelegate?.Cancel();
|
||||
|
||||
if (HoverDebounceTime <= 0)
|
||||
sampleHover?.Play();
|
||||
else
|
||||
playDelegate = Scheduler.AddDelayed(() => sampleHover?.Play(), HoverDebounceTime);
|
||||
|
||||
return base.OnHover(e);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user