1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 08:52:55 +08:00

Refactor implementation to roughly match existing HoverSampleDebounceComponent

This commit is contained in:
Dean Herbert 2023-06-12 14:32:55 +09:00
parent 4819a28791
commit 1e774fc017

View File

@ -45,6 +45,7 @@ namespace osu.Game.Overlays.Mods
public const float CORNER_RADIUS = 7; public const float CORNER_RADIUS = 7;
public const float HEIGHT = 42; public const float HEIGHT = 42;
public const double SAMPLE_PLAYBACK_DELAY = 30; public const double SAMPLE_PLAYBACK_DELAY = 30;
protected virtual float IdleSwitchWidth => 14; protected virtual float IdleSwitchWidth => 14;
@ -64,9 +65,6 @@ namespace osu.Game.Overlays.Mods
[Resolved] [Resolved]
protected OverlayColourProvider ColourProvider { get; private set; } = null!; protected OverlayColourProvider ColourProvider { get; private set; } = null!;
[Resolved]
protected SessionStatics Statics { get; private set; } = null!;
private readonly OsuSpriteText titleText; private readonly OsuSpriteText titleText;
private readonly OsuSpriteText descriptionText; private readonly OsuSpriteText descriptionText;
@ -74,6 +72,8 @@ namespace osu.Game.Overlays.Mods
private Sample? sampleOff; private Sample? sampleOff;
private Sample? sampleOn; private Sample? sampleOn;
private Bindable<double?> lastPlaybackTime = null!;
protected ModSelectPanel() protected ModSelectPanel()
{ {
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
@ -168,13 +168,15 @@ namespace osu.Game.Overlays.Mods
protected abstract void Deselect(); protected abstract void Deselect();
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(AudioManager audio, ISamplePlaybackDisabler? samplePlaybackDisabler) private void load(AudioManager audio, SessionStatics statics, ISamplePlaybackDisabler? samplePlaybackDisabler)
{ {
sampleOn = audio.Samples.Get(@"UI/check-on"); sampleOn = audio.Samples.Get(@"UI/check-on");
sampleOff = audio.Samples.Get(@"UI/check-off"); sampleOff = audio.Samples.Get(@"UI/check-off");
if (samplePlaybackDisabler != null) if (samplePlaybackDisabler != null)
((IBindable<bool>)samplePlaybackDisabled).BindTo(samplePlaybackDisabler.SamplePlaybackDisabled); ((IBindable<bool>)samplePlaybackDisabled).BindTo(samplePlaybackDisabler.SamplePlaybackDisabled);
lastPlaybackTime = statics.GetBindable<double?>(Static.LastHoverSoundPlaybackTime);
} }
protected sealed override HoverSounds CreateHoverSounds(HoverSampleSet sampleSet) => new HoverSounds(sampleSet); protected sealed override HoverSounds CreateHoverSounds(HoverSampleSet sampleSet) => new HoverSounds(sampleSet);
@ -197,17 +199,17 @@ namespace osu.Game.Overlays.Mods
if (samplePlaybackDisabled.Value) if (samplePlaybackDisabled.Value)
return; return;
double? lastPlaybackTime = Statics.Get<double?>(Static.LastModSelectPanelSamplePlaybackTime); bool enoughTimePassedSinceLastPlayback = !lastPlaybackTime.Value.HasValue || Time.Current - lastPlaybackTime.Value >= SAMPLE_PLAYBACK_DELAY;
if (lastPlaybackTime is not null && Time.Current - lastPlaybackTime < SAMPLE_PLAYBACK_DELAY) if (enoughTimePassedSinceLastPlayback)
return; {
if (Active.Value)
sampleOn?.Play();
else
sampleOff?.Play();
if (Active.Value) lastPlaybackTime.Value = Time.Current;
sampleOn?.Play(); }
else
sampleOff?.Play();
Statics.SetValue<double?>(Static.LastModSelectPanelSamplePlaybackTime, Time.Current);
} }
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)