2020-12-19 01:30:53 +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
|
|
|
|
|
2020-12-19 01:30:53 +08:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
using osu.Framework.Allocation;
|
2020-12-25 12:38:11 +08:00
|
|
|
using osu.Game.Online.Multiplayer;
|
2021-11-22 17:39:50 +08:00
|
|
|
using osu.Game.Online.Rooms;
|
2020-12-19 01:30:53 +08:00
|
|
|
|
2020-12-25 23:50:00 +08:00
|
|
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
2020-12-19 01:30:53 +08:00
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public abstract partial class MultiplayerRoomComposite : OnlinePlayComposite
|
2020-12-19 01:30:53 +08:00
|
|
|
{
|
|
|
|
[CanBeNull]
|
|
|
|
protected MultiplayerRoom Room => Client.Room;
|
|
|
|
|
|
|
|
[Resolved]
|
2021-05-20 14:39:45 +08:00
|
|
|
protected MultiplayerClient Client { get; private set; }
|
2020-12-19 01:30:53 +08:00
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2021-10-14 16:37:08 +08:00
|
|
|
Client.RoomUpdated += invokeOnRoomUpdated;
|
2022-03-17 17:43:04 +08:00
|
|
|
Client.LoadRequested += invokeOnRoomLoadRequested;
|
2021-10-14 16:37:08 +08:00
|
|
|
Client.UserLeft += invokeUserLeft;
|
|
|
|
Client.UserKicked += invokeUserKicked;
|
|
|
|
Client.UserJoined += invokeUserJoined;
|
2021-11-22 17:39:50 +08:00
|
|
|
Client.ItemAdded += invokeItemAdded;
|
|
|
|
Client.ItemRemoved += invokeItemRemoved;
|
|
|
|
Client.ItemChanged += invokeItemChanged;
|
2021-08-25 13:25:57 +08:00
|
|
|
|
2020-12-26 09:48:55 +08:00
|
|
|
OnRoomUpdated();
|
2020-12-19 01:30:53 +08:00
|
|
|
}
|
|
|
|
|
2021-10-14 16:37:08 +08:00
|
|
|
private void invokeOnRoomUpdated() => Scheduler.AddOnce(OnRoomUpdated);
|
2021-12-05 00:38:37 +08:00
|
|
|
private void invokeUserJoined(MultiplayerRoomUser user) => Scheduler.Add(() => UserJoined(user));
|
|
|
|
private void invokeUserKicked(MultiplayerRoomUser user) => Scheduler.Add(() => UserKicked(user));
|
|
|
|
private void invokeUserLeft(MultiplayerRoomUser user) => Scheduler.Add(() => UserLeft(user));
|
2021-12-02 21:11:28 +08:00
|
|
|
private void invokeItemAdded(MultiplayerPlaylistItem item) => Schedule(() => PlaylistItemAdded(item));
|
|
|
|
private void invokeItemRemoved(long item) => Schedule(() => PlaylistItemRemoved(item));
|
|
|
|
private void invokeItemChanged(MultiplayerPlaylistItem item) => Schedule(() => PlaylistItemChanged(item));
|
2022-03-17 17:43:04 +08:00
|
|
|
private void invokeOnRoomLoadRequested() => Scheduler.AddOnce(OnRoomLoadRequested);
|
2021-10-14 16:37:08 +08:00
|
|
|
|
2021-08-25 13:25:57 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Invoked when a user has joined the room.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="user">The user.</param>
|
|
|
|
protected virtual void UserJoined(MultiplayerRoomUser user)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Invoked when a user has been kicked from the room (including the local user).
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="user">The user.</param>
|
|
|
|
protected virtual void UserKicked(MultiplayerRoomUser user)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Invoked when a user has left the room.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="user">The user.</param>
|
|
|
|
protected virtual void UserLeft(MultiplayerRoomUser user)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-11-22 17:39:50 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Invoked when a playlist item is added to the room.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="item">The added playlist item.</param>
|
|
|
|
protected virtual void PlaylistItemAdded(MultiplayerPlaylistItem item)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Invoked when a playlist item is removed from the room.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="item">The ID of the removed playlist item.</param>
|
|
|
|
protected virtual void PlaylistItemRemoved(long item)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Invoked when a playlist item is changed in the room.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="item">The new playlist item, with an existing item's ID.</param>
|
|
|
|
protected virtual void PlaylistItemChanged(MultiplayerPlaylistItem item)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-12-26 09:48:55 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Invoked when any change occurs to the multiplayer room.
|
|
|
|
/// </summary>
|
|
|
|
protected virtual void OnRoomUpdated()
|
2020-12-19 01:30:53 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-17 17:43:04 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Invoked when the room requests the local user to load into gameplay.
|
|
|
|
/// </summary>
|
|
|
|
protected virtual void OnRoomLoadRequested()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-12-19 01:30:53 +08:00
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
if (Client != null)
|
2021-08-25 13:25:57 +08:00
|
|
|
{
|
2021-10-14 16:37:08 +08:00
|
|
|
Client.RoomUpdated -= invokeOnRoomUpdated;
|
2022-09-18 13:25:31 +08:00
|
|
|
Client.LoadRequested -= invokeOnRoomLoadRequested;
|
2021-10-14 16:37:08 +08:00
|
|
|
Client.UserLeft -= invokeUserLeft;
|
|
|
|
Client.UserKicked -= invokeUserKicked;
|
|
|
|
Client.UserJoined -= invokeUserJoined;
|
2021-11-22 17:39:50 +08:00
|
|
|
Client.ItemAdded -= invokeItemAdded;
|
|
|
|
Client.ItemRemoved -= invokeItemRemoved;
|
|
|
|
Client.ItemChanged -= invokeItemChanged;
|
2021-08-25 13:25:57 +08:00
|
|
|
}
|
2020-12-19 01:30:53 +08:00
|
|
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|