2021-02-12 03:14:49 +00:00
|
|
|
// 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.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2021-02-12 03:14:49 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2023-02-03 08:29:25 +00:00
|
|
|
using osu.Framework.Graphics;
|
2021-02-12 03:14:49 +00:00
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Game.Configuration;
|
2023-02-03 07:45:54 +00:00
|
|
|
using osuTK;
|
2021-02-12 03:14:49 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Handles debouncing hover sounds at a global level to ensure the effects are not overwhelming.
|
|
|
|
/// </summary>
|
2023-02-03 08:29:25 +00:00
|
|
|
public abstract partial class HoverSampleDebounceComponent : Component
|
2021-02-12 03:14:49 +00:00
|
|
|
{
|
|
|
|
private Bindable<double?> lastPlaybackTime;
|
|
|
|
|
2023-02-05 03:58:48 +00:00
|
|
|
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Parent?.ReceivePositionalInputAt(screenSpacePos) == true;
|
2023-02-03 07:45:54 +00:00
|
|
|
|
2021-02-12 03:14:49 +00:00
|
|
|
[BackgroundDependencyLoader]
|
2022-01-15 00:06:39 +00:00
|
|
|
private void load(SessionStatics statics)
|
2021-02-12 03:14:49 +00:00
|
|
|
{
|
|
|
|
lastPlaybackTime = statics.GetBindable<double?>(Static.LastHoverSoundPlaybackTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
2021-02-12 03:20:39 +00:00
|
|
|
// hover sounds shouldn't be played during scroll operations.
|
|
|
|
if (e.HasAnyButtonPressed)
|
|
|
|
return false;
|
|
|
|
|
2021-09-05 04:25:10 +00:00
|
|
|
bool enoughTimePassedSinceLastPlayback = !lastPlaybackTime.Value.HasValue || Time.Current - lastPlaybackTime.Value >= OsuGameBase.SAMPLE_DEBOUNCE_TIME;
|
2021-02-12 03:14:49 +00:00
|
|
|
|
|
|
|
if (enoughTimePassedSinceLastPlayback)
|
|
|
|
{
|
|
|
|
PlayHoverSample();
|
|
|
|
lastPlaybackTime.Value = Time.Current;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract void PlayHoverSample();
|
|
|
|
}
|
|
|
|
}
|