mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 13:32:54 +08:00
Separate solo spectator player and "exit on restart" logic to own class
This commit is contained in:
parent
1650fbb8be
commit
378734a7f8
@ -211,7 +211,7 @@ namespace osu.Game.Screens.Play
|
|||||||
Beatmap.Value = gameplayState.Beatmap;
|
Beatmap.Value = gameplayState.Beatmap;
|
||||||
Ruleset.Value = gameplayState.Ruleset.RulesetInfo;
|
Ruleset.Value = gameplayState.Ruleset.RulesetInfo;
|
||||||
|
|
||||||
this.Push(new SpectatorPlayerLoader(gameplayState.Score));
|
this.Push(new SpectatorPlayerLoader(gameplayState.Score, () => new SoloSpectatorPlayer(gameplayState.Score)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
52
osu.Game/Screens/Play/SoloSpectatorPlayer.cs
Normal file
52
osu.Game/Screens/Play/SoloSpectatorPlayer.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
// 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;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool OnExiting(IScreen next)
|
||||||
|
{
|
||||||
|
SpectatorClient.OnUserBeganPlaying -= userBeganPlaying;
|
||||||
|
|
||||||
|
return base.OnExiting(next);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -14,16 +14,16 @@ using osu.Game.Screens.Ranking;
|
|||||||
|
|
||||||
namespace osu.Game.Screens.Play
|
namespace osu.Game.Screens.Play
|
||||||
{
|
{
|
||||||
public class SpectatorPlayer : Player
|
public abstract class SpectatorPlayer : Player
|
||||||
{
|
{
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private SpectatorClient spectatorClient { get; set; }
|
protected SpectatorClient SpectatorClient { get; private set; }
|
||||||
|
|
||||||
private readonly Score score;
|
private readonly Score score;
|
||||||
|
|
||||||
protected override bool CheckModsAllowFailure() => false; // todo: better support starting mid-way through beatmap
|
protected override bool CheckModsAllowFailure() => false; // todo: better support starting mid-way through beatmap
|
||||||
|
|
||||||
public SpectatorPlayer(Score score, PlayerConfiguration configuration = null)
|
protected SpectatorPlayer(Score score, PlayerConfiguration configuration = null)
|
||||||
: base(configuration)
|
: base(configuration)
|
||||||
{
|
{
|
||||||
this.score = score;
|
this.score = score;
|
||||||
@ -32,8 +32,6 @@ namespace osu.Game.Screens.Play
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
spectatorClient.OnUserBeganPlaying += userBeganPlaying;
|
|
||||||
|
|
||||||
AddInternal(new OsuSpriteText
|
AddInternal(new OsuSpriteText
|
||||||
{
|
{
|
||||||
Text = $"Watching {score.ScoreInfo.User.Username} playing live!",
|
Text = $"Watching {score.ScoreInfo.User.Username} playing live!",
|
||||||
@ -50,7 +48,7 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
// Start gameplay along with the very first arrival frame (the latest one).
|
// Start gameplay along with the very first arrival frame (the latest one).
|
||||||
score.Replay.Frames.Clear();
|
score.Replay.Frames.Clear();
|
||||||
spectatorClient.OnNewFrames += userSentFrames;
|
SpectatorClient.OnNewFrames += userSentFrames;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void userSentFrames(int userId, FrameDataBundle bundle)
|
private void userSentFrames(int userId, FrameDataBundle bundle)
|
||||||
@ -93,31 +91,17 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
public override bool OnExiting(IScreen next)
|
public override bool OnExiting(IScreen next)
|
||||||
{
|
{
|
||||||
spectatorClient.OnUserBeganPlaying -= userBeganPlaying;
|
SpectatorClient.OnNewFrames -= userSentFrames;
|
||||||
spectatorClient.OnNewFrames -= userSentFrames;
|
|
||||||
|
|
||||||
return base.OnExiting(next);
|
return base.OnExiting(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
|
|
||||||
if (spectatorClient != null)
|
if (SpectatorClient != null)
|
||||||
{
|
SpectatorClient.OnNewFrames -= userSentFrames;
|
||||||
spectatorClient.OnUserBeganPlaying -= userBeganPlaying;
|
|
||||||
spectatorClient.OnNewFrames -= userSentFrames;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,7 @@ namespace osu.Game.Screens.Play
|
|||||||
{
|
{
|
||||||
public readonly ScoreInfo Score;
|
public readonly ScoreInfo Score;
|
||||||
|
|
||||||
public SpectatorPlayerLoader(Score score)
|
public SpectatorPlayerLoader(Score score, Func<SpectatorPlayer> createPlayer)
|
||||||
: this(score, () => new SpectatorPlayer(score))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public SpectatorPlayerLoader(Score score, Func<Player> createPlayer)
|
|
||||||
: base(createPlayer)
|
: base(createPlayer)
|
||||||
{
|
{
|
||||||
if (score.Replay == null)
|
if (score.Replay == null)
|
||||||
|
Loading…
Reference in New Issue
Block a user