2021-12-24 05:23:09 +00:00
|
|
|
// 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.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2021-12-24 05:23:09 +00:00
|
|
|
using System;
|
2022-04-28 11:10:47 +00:00
|
|
|
using System.Threading.Tasks;
|
2022-04-21 13:55:13 +00:00
|
|
|
using osu.Framework.Allocation;
|
2022-04-28 11:10:47 +00:00
|
|
|
using osu.Framework.Logging;
|
2021-12-24 05:23:09 +00:00
|
|
|
using osu.Framework.Screens;
|
2022-04-21 13:55:13 +00:00
|
|
|
using osu.Game.Online.Multiplayer;
|
2021-12-24 05:23:09 +00:00
|
|
|
using osu.Game.Screens.Play;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|
|
|
{
|
2022-11-24 05:32:20 +00:00
|
|
|
public partial class MultiplayerPlayerLoader : PlayerLoader
|
2021-12-24 05:23:09 +00:00
|
|
|
{
|
2022-01-25 16:45:11 +00:00
|
|
|
public bool GameplayPassed => player?.GameplayState.HasPassed == true;
|
2021-12-24 05:23:09 +00:00
|
|
|
|
2022-04-21 13:55:13 +00:00
|
|
|
[Resolved]
|
|
|
|
private MultiplayerClient multiplayerClient { get; set; }
|
|
|
|
|
2021-12-24 05:23:09 +00:00
|
|
|
private Player player;
|
|
|
|
|
|
|
|
public MultiplayerPlayerLoader(Func<Player> createPlayer)
|
|
|
|
: base(createPlayer)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-04-21 13:55:13 +00:00
|
|
|
protected override bool ReadyForGameplay =>
|
2022-05-26 11:01:33 +00:00
|
|
|
(
|
|
|
|
// The user is ready to enter gameplay.
|
|
|
|
base.ReadyForGameplay
|
|
|
|
// And the server has received the message that we're loaded.
|
|
|
|
&& multiplayerClient.LocalUser?.State == MultiplayerUserState.Loaded
|
|
|
|
)
|
|
|
|
// Or the server is forcefully starting gameplay.
|
2022-04-21 13:55:13 +00:00
|
|
|
|| multiplayerClient.LocalUser?.State == MultiplayerUserState.Playing;
|
|
|
|
|
2022-04-28 11:10:47 +00:00
|
|
|
protected override void OnPlayerLoaded()
|
|
|
|
{
|
|
|
|
base.OnPlayerLoaded();
|
|
|
|
|
|
|
|
multiplayerClient.ChangeState(MultiplayerUserState.Loaded)
|
|
|
|
.ContinueWith(task => failAndBail(task.Exception?.Message ?? "Server error"), TaskContinuationOptions.NotOnRanToCompletion);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void failAndBail(string message = null)
|
|
|
|
{
|
|
|
|
if (!string.IsNullOrEmpty(message))
|
|
|
|
Logger.Log(message, LoggingTarget.Runtime, LogLevel.Important);
|
|
|
|
|
|
|
|
Schedule(() =>
|
|
|
|
{
|
|
|
|
if (this.IsCurrentScreen())
|
|
|
|
this.Exit();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-21 15:52:44 +00:00
|
|
|
public override void OnSuspending(ScreenTransitionEvent e)
|
2021-12-24 05:23:09 +00:00
|
|
|
{
|
2022-04-21 15:52:44 +00:00
|
|
|
base.OnSuspending(e);
|
|
|
|
player = (Player)e.Next;
|
2021-12-24 05:23:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|