1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 16:07:24 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/PlayerInstance.cs

69 lines
2.4 KiB
C#
Raw Normal View History

// 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.
2021-04-16 12:28:32 +08:00
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
2021-04-16 12:28:32 +08:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Scoring;
using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate.Sync;
using osu.Game.Screens.Play;
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
{
public class PlayerInstance : CompositeDrawable
{
public bool PlayerLoaded => stack?.CurrentScreen is Player;
public readonly int UserId;
public readonly SpectatorCatchUpSlaveClock GameplayClock;
public Score Score { get; private set; }
[Resolved]
private BeatmapManager beatmapManager { get; set; }
2021-04-13 21:10:35 +08:00
2021-04-16 12:28:32 +08:00
private readonly Container content;
private readonly LoadingLayer loadingLayer;
private OsuScreenStack stack;
public PlayerInstance(int userId, SpectatorCatchUpSlaveClock gameplayClock)
{
UserId = userId;
GameplayClock = gameplayClock;
2021-04-08 21:13:54 +08:00
RelativeSizeAxes = Axes.Both;
Masking = true;
2021-04-16 12:28:32 +08:00
InternalChildren = new Drawable[]
{
content = new DrawSizePreservingFillContainer { RelativeSizeAxes = Axes.Both },
loadingLayer = new LoadingLayer(true) { State = { Value = Visibility.Visible } }
};
}
2021-04-16 12:28:32 +08:00
public void LoadScore(Score score)
{
2021-04-16 12:28:32 +08:00
if (Score != null)
throw new InvalidOperationException($"Cannot load a new score on a {nameof(PlayerInstance)} with an existing score.");
Score = score;
2021-04-16 12:28:32 +08:00
content.Child = new GameplayIsolationContainer(beatmapManager.GetWorkingBeatmap(Score.ScoreInfo.Beatmap, bypassCache: true), Score.ScoreInfo.Ruleset, Score.ScoreInfo.Mods)
{
RelativeSizeAxes = Axes.Both,
2021-04-16 12:28:32 +08:00
Child = stack = new OsuScreenStack()
};
stack.Push(new MultiplayerSpectatorPlayerLoader(Score, () => new MultiplayerSpectatorPlayer(Score, GameplayClock)));
2021-04-16 12:28:32 +08:00
loadingLayer.Hide();
}
2021-04-13 19:52:20 +08:00
// Player interferes with global input, so disable input for now.
public override bool PropagatePositionalInputSubTree => false;
public override bool PropagateNonPositionalInputSubTree => false;
}
}