mirror of
https://github.com/ppy/osu.git
synced 2026-06-03 22:54:23 +08:00
d0d5d97cfe
As mentioned in https://github.com/ppy/osu/discussions/36883. This has caught me off-guard a few times. Was a quick one to make this work like it does on stable. It doesn't fit as well as stable because we have a lot of elements at the top of the screen, but I think it's better than nothing, as it lets you know you're in a replay quick obviously. I don't think we can easily localise strings with formatting in them yet. Maybe using a `MarkdownContainer` or something?
129 lines
4.4 KiB
C#
129 lines
4.4 KiB
C#
// 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.Extensions.ObjectExtensions;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Screens;
|
|
using osu.Game.Beatmaps;
|
|
using osu.Game.Graphics;
|
|
using osu.Game.Graphics.Containers;
|
|
using osu.Game.Online.Spectator;
|
|
using osu.Game.Rulesets.Replays;
|
|
using osu.Game.Rulesets.Replays.Types;
|
|
using osu.Game.Scoring;
|
|
using osu.Game.Screens.Ranking;
|
|
|
|
namespace osu.Game.Screens.Play
|
|
{
|
|
public abstract partial class SpectatorPlayer : Player
|
|
{
|
|
[Resolved]
|
|
protected SpectatorClient SpectatorClient { get; private set; } = null!;
|
|
|
|
private readonly Score score;
|
|
|
|
protected SpectatorPlayer(Score score, PlayerConfiguration? configuration = null)
|
|
: base(configuration)
|
|
{
|
|
this.score = score;
|
|
}
|
|
|
|
protected override Drawable CreateOverlayComponents()
|
|
{
|
|
// TODO: This should be customised for `MultiplayerSpectatorPlayer` to be static and only show the player name.
|
|
// Or maybe we should completely redesign this to show the user avatar and other things if that happens.
|
|
OsuTextFlowContainer message = new OsuTextFlowContainer(cp => cp.Font = OsuFont.Style.Body) { AutoSizeAxes = Axes.Both };
|
|
message.AddText("Watching ");
|
|
message.AddText(Score.ScoreInfo.User.Username, s => s.Font = s.Font.With(weight: FontWeight.SemiBold));
|
|
message.AddText(" play ");
|
|
message.AddText(Beatmap.Value.BeatmapInfo.GetDisplayTitleRomanisable(), s => s.Font = s.Font.With(weight: FontWeight.SemiBold));
|
|
message.AddText(" live", s => s.Font = s.Font.With(weight: FontWeight.Bold));
|
|
|
|
return new ScrollingMessage(message)
|
|
{
|
|
Y = 100,
|
|
Anchor = Anchor.TopCentre,
|
|
Origin = Anchor.TopCentre,
|
|
};
|
|
}
|
|
|
|
protected override void LoadComplete()
|
|
{
|
|
base.LoadComplete();
|
|
|
|
DrawableRuleset.FrameStableClock.WaitingOnFrames.BindValueChanged(waiting =>
|
|
{
|
|
if (GameplayClockContainer is MasterGameplayClockContainer master)
|
|
{
|
|
if (master.UserPlaybackRate.Value > 1 && waiting.NewValue)
|
|
master.UserPlaybackRate.Value = 1;
|
|
}
|
|
}, true);
|
|
}
|
|
|
|
protected override void StartGameplay()
|
|
{
|
|
base.StartGameplay();
|
|
|
|
// Start gameplay along with the very first arrival frame (the latest one).
|
|
score.Replay.Frames.Clear();
|
|
SpectatorClient.OnNewFrames += userSentFrames;
|
|
}
|
|
|
|
private void userSentFrames(int userId, FrameDataBundle bundle)
|
|
{
|
|
if (userId != score.ScoreInfo.User.OnlineID)
|
|
return;
|
|
|
|
if (!LoadedBeatmapSuccessfully)
|
|
return;
|
|
|
|
if (!this.IsCurrentScreen())
|
|
return;
|
|
|
|
bool isFirstBundle = score.Replay.Frames.Count == 0;
|
|
|
|
foreach (var frame in bundle.Frames)
|
|
{
|
|
IConvertibleReplayFrame convertibleFrame = GameplayState.Ruleset.CreateConvertibleReplayFrame()!;
|
|
convertibleFrame.FromLegacy(frame, GameplayState.Beatmap);
|
|
|
|
var convertedFrame = (ReplayFrame)convertibleFrame;
|
|
convertedFrame.Time = frame.Time;
|
|
convertedFrame.Header = frame.Header;
|
|
|
|
score.Replay.Frames.Add(convertedFrame);
|
|
}
|
|
|
|
if (isFirstBundle && score.Replay.Frames.Count > 0)
|
|
SetGameplayStartTime(score.Replay.Frames[0].Time);
|
|
}
|
|
|
|
protected override Score CreateScore(IBeatmap beatmap) => score;
|
|
|
|
protected override ResultsScreen CreateResults(ScoreInfo score)
|
|
=> new SpectatorResultsScreen(score);
|
|
|
|
protected override void PrepareReplay()
|
|
{
|
|
DrawableRuleset?.SetReplayScore(score);
|
|
}
|
|
|
|
public override bool OnExiting(ScreenExitEvent e)
|
|
{
|
|
SpectatorClient.OnNewFrames -= userSentFrames;
|
|
|
|
return base.OnExiting(e);
|
|
}
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
{
|
|
base.Dispose(isDisposing);
|
|
|
|
if (SpectatorClient.IsNotNull())
|
|
SpectatorClient.OnNewFrames -= userSentFrames;
|
|
}
|
|
}
|
|
}
|