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.
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2024-02-28 19:03:09 +00:00
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2021-08-27 10:16:08 +00:00
|
|
|
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
|
|
|
|
{
|
|
|
|
public partial class SoloSpectatorPlayer : SpectatorPlayer
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2023-11-22 08:53:35 +00:00
|
|
|
public SoloSpectatorPlayer(Score score)
|
|
|
|
: base(score, new PlayerConfiguration { AllowUserInteraction = false })
|
2021-08-27 10:16:08 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
2024-02-28 19:03:09 +00:00
|
|
|
if (SpectatorClient.IsNotNull())
|
|
|
|
SpectatorClient.OnUserBeganPlaying -= userBeganPlaying;
|
2021-08-27 10:16:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|