From 6eddc6c59e6c63c219798bc0fb92a59e0d3c3b96 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 9 Apr 2021 21:03:45 +0900 Subject: [PATCH] Enable spectating multiplayer matches --- .../Online/Multiplayer/MultiplayerClient.cs | 3 --- .../Screens/OnlinePlay/Match/RoomSubScreen.cs | 6 ++++-- .../Multiplayer/MultiplayerMatchSubScreen.cs | 20 +++++++++++++++---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/osu.Game/Online/Multiplayer/MultiplayerClient.cs b/osu.Game/Online/Multiplayer/MultiplayerClient.cs index 37e11cc576..4529dfd0a7 100644 --- a/osu.Game/Online/Multiplayer/MultiplayerClient.cs +++ b/osu.Game/Online/Multiplayer/MultiplayerClient.cs @@ -96,9 +96,6 @@ namespace osu.Game.Online.Multiplayer if (!IsConnected.Value) return Task.CompletedTask; - if (newState == MultiplayerUserState.Spectating) - return Task.CompletedTask; // Not supported yet. - return connection.InvokeAsync(nameof(IMultiplayerServer.ChangeState), newState); } diff --git a/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs b/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs index 706da05d15..0d1ed5d88e 100644 --- a/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs @@ -148,10 +148,12 @@ namespace osu.Game.Screens.OnlinePlay.Match return base.OnExiting(next); } - protected void StartPlay(Func player) + protected void StartPlay(Func player) => PushTopLevelScreen(() => new PlayerLoader(player)); + + protected void PushTopLevelScreen(Func screen) { sampleStart?.Play(); - ParentScreen?.Push(new PlayerLoader(player)); + ParentScreen?.Push(screen()); } private void selectedItemChanged() diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerMatchSubScreen.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerMatchSubScreen.cs index 90cef0107c..035eba4f30 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerMatchSubScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerMatchSubScreen.cs @@ -25,6 +25,7 @@ using osu.Game.Screens.OnlinePlay.Match; using osu.Game.Screens.OnlinePlay.Match.Components; using osu.Game.Screens.OnlinePlay.Multiplayer.Match; using osu.Game.Screens.OnlinePlay.Multiplayer.Participants; +using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate; using osu.Game.Screens.Play.HUD; using osu.Game.Users; using osuTK; @@ -405,11 +406,22 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer } } - private void onRoomUpdated() + private void onRoomUpdated() => Scheduler.Add(() => { - // user mods may have changed. - Scheduler.AddOnce(UpdateMods); - } + if (client.Room == null) + return; + + Debug.Assert(client.LocalUser != null); + + UpdateMods(); + + if (client.LocalUser.State == MultiplayerUserState.Spectating + && (client.Room.State == MultiplayerRoomState.Playing || client.Room.State == MultiplayerRoomState.WaitingForLoad) + && ParentScreen.IsCurrentScreen()) + { + PushTopLevelScreen(() => new MultiplayerSpectator(client.CurrentMatchPlayingUserIds.ToArray())); + } + }); private void onLoadRequested() {