mirror of
https://github.com/ppy/osu.git
synced 2025-01-07 20:42:54 +08:00
Improve reliability of exiting gameplay
This commit is contained in:
parent
59124faa48
commit
727335dcad
@ -15,6 +15,26 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private MultiplayerClient client { get; set; }
|
private MultiplayerClient client { get; set; }
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
client.RoomUpdated += onRoomUpdated;
|
||||||
|
onRoomUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onRoomUpdated()
|
||||||
|
{
|
||||||
|
if (client.Room == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Debug.Assert(client.LocalUser != null);
|
||||||
|
|
||||||
|
// If the user exits gameplay before score submission completes, we'll transition to idle when results has been prepared.
|
||||||
|
if (client.LocalUser.State == MultiplayerUserState.Results && this.IsCurrentScreen())
|
||||||
|
transitionFromResults();
|
||||||
|
}
|
||||||
|
|
||||||
public override void OnResuming(IScreen last)
|
public override void OnResuming(IScreen last)
|
||||||
{
|
{
|
||||||
base.OnResuming(last);
|
base.OnResuming(last);
|
||||||
@ -22,23 +42,27 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
if (client.Room == null)
|
if (client.Room == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!(last is MultiplayerPlayerLoader playerLoader))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// If gameplay wasn't finished, then we have a simple path back to the idle state by aborting gameplay.
|
||||||
|
if (!playerLoader.GameplayCompleted)
|
||||||
|
{
|
||||||
|
client.AbortGameplay();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If gameplay was completed and the user went all the way to results, we'll transition to idle here.
|
||||||
|
// Otherwise, the transition will happen in onRoomUpdated().
|
||||||
|
transitionFromResults();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void transitionFromResults()
|
||||||
|
{
|
||||||
Debug.Assert(client.LocalUser != null);
|
Debug.Assert(client.LocalUser != null);
|
||||||
|
|
||||||
switch (client.LocalUser.State)
|
if (client.LocalUser.State == MultiplayerUserState.Results)
|
||||||
{
|
|
||||||
case MultiplayerUserState.Spectating:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MultiplayerUserState.WaitingForLoad:
|
|
||||||
case MultiplayerUserState.Loaded:
|
|
||||||
case MultiplayerUserState.Playing:
|
|
||||||
client.AbortGameplay();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
client.ChangeState(MultiplayerUserState.Idle);
|
client.ChangeState(MultiplayerUserState.Idle);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string ScreenTitle => "Multiplayer";
|
protected override string ScreenTitle => "Multiplayer";
|
||||||
|
@ -30,7 +30,6 @@ using osu.Game.Screens.OnlinePlay.Multiplayer.Match;
|
|||||||
using osu.Game.Screens.OnlinePlay.Multiplayer.Match.Playlist;
|
using osu.Game.Screens.OnlinePlay.Multiplayer.Match.Playlist;
|
||||||
using osu.Game.Screens.OnlinePlay.Multiplayer.Participants;
|
using osu.Game.Screens.OnlinePlay.Multiplayer.Participants;
|
||||||
using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate;
|
using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate;
|
||||||
using osu.Game.Screens.Play;
|
|
||||||
using osu.Game.Screens.Play.HUD;
|
using osu.Game.Screens.Play.HUD;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
@ -478,7 +477,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
return new MultiSpectatorScreen(users.Take(PlayerGrid.MAX_PLAYERS).ToArray());
|
return new MultiSpectatorScreen(users.Take(PlayerGrid.MAX_PLAYERS).ToArray());
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return new PlayerLoader(() => new MultiplayerPlayer(Room, SelectedItem.Value, users));
|
return new MultiplayerPlayerLoader(() => new MultiplayerPlayer(Room, SelectedItem.Value, users));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
// 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 System;
|
||||||
|
using osu.Framework.Screens;
|
||||||
|
using osu.Game.Screens.Play;
|
||||||
|
|
||||||
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||||
|
{
|
||||||
|
public class MultiplayerPlayerLoader : PlayerLoader
|
||||||
|
{
|
||||||
|
public bool GameplayCompleted => player?.GameplayCompleted == true;
|
||||||
|
|
||||||
|
private Player player;
|
||||||
|
|
||||||
|
public MultiplayerPlayerLoader(Func<Player> createPlayer)
|
||||||
|
: base(createPlayer)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnSuspending(IScreen next)
|
||||||
|
{
|
||||||
|
base.OnSuspending(next);
|
||||||
|
player = (Player)next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -66,6 +66,11 @@ namespace osu.Game.Screens.Play
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual bool PauseOnFocusLost => true;
|
protected virtual bool PauseOnFocusLost => true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether gameplay has completed without the user having failed.
|
||||||
|
/// </summary>
|
||||||
|
public bool GameplayCompleted { get; private set; }
|
||||||
|
|
||||||
public Action RestartRequested;
|
public Action RestartRequested;
|
||||||
|
|
||||||
public bool HasFailed { get; private set; }
|
public bool HasFailed { get; private set; }
|
||||||
@ -675,6 +680,8 @@ namespace osu.Game.Screens.Play
|
|||||||
if (HealthProcessor.HasFailed)
|
if (HealthProcessor.HasFailed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
GameplayCompleted = true;
|
||||||
|
|
||||||
// Setting this early in the process means that even if something were to go wrong in the order of events following, there
|
// Setting this early in the process means that even if something were to go wrong in the order of events following, there
|
||||||
// is no chance that a user could return to the (already completed) Player instance from a child screen.
|
// is no chance that a user could return to the (already completed) Player instance from a child screen.
|
||||||
ValidForResume = false;
|
ValidForResume = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user