mirror of
https://github.com/ppy/osu.git
synced 2025-02-10 06:12:55 +08:00
Share hover sound debounce across all instances via SessionStatics
This commit is contained in:
parent
6620eadec3
commit
8f52a83b29
@ -1,7 +1,9 @@
|
|||||||
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
using osu.Game.Overlays;
|
||||||
|
|
||||||
namespace osu.Game.Configuration
|
namespace osu.Game.Configuration
|
||||||
{
|
{
|
||||||
@ -14,6 +16,7 @@ namespace osu.Game.Configuration
|
|||||||
{
|
{
|
||||||
Set(Static.LoginOverlayDisplayed, false);
|
Set(Static.LoginOverlayDisplayed, false);
|
||||||
Set(Static.MutedAudioNotificationShownOnce, false);
|
Set(Static.MutedAudioNotificationShownOnce, false);
|
||||||
|
Set(Static.LastHoverSoundPlaybackTime, 0.0);
|
||||||
Set<APISeasonalBackgrounds>(Static.SeasonalBackgrounds, null);
|
Set<APISeasonalBackgrounds>(Static.SeasonalBackgrounds, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -28,5 +31,11 @@ namespace osu.Game.Configuration
|
|||||||
/// Value under this lookup can be <c>null</c> if there are no backgrounds available (or API is not reachable).
|
/// Value under this lookup can be <c>null</c> if there are no backgrounds available (or API is not reachable).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
SeasonalBackgrounds,
|
SeasonalBackgrounds,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The last playback time in milliseconds of a hover sample (from <see cref="HoverSounds"/>).
|
||||||
|
/// Used to debounce hover sounds game-wide to avoid volume saturation, especially in scrolling views with many UI controls like <see cref="SettingsOverlay"/>.
|
||||||
|
/// </summary>
|
||||||
|
LastHoverSoundPlaybackTime
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,12 @@ using System.ComponentModel;
|
|||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Audio;
|
using osu.Framework.Audio;
|
||||||
using osu.Framework.Audio.Sample;
|
using osu.Framework.Audio.Sample;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Extensions;
|
using osu.Framework.Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Framework.Threading;
|
using osu.Game.Configuration;
|
||||||
|
|
||||||
namespace osu.Game.Graphics.UserInterface
|
namespace osu.Game.Graphics.UserInterface
|
||||||
{
|
{
|
||||||
@ -28,30 +29,34 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
|
|
||||||
protected readonly HoverSampleSet SampleSet;
|
protected readonly HoverSampleSet SampleSet;
|
||||||
|
|
||||||
|
private Bindable<double> lastPlaybackTime;
|
||||||
|
|
||||||
public HoverSounds(HoverSampleSet sampleSet = HoverSampleSet.Normal)
|
public HoverSounds(HoverSampleSet sampleSet = HoverSampleSet.Normal)
|
||||||
{
|
{
|
||||||
SampleSet = sampleSet;
|
SampleSet = sampleSet;
|
||||||
RelativeSizeAxes = Axes.Both;
|
RelativeSizeAxes = Axes.Both;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScheduledDelegate playDelegate;
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(AudioManager audio, SessionStatics statics)
|
||||||
|
{
|
||||||
|
lastPlaybackTime = statics.GetBindable<double>(Static.LastHoverSoundPlaybackTime);
|
||||||
|
|
||||||
|
sampleHover = audio.Samples.Get($@"UI/generic-hover{SampleSet.GetDescription()}");
|
||||||
|
}
|
||||||
|
|
||||||
protected override bool OnHover(HoverEvent e)
|
protected override bool OnHover(HoverEvent e)
|
||||||
{
|
{
|
||||||
playDelegate?.Cancel();
|
bool requiresDebounce = HoverDebounceTime <= 0;
|
||||||
|
bool enoughTimePassedSinceLastPlayback = lastPlaybackTime.Value == 0 || Time.Current - lastPlaybackTime.Value > HoverDebounceTime;
|
||||||
|
|
||||||
if (HoverDebounceTime <= 0)
|
if (!requiresDebounce || enoughTimePassedSinceLastPlayback)
|
||||||
|
{
|
||||||
sampleHover?.Play();
|
sampleHover?.Play();
|
||||||
else
|
lastPlaybackTime.Value = Time.Current;
|
||||||
playDelegate = Scheduler.AddDelayed(() => sampleHover?.Play(), HoverDebounceTime);
|
|
||||||
|
|
||||||
return base.OnHover(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
return base.OnHover(e);
|
||||||
private void load(AudioManager audio)
|
|
||||||
{
|
|
||||||
sampleHover = audio.Samples.Get($@"UI/generic-hover{SampleSet.GetDescription()}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user