2021-08-27 18:16:08 +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
|
|
|
|
|
2021-08-27 18:16:08 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Screens;
|
|
|
|
using osu.Game.Online.Spectator;
|
|
|
|
using osu.Game.Scoring;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
{
|
|
|
|
public class SoloSpectatorPlayer : SpectatorPlayer
|
|
|
|
{
|
|
|
|
private readonly Score score;
|
|
|
|
|
|
|
|
public SoloSpectatorPlayer(Score score, PlayerConfiguration configuration = null)
|
|
|
|
: base(score, configuration)
|
|
|
|
{
|
|
|
|
this.score = score;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
SpectatorClient.OnUserBeganPlaying += userBeganPlaying;
|
|
|
|
}
|
|
|
|
|
2022-04-21 23:52:44 +08:00
|
|
|
public override bool OnExiting(ScreenExitEvent e)
|
2021-08-27 18:16:08 +08:00
|
|
|
{
|
|
|
|
SpectatorClient.OnUserBeganPlaying -= userBeganPlaying;
|
|
|
|
|
2022-04-21 23:52:44 +08:00
|
|
|
return base.OnExiting(e);
|
2021-08-27 18:16:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void userBeganPlaying(int userId, SpectatorState state)
|
|
|
|
{
|
|
|
|
if (userId != score.ScoreInfo.UserID) return;
|
|
|
|
|
|
|
|
Schedule(() =>
|
|
|
|
{
|
|
|
|
if (this.IsCurrentScreen()) this.Exit();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
|
|
if (SpectatorClient != null)
|
|
|
|
SpectatorClient.OnUserBeganPlaying -= userBeganPlaying;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|