1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 20:07:29 +08:00

Change debounce back to using scheduler

Should better allow for adjusting in the future, as well.
This commit is contained in:
Dean Herbert 2021-08-27 18:57:18 +09:00
parent 33aa48bcf6
commit 2b06dacd0e

View File

@ -8,6 +8,7 @@ using osu.Framework.Audio;
using osu.Framework.Audio.Sample; using osu.Framework.Audio.Sample;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Threading;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds; using osu.Game.Graphics.Backgrounds;
using osu.Game.Online.API; using osu.Game.Online.API;
@ -38,12 +39,13 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
private Sample sampleReady; private Sample sampleReady;
private Sample sampleReadyAll; private Sample sampleReadyAll;
private Sample sampleUnready; private Sample sampleUnready;
private double unreadyLastPlaybackTime;
private readonly ButtonWithTrianglesExposed button; private readonly ButtonWithTrianglesExposed button;
private int countReady; private int countReady;
private ScheduledDelegate readySampleDelegate;
public MultiplayerReadyButton() public MultiplayerReadyButton()
{ {
InternalChild = button = new ButtonWithTrianglesExposed InternalChild = button = new ButtonWithTrianglesExposed
@ -63,8 +65,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
sampleReady = audio.Samples.Get(@"Multiplayer/player-ready"); sampleReady = audio.Samples.Get(@"Multiplayer/player-ready");
sampleReadyAll = audio.Samples.Get(@"Multiplayer/player-ready-all"); sampleReadyAll = audio.Samples.Get(@"Multiplayer/player-ready-all");
sampleUnready = audio.Samples.Get(@"Multiplayer/player-unready"); sampleUnready = audio.Samples.Get(@"Multiplayer/player-unready");
unreadyLastPlaybackTime = Time.Current;
} }
protected override void OnRoomUpdated() protected override void OnRoomUpdated()
@ -117,24 +117,23 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
if (newCountReady == countReady) if (newCountReady == countReady)
return; return;
if (newCountReady > countReady) readySampleDelegate?.Cancel();
readySampleDelegate = Schedule(() =>
{ {
if (newCountReady == newCountTotal) if (newCountReady > countReady)
sampleReadyAll?.Play(); {
else if (newCountReady == newCountTotal)
sampleReady?.Play(); sampleReadyAll?.Play();
} else
else sampleReady?.Play();
{ }
// debounce sample playback to prevent the mass-unready of game mode changes from deafening players else if (newCountReady < countReady)
if (Time.Current - unreadyLastPlaybackTime > 10)
{ {
sampleUnready?.Play(); sampleUnready?.Play();
unreadyLastPlaybackTime = Time.Current;
} }
}
countReady = newCountReady; countReady = newCountReady;
});
} }
private void updateButtonColour(bool green) private void updateButtonColour(bool green)