1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 04:22:54 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Multiplayer/Multiplayer.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
2.6 KiB
C#
Raw Normal View History

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.
using System.Diagnostics;
2020-12-20 22:32:57 +08:00
using osu.Framework.Allocation;
using osu.Framework.Screens;
using osu.Game.Online.Multiplayer;
using osu.Game.Screens.OnlinePlay.Components;
using osu.Game.Screens.OnlinePlay.Lounge;
2020-12-20 22:32:57 +08:00
namespace osu.Game.Screens.OnlinePlay.Multiplayer
2020-12-20 22:32:57 +08:00
{
public 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; }
2020-12-20 22:32:57 +08:00
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();
}
2020-12-20 22:32:57 +08:00
public override void OnResuming(IScreen last)
{
base.OnResuming(last);
if (client.Room == null)
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.GameplayPassed)
{
client.AbortGameplay().FireAndForget();
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);
if (client.LocalUser.State == MultiplayerUserState.Results)
client.ChangeState(MultiplayerUserState.Idle);
2020-12-20 22:32:57 +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
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (client != null)
client.RoomUpdated -= onRoomUpdated;
}
2020-12-20 22:32:57 +08:00
}
}