1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-17 05:52:36 +08: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:
Dean Herbert
2019-11-28 21:05:41 +09:00
committed by GitHub
Unverified
2 changed files with 16 additions and 2 deletions
@@ -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;
+15 -1
View File
@@ -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);
}