1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 16:27:26 +08:00

Add sound when players change ready state

This commit is contained in:
Dean Herbert 2020-12-24 17:17:45 +09:00
parent 43370d7021
commit c35454081c
2 changed files with 64 additions and 3 deletions

View File

@ -7,6 +7,7 @@ using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Graphics;
using osu.Framework.Platform;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Online.Multiplayer;
using osu.Game.Online.RealtimeMultiplayer;
@ -124,6 +125,36 @@ namespace osu.Game.Tests.Visual.RealtimeMultiplayer
AddAssert("match not started", () => Client.Room?.Users[0].State == MultiplayerUserState.Idle);
}
[TestCase(true)]
[TestCase(false)]
public void TestManyUsersChangingState(bool isHost)
{
const int users = 10;
AddStep("setup", () =>
{
Client.TransferHost(Client.Room?.Users[0].UserID ?? 0);
for (int i = 0; i < users; i++)
Client.AddUser(new User { Id = i, Username = "Another user" });
});
if (!isHost)
AddStep("transfer host", () => Client.TransferHost(2));
addClickButtonStep();
AddRepeatStep("change user ready state", () =>
{
Client.ChangeUserState(RNG.Next(0, users), RNG.NextBool() ? MultiplayerUserState.Ready : MultiplayerUserState.Idle);
}, 20);
AddRepeatStep("ready all users", () =>
{
var nextUnready = Client.Room?.Users.FirstOrDefault(c => c.State == MultiplayerUserState.Idle);
if (nextUnready != null)
Client.ChangeUserState(nextUnready.UserID, MultiplayerUserState.Ready);
}, users);
}
private void addClickButtonStep() => AddStep("click button", () =>
{
InputManager.MoveMouseTo(button);

View File

@ -5,6 +5,8 @@ using System.Diagnostics;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Extensions;
@ -31,8 +33,12 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer.Match
[Resolved]
private OsuColour colours { get; set; }
private SampleChannel sampleReadyCount;
private readonly ButtonWithTrianglesExposed button;
private int countReady;
public RealtimeReadyButton()
{
InternalChild = button = new ButtonWithTrianglesExposed
@ -44,6 +50,12 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer.Match
};
}
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
sampleReadyCount = audio.Samples.Get(@"SongSelect/select-difficulty");
}
protected override void OnRoomChanged()
{
base.OnRoomChanged();
@ -60,6 +72,10 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer.Match
Debug.Assert(Room != null);
int newCountReady = Room.Users.Count(u => u.State == MultiplayerUserState.Ready);
string countText = $"({newCountReady} / {Room.Users.Count} ready)";
switch (localUser.State)
{
case MultiplayerUserState.Idle:
@ -70,18 +86,32 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer.Match
case MultiplayerUserState.Ready:
if (Room?.Host?.Equals(localUser) == true)
{
int countReady = Room.Users.Count(u => u.State == MultiplayerUserState.Ready);
button.Text = $"Start match ({countReady} / {Room.Users.Count} ready)";
button.Text = $"Start match {countText}";
updateButtonColour(true);
}
else
{
button.Text = "Waiting for host...";
button.Text = $"Waiting for host... {countText}";
updateButtonColour(false);
}
break;
}
if (newCountReady != countReady)
{
countReady = newCountReady;
Scheduler.AddOnce(playSound);
}
}
private void playSound()
{
if (sampleReadyCount != null)
{
sampleReadyCount.Frequency.Value = 0.77f + countReady * 0.06f;
sampleReadyCount.Play();
}
}
private void updateButtonColour(bool green)