mirror of
https://github.com/ppy/osu.git
synced 2025-03-10 18:17:19 +08:00
Merge pull request #32005 from smoogipoo/fix-multi-leave-host-sound
Fix host change sounds playing when exiting multiplayer rooms
This commit is contained in:
commit
e9b8154090
@ -51,6 +51,11 @@ namespace osu.Game.Online.Multiplayer
|
||||
/// </summary>
|
||||
public event Action<MultiplayerRoomUser>? UserKicked;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when the room's host is changed.
|
||||
/// </summary>
|
||||
public event Action<MultiplayerRoomUser?>? HostChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when a new item is added to the playlist.
|
||||
/// </summary>
|
||||
@ -531,6 +536,7 @@ namespace osu.Game.Online.Multiplayer
|
||||
Room.Host = user;
|
||||
APIRoom.Host = user?.User;
|
||||
|
||||
HostChanged?.Invoke(user);
|
||||
RoomUpdated?.Invoke();
|
||||
}, false);
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
// 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.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Sample;
|
||||
@ -20,7 +19,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
private Sample? userJoinedSample;
|
||||
private Sample? userLeftSample;
|
||||
private Sample? userKickedSample;
|
||||
private MultiplayerRoomUser? host;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(AudioManager audio)
|
||||
@ -35,25 +33,10 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
client.RoomUpdated += onRoomUpdated;
|
||||
client.UserJoined += onUserJoined;
|
||||
client.UserLeft += onUserLeft;
|
||||
client.UserKicked += onUserKicked;
|
||||
updateState();
|
||||
}
|
||||
|
||||
private void onRoomUpdated() => Scheduler.AddOnce(updateState);
|
||||
|
||||
private void updateState()
|
||||
{
|
||||
if (EqualityComparer<MultiplayerRoomUser>.Default.Equals(host, client.Room?.Host))
|
||||
return;
|
||||
|
||||
// only play sound when the host changes from an already-existing host.
|
||||
if (host != null)
|
||||
Scheduler.AddOnce(() => hostChangedSample?.Play());
|
||||
|
||||
host = client.Room?.Host;
|
||||
client.HostChanged += onHostChanged;
|
||||
}
|
||||
|
||||
private void onUserJoined(MultiplayerRoomUser user)
|
||||
@ -65,16 +48,22 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
private void onUserKicked(MultiplayerRoomUser user)
|
||||
=> Scheduler.AddOnce(() => userKickedSample?.Play());
|
||||
|
||||
private void onHostChanged(MultiplayerRoomUser? host)
|
||||
{
|
||||
if (host != null)
|
||||
Scheduler.AddOnce(() => hostChangedSample?.Play());
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
if (client.IsNotNull())
|
||||
{
|
||||
client.RoomUpdated -= onRoomUpdated;
|
||||
client.UserJoined -= onUserJoined;
|
||||
client.UserLeft -= onUserLeft;
|
||||
client.UserKicked -= onUserKicked;
|
||||
client.HostChanged -= onHostChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user