1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 09:32:55 +08:00

Remove implicit schedule of abstract methods in SpectatorScreen

This allows each implementation to have control over scheduling. Without
this, the solo implementation would not be able to handle quit events
while watching a player, as it would push a child (gameplay) screen to
the stack where the `SpectatorScreen` would usually be.
This commit is contained in:
Dean Herbert 2023-11-24 14:21:52 +09:00
parent 73ad92189b
commit b024065857
No known key found for this signature in database
3 changed files with 24 additions and 15 deletions

View File

@ -228,7 +228,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
{
}
protected override void StartGameplay(int userId, SpectatorGameplayState spectatorGameplayState)
protected override void StartGameplay(int userId, SpectatorGameplayState spectatorGameplayState) => Schedule(() =>
{
var playerArea = instances.Single(i => i.UserId == userId);
@ -242,9 +242,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
return;
playerArea.LoadScore(spectatorGameplayState.Score);
}
});
protected override void QuitGameplay(int userId)
protected override void QuitGameplay(int userId) => Schedule(() =>
{
RemoveUser(userId);
@ -252,7 +252,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
instance.FadeColour(colours.Gray4, 400, Easing.OutQuint);
syncManager.RemoveManagedClock(instance.SpectatorPlayerClock);
}
});
public override bool OnBackButton()
{

View File

@ -164,27 +164,33 @@ namespace osu.Game.Screens.Play
automaticDownload.Current.BindValueChanged(_ => checkForAutomaticDownload());
}
protected override void OnNewPlayingUserState(int userId, SpectatorState spectatorState)
protected override void OnNewPlayingUserState(int userId, SpectatorState spectatorState) => Schedule(() =>
{
clearDisplay();
showBeatmapPanel(spectatorState);
}
});
protected override void StartGameplay(int userId, SpectatorGameplayState spectatorGameplayState)
protected override void StartGameplay(int userId, SpectatorGameplayState spectatorGameplayState) => Schedule(() =>
{
immediateSpectatorGameplayState = spectatorGameplayState;
watchButton.Enabled.Value = true;
scheduleStart(spectatorGameplayState);
}
});
protected override void QuitGameplay(int userId)
{
scheduledStart?.Cancel();
immediateSpectatorGameplayState = null;
watchButton.Enabled.Value = false;
// Importantly, don't schedule this call, as a child screen may be present (and will cause the schedule to not be run as expected).
this.MakeCurrent();
clearDisplay();
Schedule(() =>
{
scheduledStart?.Cancel();
immediateSpectatorGameplayState = null;
watchButton.Enabled.Value = false;
clearDisplay();
});
}
private void clearDisplay()

View File

@ -129,7 +129,7 @@ namespace osu.Game.Screens.Spectate
switch (newState.State)
{
case SpectatedUserState.Playing:
Schedule(() => OnNewPlayingUserState(userId, newState));
OnNewPlayingUserState(userId, newState);
startGameplay(userId);
break;
@ -173,7 +173,7 @@ namespace osu.Game.Screens.Spectate
var gameplayState = new SpectatorGameplayState(score, resolvedRuleset, beatmaps.GetWorkingBeatmap(resolvedBeatmap));
gameplayStates[userId] = gameplayState;
Schedule(() => StartGameplay(userId, gameplayState));
StartGameplay(userId, gameplayState);
}
/// <summary>
@ -196,11 +196,12 @@ namespace osu.Game.Screens.Spectate
markReceivedAllFrames(userId);
gameplayStates.Remove(userId);
Schedule(() => QuitGameplay(userId));
QuitGameplay(userId);
}
/// <summary>
/// Invoked when a spectated user's state has changed to a new state indicating the player is currently playing.
/// Thread safety is not guaranteed should be scheduled as required.
/// </summary>
/// <param name="userId">The user whose state has changed.</param>
/// <param name="spectatorState">The new state.</param>
@ -208,6 +209,7 @@ namespace osu.Game.Screens.Spectate
/// <summary>
/// Starts gameplay for a user.
/// Thread safety is not guaranteed should be scheduled as required.
/// </summary>
/// <param name="userId">The user to start gameplay for.</param>
/// <param name="spectatorGameplayState">The gameplay state.</param>
@ -215,6 +217,7 @@ namespace osu.Game.Screens.Spectate
/// <summary>
/// Quits gameplay for a user.
/// Thread safety is not guaranteed should be scheduled as required.
/// </summary>
/// <param name="userId">The user to quit gameplay for.</param>
protected abstract void QuitGameplay(int userId);