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;
|
2023-02-06 07:58:08 +08:00
|
|
|
using osu.Game.Users;
|
2021-08-27 18:16:08 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
{
|
|
|
|
public partial class SoloSpectatorPlayer : SpectatorPlayer
|
|
|
|
{
|
|
|
|
private readonly Score score;
|
|
|
|
|
2023-02-13 04:32:17 +08:00
|
|
|
protected override UserActivity InitialActivity => new UserActivity.SpectatingUser(Score.ScoreInfo);
|
2023-02-06 07:58:08 +08:00
|
|
|
|
2023-11-22 16:53:35 +08:00
|
|
|
public SoloSpectatorPlayer(Score score)
|
|
|
|
: base(score, new PlayerConfiguration { AllowUserInteraction = false })
|
2021-08-27 18:16:08 +08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|