mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 14:12:56 +08:00
Merge pull request #16090 from peppy/fix-scroll-speed-toast-sample-spam
Fix toast popups spamming samples when adjusting osu!mania scroll speed during gameplay
This commit is contained in:
commit
3f1d747b7a
@ -5,12 +5,14 @@ using System;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Configuration.Tracking;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Effects;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Graphics;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
@ -28,6 +30,8 @@ namespace osu.Game.Overlays.OSD
|
||||
private Sample sampleOff;
|
||||
private Sample sampleChange;
|
||||
|
||||
private Bindable<double?> lastPlaybackTime;
|
||||
|
||||
public TrackedSettingToast(SettingDescription description)
|
||||
: base(description.Name, description.Value, description.Shortcut)
|
||||
{
|
||||
@ -75,10 +79,28 @@ namespace osu.Game.Overlays.OSD
|
||||
optionLights.Add(new OptionLight { Glowing = i == selectedOption });
|
||||
}
|
||||
|
||||
[Resolved]
|
||||
private SessionStatics statics { get; set; }
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
playSound();
|
||||
}
|
||||
|
||||
private void playSound()
|
||||
{
|
||||
// This debounce code roughly follows what we're using in HoverSampleDebounceComponent.
|
||||
// We're sharing the existing static for hover sounds because it doesn't really matter if they block each other.
|
||||
// This is a simple solution, but if this ever becomes a problem (or other performance issues arise),
|
||||
// the whole toast system should be rewritten to avoid recreating this drawable each time a value changes.
|
||||
lastPlaybackTime = statics.GetBindable<double?>(Static.LastHoverSoundPlaybackTime);
|
||||
|
||||
bool enoughTimePassedSinceLastPlayback = !lastPlaybackTime.Value.HasValue || Time.Current - lastPlaybackTime.Value >= OsuGameBase.SAMPLE_DEBOUNCE_TIME;
|
||||
|
||||
if (!enoughTimePassedSinceLastPlayback) return;
|
||||
|
||||
if (optionCount == 1)
|
||||
{
|
||||
if (selectedOption == 0)
|
||||
@ -93,6 +115,8 @@ namespace osu.Game.Overlays.OSD
|
||||
sampleChange.Frequency.Value = 1 + (double)selectedOption / (optionCount - 1) * 0.25f;
|
||||
sampleChange.Play();
|
||||
}
|
||||
|
||||
lastPlaybackTime.Value = Time.Current;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
|
@ -101,7 +101,7 @@ namespace osu.Game.Overlays
|
||||
DisplayTemporarily(box);
|
||||
});
|
||||
|
||||
private void displayTrackedSettingChange(SettingDescription description) => Display(new TrackedSettingToast(description));
|
||||
private void displayTrackedSettingChange(SettingDescription description) => Scheduler.AddOnce(Display, new TrackedSettingToast(description));
|
||||
|
||||
private TransformSequence<Drawable> fadeIn;
|
||||
private ScheduledDelegate fadeOut;
|
||||
|
Loading…
Reference in New Issue
Block a user