2022-01-14 17:06:19 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2022-01-14 17:06:19 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Audio.Sample;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
using osu.Game.Online.Multiplayer;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class MultiplayerRoomSounds : MultiplayerRoomComposite
|
2022-01-14 17:06:19 +08:00
|
|
|
{
|
|
|
|
private Sample hostChangedSample;
|
|
|
|
private Sample userJoinedSample;
|
|
|
|
private Sample userLeftSample;
|
|
|
|
private Sample userKickedSample;
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(AudioManager audio)
|
|
|
|
{
|
|
|
|
hostChangedSample = audio.Samples.Get(@"Multiplayer/host-changed");
|
|
|
|
userJoinedSample = audio.Samples.Get(@"Multiplayer/player-joined");
|
|
|
|
userLeftSample = audio.Samples.Get(@"Multiplayer/player-left");
|
|
|
|
userKickedSample = audio.Samples.Get(@"Multiplayer/player-kicked");
|
2022-01-15 20:20:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2022-01-14 17:06:19 +08:00
|
|
|
|
2022-01-15 20:20:27 +08:00
|
|
|
Host.BindValueChanged(hostChanged);
|
2022-01-14 17:06:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void UserJoined(MultiplayerRoomUser user)
|
|
|
|
{
|
|
|
|
base.UserJoined(user);
|
|
|
|
|
2022-03-31 15:18:26 +08:00
|
|
|
Scheduler.AddOnce(() => userJoinedSample?.Play());
|
2022-01-14 17:06:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void UserLeft(MultiplayerRoomUser user)
|
|
|
|
{
|
|
|
|
base.UserLeft(user);
|
|
|
|
|
2022-03-31 15:18:26 +08:00
|
|
|
Scheduler.AddOnce(() => userLeftSample?.Play());
|
2022-01-14 17:06:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void UserKicked(MultiplayerRoomUser user)
|
|
|
|
{
|
|
|
|
base.UserKicked(user);
|
|
|
|
|
2022-03-31 15:18:26 +08:00
|
|
|
Scheduler.AddOnce(() => userKickedSample?.Play());
|
2022-01-14 17:06:19 +08:00
|
|
|
}
|
|
|
|
|
2022-01-15 20:19:02 +08:00
|
|
|
private void hostChanged(ValueChangedEvent<APIUser> value)
|
|
|
|
{
|
|
|
|
// only play sound when the host changes from an already-existing host.
|
|
|
|
if (value.OldValue == null) return;
|
|
|
|
|
2022-03-31 15:18:26 +08:00
|
|
|
Scheduler.AddOnce(() => hostChangedSample?.Play());
|
2022-01-15 20:19:02 +08:00
|
|
|
}
|
2022-01-14 17:06:19 +08:00
|
|
|
}
|
|
|
|
}
|