mirror of
https://github.com/ppy/osu.git
synced 2024-12-13 08:32:57 +08:00
Merge pull request #14512 from nekodex/lobby-sounds
Add sounds for some lobby events
This commit is contained in:
commit
2bfb9d5478
@ -51,7 +51,7 @@
|
||||
<Reference Include="Java.Interop" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.822.0" />
|
||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.827.0" />
|
||||
<PackageReference Include="ppy.osu.Framework.Android" Version="2021.819.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Label="Transitive Dependencies">
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
@ -12,6 +13,7 @@ using osu.Framework.Input;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
@ -94,6 +96,120 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
AddStep("empty step", () => { });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestLobbyEvents()
|
||||
{
|
||||
createRoom(() => new Room
|
||||
{
|
||||
Name = { Value = "Test Room" },
|
||||
Playlist =
|
||||
{
|
||||
new PlaylistItem
|
||||
{
|
||||
Beatmap = { Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.RulesetID == 0)).BeatmapInfo },
|
||||
Ruleset = { Value = new OsuRuleset().RulesetInfo },
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
AddRepeatStep("random stuff happens", performRandomAction, 30);
|
||||
|
||||
// ensure we have a handful of players so the ready-up sounds good :9
|
||||
AddRepeatStep("player joins", addRandomPlayer, 5);
|
||||
|
||||
// all ready
|
||||
AddUntilStep("all players ready", () =>
|
||||
{
|
||||
var nextUnready = client.Room?.Users.FirstOrDefault(c => c.State == MultiplayerUserState.Idle);
|
||||
if (nextUnready != null)
|
||||
client.ChangeUserState(nextUnready.UserID, MultiplayerUserState.Ready);
|
||||
|
||||
return client.Room?.Users.All(u => u.State == MultiplayerUserState.Ready) == true;
|
||||
});
|
||||
|
||||
AddStep("unready all players at once", () =>
|
||||
{
|
||||
Debug.Assert(client.Room != null);
|
||||
|
||||
foreach (var u in client.Room.Users) client.ChangeUserState(u.UserID, MultiplayerUserState.Idle);
|
||||
});
|
||||
|
||||
AddStep("ready all players at once", () =>
|
||||
{
|
||||
Debug.Assert(client.Room != null);
|
||||
|
||||
foreach (var u in client.Room.Users) client.ChangeUserState(u.UserID, MultiplayerUserState.Ready);
|
||||
});
|
||||
}
|
||||
|
||||
private void addRandomPlayer()
|
||||
{
|
||||
int randomUser = RNG.Next(200000, 500000);
|
||||
client.AddUser(new User { Id = randomUser, Username = $"user {randomUser}" });
|
||||
}
|
||||
|
||||
private void removeLastUser()
|
||||
{
|
||||
User lastUser = client.Room?.Users.Last().User;
|
||||
|
||||
if (lastUser == null || lastUser == client.LocalUser?.User)
|
||||
return;
|
||||
|
||||
client.RemoveUser(lastUser);
|
||||
}
|
||||
|
||||
private void kickLastUser()
|
||||
{
|
||||
User lastUser = client.Room?.Users.Last().User;
|
||||
|
||||
if (lastUser == null || lastUser == client.LocalUser?.User)
|
||||
return;
|
||||
|
||||
client.KickUser(lastUser.Id);
|
||||
}
|
||||
|
||||
private void markNextPlayerReady()
|
||||
{
|
||||
var nextUnready = client.Room?.Users.FirstOrDefault(c => c.State == MultiplayerUserState.Idle);
|
||||
if (nextUnready != null)
|
||||
client.ChangeUserState(nextUnready.UserID, MultiplayerUserState.Ready);
|
||||
}
|
||||
|
||||
private void markNextPlayerIdle()
|
||||
{
|
||||
var nextUnready = client.Room?.Users.FirstOrDefault(c => c.State == MultiplayerUserState.Ready);
|
||||
if (nextUnready != null)
|
||||
client.ChangeUserState(nextUnready.UserID, MultiplayerUserState.Idle);
|
||||
}
|
||||
|
||||
private void performRandomAction()
|
||||
{
|
||||
int eventToPerform = RNG.Next(1, 6);
|
||||
|
||||
switch (eventToPerform)
|
||||
{
|
||||
case 1:
|
||||
addRandomPlayer();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
removeLastUser();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
kickLastUser();
|
||||
break;
|
||||
|
||||
case 4:
|
||||
markNextPlayerReady();
|
||||
break;
|
||||
|
||||
case 5:
|
||||
markNextPlayerIdle();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateRoomViaKeyboard()
|
||||
{
|
||||
|
@ -8,6 +8,7 @@ using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Screens.OnlinePlay.Components;
|
||||
using osuTK;
|
||||
@ -75,6 +76,7 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
|
||||
},
|
||||
},
|
||||
},
|
||||
new HoverClickSounds(),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
@ -35,12 +36,16 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
|
||||
private IBindable<bool> operationInProgress;
|
||||
|
||||
private Sample sampleReadyCount;
|
||||
private Sample sampleReady;
|
||||
private Sample sampleReadyAll;
|
||||
private Sample sampleUnready;
|
||||
|
||||
private readonly ButtonWithTrianglesExposed button;
|
||||
|
||||
private int countReady;
|
||||
|
||||
private ScheduledDelegate readySampleDelegate;
|
||||
|
||||
public MultiplayerReadyButton()
|
||||
{
|
||||
InternalChild = button = new ButtonWithTrianglesExposed
|
||||
@ -54,10 +59,12 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(AudioManager audio)
|
||||
{
|
||||
sampleReadyCount = audio.Samples.Get(@"SongSelect/select-difficulty");
|
||||
|
||||
operationInProgress = ongoingOperationTracker.InProgress.GetBoundCopy();
|
||||
operationInProgress.BindValueChanged(_ => updateState());
|
||||
|
||||
sampleReady = audio.Samples.Get(@"Multiplayer/player-ready");
|
||||
sampleReadyAll = audio.Samples.Get(@"Multiplayer/player-ready-all");
|
||||
sampleUnready = audio.Samples.Get(@"Multiplayer/player-unready");
|
||||
}
|
||||
|
||||
protected override void OnRoomUpdated()
|
||||
@ -107,21 +114,26 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
|
||||
button.Enabled.Value = enableButton;
|
||||
|
||||
if (newCountReady != countReady)
|
||||
{
|
||||
countReady = newCountReady;
|
||||
Scheduler.AddOnce(playSound);
|
||||
}
|
||||
}
|
||||
|
||||
private void playSound()
|
||||
{
|
||||
if (sampleReadyCount == null)
|
||||
if (newCountReady == countReady)
|
||||
return;
|
||||
|
||||
var channel = sampleReadyCount.GetChannel();
|
||||
channel.Frequency.Value = 0.77f + countReady * 0.06f;
|
||||
channel.Play();
|
||||
readySampleDelegate?.Cancel();
|
||||
readySampleDelegate = Schedule(() =>
|
||||
{
|
||||
if (newCountReady > countReady)
|
||||
{
|
||||
if (newCountReady == newCountTotal)
|
||||
sampleReadyAll?.Play();
|
||||
else
|
||||
sampleReady?.Play();
|
||||
}
|
||||
else if (newCountReady < countReady)
|
||||
{
|
||||
sampleUnready?.Play();
|
||||
}
|
||||
|
||||
countReady = newCountReady;
|
||||
});
|
||||
}
|
||||
|
||||
private void updateButtonColour(bool green)
|
||||
|
@ -3,10 +3,13 @@
|
||||
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Cursor;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
|
||||
@ -15,8 +18,12 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
|
||||
{
|
||||
private FillFlowContainer<ParticipantPanel> panels;
|
||||
|
||||
private Sample userJoinSample;
|
||||
private Sample userLeftSample;
|
||||
private Sample userKickedSample;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
private void load(AudioManager audio)
|
||||
{
|
||||
InternalChild = new OsuContextMenuContainer
|
||||
{
|
||||
@ -34,6 +41,31 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
userJoinSample = audio.Samples.Get(@"Multiplayer/player-joined");
|
||||
userLeftSample = audio.Samples.Get(@"Multiplayer/player-left");
|
||||
userKickedSample = audio.Samples.Get(@"Multiplayer/player-kicked");
|
||||
}
|
||||
|
||||
protected override void UserJoined(MultiplayerRoomUser user)
|
||||
{
|
||||
base.UserJoined(user);
|
||||
|
||||
userJoinSample?.Play();
|
||||
}
|
||||
|
||||
protected override void UserLeft(MultiplayerRoomUser user)
|
||||
{
|
||||
base.UserLeft(user);
|
||||
|
||||
userLeftSample?.Play();
|
||||
}
|
||||
|
||||
protected override void UserKicked(MultiplayerRoomUser user)
|
||||
{
|
||||
base.UserKicked(user);
|
||||
|
||||
userKickedSample?.Play();
|
||||
}
|
||||
|
||||
protected override void OnRoomUpdated()
|
||||
|
@ -37,7 +37,7 @@
|
||||
</PackageReference>
|
||||
<PackageReference Include="Realm" Version="10.3.0" />
|
||||
<PackageReference Include="ppy.osu.Framework" Version="2021.819.0" />
|
||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.822.0" />
|
||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.827.0" />
|
||||
<PackageReference Include="Sentry" Version="3.8.3" />
|
||||
<PackageReference Include="SharpCompress" Version="0.28.3" />
|
||||
<PackageReference Include="NUnit" Version="3.13.2" />
|
||||
|
@ -71,7 +71,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup Label="Package References">
|
||||
<PackageReference Include="ppy.osu.Framework.iOS" Version="2021.819.0" />
|
||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.822.0" />
|
||||
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.827.0" />
|
||||
</ItemGroup>
|
||||
<!-- See https://github.com/dotnet/runtime/issues/35988 (can be removed after Xamarin uses net5.0 / net6.0) -->
|
||||
<PropertyGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user