1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 02:42:54 +08:00

Simplify sound debounce logic

This commit is contained in:
Dean Herbert 2021-02-04 17:06:11 +09:00
parent daf7ab9422
commit 4bfe3aabdc

View File

@ -496,17 +496,12 @@ namespace osu.Game.Overlays.Mods
MultiplierLabel.FadeColour(Color4.White, 200); MultiplierLabel.FadeColour(Color4.White, 200);
} }
private ScheduledDelegate sampleOnDelegate;
private ScheduledDelegate sampleOffDelegate;
private void modButtonPressed(Mod selectedMod) private void modButtonPressed(Mod selectedMod)
{ {
if (selectedMod != null) if (selectedMod != null)
{ {
// Fixes buzzing when multiple mods are selected in the same frame.
sampleOnDelegate?.Cancel();
if (State.Value == Visibility.Visible) if (State.Value == Visibility.Visible)
sampleOnDelegate = Scheduler.Add(() => sampleOn?.Play()); Scheduler.AddOnce(playSelectedSound);
OnModSelected(selectedMod); OnModSelected(selectedMod);
@ -514,15 +509,16 @@ namespace osu.Game.Overlays.Mods
} }
else else
{ {
// Fixes buzzing when multiple mods are deselected in the same frame.
sampleOffDelegate?.Cancel();
if (State.Value == Visibility.Visible) if (State.Value == Visibility.Visible)
sampleOffDelegate = Scheduler.Add(() => sampleOff?.Play()); Scheduler.AddOnce(playDeselectedSound);
} }
refreshSelectedMods(); refreshSelectedMods();
} }
private void playSelectedSound() => sampleOn?.Play();
private void playDeselectedSound() => sampleOff?.Play();
/// <summary> /// <summary>
/// Invoked when a new <see cref="Mod"/> has been selected. /// Invoked when a new <see cref="Mod"/> has been selected.
/// </summary> /// </summary>