mirror of
https://github.com/ppy/osu.git
synced 2025-03-10 20:57: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>
|
/// </summary>
|
||||||
public event Action<MultiplayerRoomUser>? UserKicked;
|
public event Action<MultiplayerRoomUser>? UserKicked;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invoked when the room's host is changed.
|
||||||
|
/// </summary>
|
||||||
|
public event Action<MultiplayerRoomUser?>? HostChanged;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invoked when a new item is added to the playlist.
|
/// Invoked when a new item is added to the playlist.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -531,6 +536,7 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
Room.Host = user;
|
Room.Host = user;
|
||||||
APIRoom.Host = user?.User;
|
APIRoom.Host = user?.User;
|
||||||
|
|
||||||
|
HostChanged?.Invoke(user);
|
||||||
RoomUpdated?.Invoke();
|
RoomUpdated?.Invoke();
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Audio;
|
using osu.Framework.Audio;
|
||||||
using osu.Framework.Audio.Sample;
|
using osu.Framework.Audio.Sample;
|
||||||
@ -20,7 +19,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
private Sample? userJoinedSample;
|
private Sample? userJoinedSample;
|
||||||
private Sample? userLeftSample;
|
private Sample? userLeftSample;
|
||||||
private Sample? userKickedSample;
|
private Sample? userKickedSample;
|
||||||
private MultiplayerRoomUser? host;
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(AudioManager audio)
|
private void load(AudioManager audio)
|
||||||
@ -35,25 +33,10 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
client.RoomUpdated += onRoomUpdated;
|
|
||||||
client.UserJoined += onUserJoined;
|
client.UserJoined += onUserJoined;
|
||||||
client.UserLeft += onUserLeft;
|
client.UserLeft += onUserLeft;
|
||||||
client.UserKicked += onUserKicked;
|
client.UserKicked += onUserKicked;
|
||||||
updateState();
|
client.HostChanged += onHostChanged;
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onUserJoined(MultiplayerRoomUser user)
|
private void onUserJoined(MultiplayerRoomUser user)
|
||||||
@ -65,16 +48,22 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
private void onUserKicked(MultiplayerRoomUser user)
|
private void onUserKicked(MultiplayerRoomUser user)
|
||||||
=> Scheduler.AddOnce(() => userKickedSample?.Play());
|
=> Scheduler.AddOnce(() => userKickedSample?.Play());
|
||||||
|
|
||||||
|
private void onHostChanged(MultiplayerRoomUser? host)
|
||||||
|
{
|
||||||
|
if (host != null)
|
||||||
|
Scheduler.AddOnce(() => hostChangedSample?.Play());
|
||||||
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
|
|
||||||
if (client.IsNotNull())
|
if (client.IsNotNull())
|
||||||
{
|
{
|
||||||
client.RoomUpdated -= onRoomUpdated;
|
|
||||||
client.UserJoined -= onUserJoined;
|
client.UserJoined -= onUserJoined;
|
||||||
client.UserLeft -= onUserLeft;
|
client.UserLeft -= onUserLeft;
|
||||||
client.UserKicked -= onUserKicked;
|
client.UserKicked -= onUserKicked;
|
||||||
|
client.HostChanged -= onHostChanged;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user