mirror of
https://github.com/osukey/osukey.git
synced 2025-08-07 08:33:55 +09:00
Schedule spectator callbacks
This commit is contained in:
@ -9,6 +9,7 @@ using osu.Framework.Graphics.Containers;
|
|||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.Screens;
|
using osu.Framework.Screens;
|
||||||
|
using osu.Framework.Threading;
|
||||||
using osu.Game.Audio;
|
using osu.Game.Audio;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
@ -53,15 +54,10 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The player's immediate online gameplay state.
|
/// The player's immediate online gameplay state.
|
||||||
/// This doesn't reflect the gameplay state being watched by the user if <see cref="pendingGameplayState"/> is non-null.
|
/// This doesn't always reflect the gameplay state being watched.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private GameplayState immediateGameplayState;
|
private GameplayState immediateGameplayState;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The gameplay state that is pending to be watched, upon this screen becoming current.
|
|
||||||
/// </summary>
|
|
||||||
private GameplayState pendingGameplayState;
|
|
||||||
|
|
||||||
private GetBeatmapSetRequest onlineBeatmapRequest;
|
private GetBeatmapSetRequest onlineBeatmapRequest;
|
||||||
|
|
||||||
public SoloSpectator([NotNull] User targetUser)
|
public SoloSpectator([NotNull] User targetUser)
|
||||||
@ -150,7 +146,7 @@ namespace osu.Game.Screens.Play
|
|||||||
Width = 250,
|
Width = 250,
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Action = () => attemptStart(immediateGameplayState),
|
Action = () => scheduleStart(immediateGameplayState),
|
||||||
Enabled = { Value = false }
|
Enabled = { Value = false }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -165,44 +161,27 @@ namespace osu.Game.Screens.Play
|
|||||||
automaticDownload.Current.BindValueChanged(_ => checkForAutomaticDownload());
|
automaticDownload.Current.BindValueChanged(_ => checkForAutomaticDownload());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnUserStateChanged(int userId, SpectatorState spectatorState) => Schedule(() =>
|
protected override void OnUserStateChanged(int userId, SpectatorState spectatorState)
|
||||||
{
|
{
|
||||||
clearDisplay();
|
clearDisplay();
|
||||||
showBeatmapPanel(spectatorState);
|
showBeatmapPanel(spectatorState);
|
||||||
});
|
}
|
||||||
|
|
||||||
protected override void StartGameplay(int userId, GameplayState gameplayState) => Schedule(() =>
|
protected override void StartGameplay(int userId, GameplayState gameplayState)
|
||||||
{
|
{
|
||||||
pendingGameplayState = null;
|
|
||||||
immediateGameplayState = gameplayState;
|
immediateGameplayState = gameplayState;
|
||||||
|
|
||||||
if (this.IsCurrentScreen())
|
|
||||||
attemptStart(gameplayState);
|
|
||||||
else
|
|
||||||
pendingGameplayState = gameplayState;
|
|
||||||
|
|
||||||
watchButton.Enabled.Value = true;
|
watchButton.Enabled.Value = true;
|
||||||
});
|
|
||||||
|
|
||||||
protected override void EndGameplay(int userId) => Schedule(() =>
|
scheduleStart(gameplayState);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void EndGameplay(int userId)
|
||||||
{
|
{
|
||||||
pendingGameplayState = null;
|
scheduledStart?.Cancel();
|
||||||
immediateGameplayState = null;
|
immediateGameplayState = null;
|
||||||
|
|
||||||
Schedule(clearDisplay);
|
|
||||||
|
|
||||||
watchButton.Enabled.Value = false;
|
watchButton.Enabled.Value = false;
|
||||||
});
|
|
||||||
|
|
||||||
public override void OnResuming(IScreen last)
|
clearDisplay();
|
||||||
{
|
|
||||||
base.OnResuming(last);
|
|
||||||
|
|
||||||
if (pendingGameplayState != null)
|
|
||||||
{
|
|
||||||
attemptStart(pendingGameplayState);
|
|
||||||
pendingGameplayState = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearDisplay()
|
private void clearDisplay()
|
||||||
@ -213,15 +192,27 @@ namespace osu.Game.Screens.Play
|
|||||||
previewTrackManager.StopAnyPlaying(this);
|
previewTrackManager.StopAnyPlaying(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void attemptStart(GameplayState gameplayState)
|
private ScheduledDelegate scheduledStart;
|
||||||
|
|
||||||
|
private void scheduleStart(GameplayState gameplayState)
|
||||||
{
|
{
|
||||||
if (gameplayState == null)
|
// This function may be called multiple times in quick succession once the screen becomes current again.
|
||||||
return;
|
scheduledStart?.Cancel();
|
||||||
|
scheduledStart = Schedule(() =>
|
||||||
|
{
|
||||||
|
if (this.IsCurrentScreen())
|
||||||
|
start();
|
||||||
|
else
|
||||||
|
scheduleStart(gameplayState);
|
||||||
|
});
|
||||||
|
|
||||||
Beatmap.Value = gameplayState.Beatmap;
|
void start()
|
||||||
Ruleset.Value = gameplayState.Ruleset.RulesetInfo;
|
{
|
||||||
|
Beatmap.Value = gameplayState.Beatmap;
|
||||||
|
Ruleset.Value = gameplayState.Ruleset.RulesetInfo;
|
||||||
|
|
||||||
this.Push(new SpectatorPlayerLoader(gameplayState.Score));
|
this.Push(new SpectatorPlayerLoader(gameplayState.Score));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showBeatmapPanel(SpectatorState state)
|
private void showBeatmapPanel(SpectatorState state)
|
||||||
|
@ -110,7 +110,7 @@ namespace osu.Game.Screens.Spectate
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
spectatorStates[userId] = state;
|
spectatorStates[userId] = state;
|
||||||
OnUserStateChanged(userId, state);
|
Schedule(() => OnUserStateChanged(userId, state));
|
||||||
|
|
||||||
updateGameplayState(userId);
|
updateGameplayState(userId);
|
||||||
}
|
}
|
||||||
@ -148,7 +148,7 @@ namespace osu.Game.Screens.Spectate
|
|||||||
var gameplayState = new GameplayState(score, resolvedRuleset, beatmaps.GetWorkingBeatmap(resolvedBeatmap));
|
var gameplayState = new GameplayState(score, resolvedRuleset, beatmaps.GetWorkingBeatmap(resolvedBeatmap));
|
||||||
|
|
||||||
gameplayStates[userId] = gameplayState;
|
gameplayStates[userId] = gameplayState;
|
||||||
StartGameplay(userId, gameplayState);
|
Schedule(() => StartGameplay(userId, gameplayState));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,7 +191,7 @@ namespace osu.Game.Screens.Spectate
|
|||||||
gameplayState.Score.Replay.HasReceivedAllFrames = true;
|
gameplayState.Score.Replay.HasReceivedAllFrames = true;
|
||||||
|
|
||||||
gameplayStates.Remove(userId);
|
gameplayStates.Remove(userId);
|
||||||
EndGameplay(userId);
|
Schedule(() => EndGameplay(userId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user