From 1c086d99deae8c03b1412b13ec6f5c00e0abfe94 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 16 Apr 2021 13:28:32 +0900 Subject: [PATCH] Add loading spinner --- .../Spectate/MultiplayerSpectator.cs | 8 ++----- .../Multiplayer/Spectate/PlayerInstance.cs | 24 +++++++++++++------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/MultiplayerSpectator.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/MultiplayerSpectator.cs index 08b9938e79..e1af95b870 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/MultiplayerSpectator.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/MultiplayerSpectator.cs @@ -95,13 +95,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate protected override void StartGameplay(int userId, GameplayState gameplayState) { - int userIndex = getIndexForUser(userId); + var instance = instances[getIndexForUser(userId)]; + instance.LoadScore(gameplayState.Score); - var instance = instances[userIndex]; - syncManager.RemoveSlave(instance.GameplayClock); - leaderboard.RemoveClock(instance.UserId); - - instance.LoadPlayer(gameplayState.Score); syncManager.AddSlave(instance.GameplayClock); leaderboard.AddClock(instance.UserId, instance.GameplayClock); } diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/PlayerInstance.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/PlayerInstance.cs index 8c54fc9ec2..31d2d458df 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/PlayerInstance.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/PlayerInstance.cs @@ -1,10 +1,12 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; +using osu.Game.Graphics.UserInterface; using osu.Game.Scoring; using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate.Sync; using osu.Game.Screens.Play; @@ -23,6 +25,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate [Resolved] private BeatmapManager beatmapManager { get; set; } + private readonly Container content; + private readonly LoadingLayer loadingLayer; private OsuScreenStack stack; public PlayerInstance(int userId, SpectatorCatchUpSlaveClock gameplayClock) @@ -32,23 +36,29 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate RelativeSizeAxes = Axes.Both; Masking = true; + + InternalChildren = new Drawable[] + { + content = new DrawSizePreservingFillContainer { RelativeSizeAxes = Axes.Both }, + loadingLayer = new LoadingLayer(true) { State = { Value = Visibility.Visible } } + }; } - public void LoadPlayer(Score score) + public void LoadScore(Score score) { + if (Score != null) + throw new InvalidOperationException($"Cannot load a new score on a {nameof(PlayerInstance)} with an existing score."); + Score = score; - InternalChild = new GameplayIsolationContainer(beatmapManager.GetWorkingBeatmap(Score.ScoreInfo.Beatmap, bypassCache: true), Score.ScoreInfo.Ruleset, Score.ScoreInfo.Mods) + content.Child = new GameplayIsolationContainer(beatmapManager.GetWorkingBeatmap(Score.ScoreInfo.Beatmap, bypassCache: true), Score.ScoreInfo.Ruleset, Score.ScoreInfo.Mods) { RelativeSizeAxes = Axes.Both, - Child = new DrawSizePreservingFillContainer - { - RelativeSizeAxes = Axes.Both, - Child = stack = new OsuScreenStack() - } + Child = stack = new OsuScreenStack() }; stack.Push(new MultiplayerSpectatorPlayerLoader(Score, () => new MultiplayerSpectatorPlayer(Score, GameplayClock))); + loadingLayer.Hide(); } // Player interferes with global input, so disable input for now.