mirror of
https://github.com/osukey/osukey.git
synced 2025-05-06 14:17:27 +09:00
Add sound when players change ready state
This commit is contained in:
parent
43370d7021
commit
c35454081c
@ -7,6 +7,7 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Audio;
|
using osu.Framework.Audio;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
using osu.Game.Online.RealtimeMultiplayer;
|
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);
|
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", () =>
|
private void addClickButtonStep() => AddStep("click button", () =>
|
||||||
{
|
{
|
||||||
InputManager.MoveMouseTo(button);
|
InputManager.MoveMouseTo(button);
|
||||||
|
@ -5,6 +5,8 @@ using System.Diagnostics;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Audio;
|
||||||
|
using osu.Framework.Audio.Sample;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Extensions;
|
using osu.Game.Extensions;
|
||||||
@ -31,8 +33,12 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer.Match
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private OsuColour colours { get; set; }
|
private OsuColour colours { get; set; }
|
||||||
|
|
||||||
|
private SampleChannel sampleReadyCount;
|
||||||
|
|
||||||
private readonly ButtonWithTrianglesExposed button;
|
private readonly ButtonWithTrianglesExposed button;
|
||||||
|
|
||||||
|
private int countReady;
|
||||||
|
|
||||||
public RealtimeReadyButton()
|
public RealtimeReadyButton()
|
||||||
{
|
{
|
||||||
InternalChild = button = new ButtonWithTrianglesExposed
|
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()
|
protected override void OnRoomChanged()
|
||||||
{
|
{
|
||||||
base.OnRoomChanged();
|
base.OnRoomChanged();
|
||||||
@ -60,6 +72,10 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer.Match
|
|||||||
|
|
||||||
Debug.Assert(Room != null);
|
Debug.Assert(Room != null);
|
||||||
|
|
||||||
|
int newCountReady = Room.Users.Count(u => u.State == MultiplayerUserState.Ready);
|
||||||
|
|
||||||
|
string countText = $"({newCountReady} / {Room.Users.Count} ready)";
|
||||||
|
|
||||||
switch (localUser.State)
|
switch (localUser.State)
|
||||||
{
|
{
|
||||||
case MultiplayerUserState.Idle:
|
case MultiplayerUserState.Idle:
|
||||||
@ -70,18 +86,32 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer.Match
|
|||||||
case MultiplayerUserState.Ready:
|
case MultiplayerUserState.Ready:
|
||||||
if (Room?.Host?.Equals(localUser) == true)
|
if (Room?.Host?.Equals(localUser) == true)
|
||||||
{
|
{
|
||||||
int countReady = Room.Users.Count(u => u.State == MultiplayerUserState.Ready);
|
button.Text = $"Start match {countText}";
|
||||||
button.Text = $"Start match ({countReady} / {Room.Users.Count} ready)";
|
|
||||||
updateButtonColour(true);
|
updateButtonColour(true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
button.Text = "Waiting for host...";
|
button.Text = $"Waiting for host... {countText}";
|
||||||
updateButtonColour(false);
|
updateButtonColour(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
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)
|
private void updateButtonColour(bool green)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user