2020-12-20 22:32:57 +08: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.
|
|
|
|
|
|
2021-12-14 10:30:42 +08:00
|
|
|
|
using System.Diagnostics;
|
2020-12-20 22:32:57 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2023-06-23 23:59:36 +08:00
|
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2022-04-21 21:55:13 +08:00
|
|
|
|
using osu.Framework.Logging;
|
2020-12-20 22:32:57 +08:00
|
|
|
|
using osu.Framework.Screens;
|
|
|
|
|
using osu.Game.Online.Multiplayer;
|
2023-10-03 07:31:30 +08:00
|
|
|
|
using osu.Game.Online.Rooms;
|
2020-12-25 23:50:00 +08:00
|
|
|
|
using osu.Game.Screens.OnlinePlay.Components;
|
|
|
|
|
using osu.Game.Screens.OnlinePlay.Lounge;
|
2020-12-20 22:32:57 +08:00
|
|
|
|
|
2020-12-25 23:50:00 +08:00
|
|
|
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
2020-12-20 22:32:57 +08:00
|
|
|
|
{
|
2020-12-26 00:00:00 +08:00
|
|
|
|
public partial class Multiplayer : OnlinePlayScreen
|
2020-12-20 22:32:57 +08:00
|
|
|
|
{
|
|
|
|
|
[Resolved]
|
2021-05-20 14:39:45 +08:00
|
|
|
|
private MultiplayerClient client { get; set; } = null!;
|
2020-12-20 22:32:57 +08:00
|
|
|
|
|
2021-12-24 13:23:09 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
client.RoomUpdated += onRoomUpdated;
|
2022-04-21 21:55:13 +08:00
|
|
|
|
client.LoadAborted += onLoadAborted;
|
2021-12-24 13:23:09 +08:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-21 21:55:13 +08:00
|
|
|
|
private void onLoadAborted()
|
|
|
|
|
{
|
|
|
|
|
// If the server aborts gameplay for this user (due to loading too slow), exit gameplay screens.
|
|
|
|
|
if (!this.IsCurrentScreen())
|
|
|
|
|
{
|
|
|
|
|
Logger.Log("Gameplay aborted because loading the beatmap took too long.", LoggingTarget.Runtime, LogLevel.Important);
|
|
|
|
|
this.MakeCurrent();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-21 23:52:44 +08:00
|
|
|
|
public override void OnResuming(ScreenTransitionEvent e)
|
2020-12-20 22:32:57 +08:00
|
|
|
|
{
|
2022-04-21 23:52:44 +08:00
|
|
|
|
base.OnResuming(e);
|
2020-12-20 22:32:57 +08:00
|
|
|
|
|
2021-12-14 10:30:42 +08:00
|
|
|
|
if (client.Room == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-04-21 21:55:13 +08:00
|
|
|
|
Debug.Assert(client.LocalUser != null);
|
|
|
|
|
|
2022-04-21 23:52:44 +08:00
|
|
|
|
if (!(e.Last is MultiplayerPlayerLoader playerLoader))
|
2021-12-24 13:23:09 +08:00
|
|
|
|
return;
|
2021-12-14 10:30:42 +08:00
|
|
|
|
|
2022-04-21 21:55:13 +08:00
|
|
|
|
// Nothing needs to be done if already in the idle state (e.g. via load being aborted by the server).
|
|
|
|
|
if (client.LocalUser.State == MultiplayerUserState.Idle)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-12-24 13:23:09 +08:00
|
|
|
|
// If gameplay wasn't finished, then we have a simple path back to the idle state by aborting gameplay.
|
2021-12-24 20:58:20 +08:00
|
|
|
|
if (!playerLoader.GameplayPassed)
|
2021-12-14 10:30:42 +08:00
|
|
|
|
{
|
2022-03-30 22:58:30 +08:00
|
|
|
|
client.AbortGameplay().FireAndForget();
|
2021-12-24 13:23:09 +08:00
|
|
|
|
return;
|
2021-12-14 10:30:42 +08:00
|
|
|
|
}
|
2021-12-24 13:23:09 +08:00
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
|
|
if (client.LocalUser.State == MultiplayerUserState.Results)
|
|
|
|
|
client.ChangeState(MultiplayerUserState.Idle);
|
2020-12-20 22:32:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-24 23:18:35 +08:00
|
|
|
|
protected override string ScreenTitle => "Multiplayer";
|
|
|
|
|
|
2020-12-25 12:38:11 +08:00
|
|
|
|
protected override RoomManager CreateRoomManager() => new MultiplayerRoomManager();
|
2020-12-20 22:36:56 +08:00
|
|
|
|
|
2020-12-25 12:38:11 +08:00
|
|
|
|
protected override LoungeSubScreen CreateLounge() => new MultiplayerLoungeSubScreen();
|
2021-12-24 20:57:29 +08:00
|
|
|
|
|
2023-10-12 16:42:02 +08:00
|
|
|
|
public void Join(Room room, string? password) => Schedule(() => Lounge.Join(room, password));
|
2023-10-03 07:31:30 +08:00
|
|
|
|
|
2021-12-24 20:57:29 +08:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
2023-06-23 23:59:36 +08:00
|
|
|
|
if (client.IsNotNull())
|
2021-12-24 20:57:29 +08:00
|
|
|
|
client.RoomUpdated -= onRoomUpdated;
|
|
|
|
|
}
|
2020-12-20 22:32:57 +08:00
|
|
|
|
}
|
|
|
|
|
}
|