Use single method for starting/restarting spectator screen

This commit is contained in:
smoogipoo
2021-04-26 21:55:38 +09:00
parent 7e11d520d5
commit ed93e26e52
3 changed files with 20 additions and 20 deletions

View File

@ -21,7 +21,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
{
base.OnResuming(last);
if (client.Room != null)
if (client.Room != null && client.LocalUser?.State != MultiplayerUserState.Spectating)
client.ChangeState(MultiplayerUserState.Idle);
}

View File

@ -406,29 +406,22 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
}
}
private void onRoomUpdated() => Scheduler.Add(() =>
private void onRoomUpdated()
{
if (client.Room == null)
return;
Debug.Assert(client.LocalUser != null);
UpdateMods();
if (client.LocalUser.State == MultiplayerUserState.Spectating
&& (client.Room.State == MultiplayerRoomState.Playing || client.Room.State == MultiplayerRoomState.WaitingForLoad)
&& ParentScreen.IsCurrentScreen())
{
StartPlay();
// If the current user was host, they started the match and the in-progress operation needs to be stopped now.
readyClickOperation?.Dispose();
readyClickOperation = null;
}
});
Scheduler.AddOnce(UpdateMods);
}
private void onLoadRequested()
{
// If the user is spectating, the multi-spectator screen may still be the current screen.
if (!ParentScreen.IsCurrentScreen())
{
ParentScreen.MakeCurrent();
Schedule(onLoadRequested);
return;
}
StartPlay();
readyClickOperation?.Dispose();

View File

@ -140,6 +140,13 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
leaderboard.RemoveClock(userId);
}
public override bool OnBackButton()
{
// On a manual exit, set the player state back to idle.
multiplayerClient.ChangeState(MultiplayerUserState.Idle);
return base.OnBackButton();
}
private int getIndexForUser(int userId) => Array.IndexOf(userIds, userId);
}
}