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