2021-08-27 10:16:08 +00: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 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2021-08-27 10:16:08 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Screens;
|
|
|
|
using osu.Game.Online.Spectator;
|
|
|
|
using osu.Game.Scoring;
|
2023-02-05 23:58:08 +00:00
|
|
|
using osu.Game.Users;
|
2021-08-27 10:16:08 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
{
|
2022-11-24 05:32:20 +00:00
|
|
|
public partial class SoloSpectatorPlayer : SpectatorPlayer
|
2021-08-27 10:16:08 +00:00
|
|
|
{
|
|
|
|
private readonly Score score;
|
|
|
|
|
2023-02-12 20:32:17 +00:00
|
|
|
protected override UserActivity InitialActivity => new UserActivity.SpectatingUser(Score.ScoreInfo);
|
2023-02-05 23:58:08 +00:00
|
|
|
|
2021-08-27 10:16:08 +00:00
|
|
|
public SoloSpectatorPlayer(Score score, PlayerConfiguration configuration = null)
|
|
|
|
: base(score, configuration)
|
|
|
|
{
|
|
|
|
this.score = score;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
SpectatorClient.OnUserBeganPlaying += userBeganPlaying;
|
|
|
|
}
|
|
|
|
|
2022-04-21 15:52:44 +00:00
|
|
|
public override bool OnExiting(ScreenExitEvent e)
|
2021-08-27 10:16:08 +00:00
|
|
|
{
|
|
|
|
SpectatorClient.OnUserBeganPlaying -= userBeganPlaying;
|
|
|
|
|
2022-04-21 15:52:44 +00:00
|
|
|
return base.OnExiting(e);
|
2021-08-27 10:16:08 +00: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|