mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 00:23:01 +08:00
Add AbortLoad() method to abort gameplay loads
This commit is contained in:
parent
19f7f4dc02
commit
2f1dc91211
@ -77,6 +77,11 @@ namespace osu.Game.Online.Multiplayer
|
||||
/// <exception cref="InvalidStateException">If an attempt to start the game occurs when the game's (or users') state disallows it.</exception>
|
||||
Task StartMatch();
|
||||
|
||||
/// <summary>
|
||||
/// Aborts an ongoing gameplay load.
|
||||
/// </summary>
|
||||
Task AbortLoad();
|
||||
|
||||
/// <summary>
|
||||
/// Adds an item to the playlist.
|
||||
/// </summary>
|
||||
|
@ -333,6 +333,8 @@ namespace osu.Game.Online.Multiplayer
|
||||
|
||||
public abstract Task StartMatch();
|
||||
|
||||
public abstract Task AbortLoad();
|
||||
|
||||
public abstract Task AddPlaylistItem(MultiplayerPlaylistItem item);
|
||||
|
||||
public abstract Task EditPlaylistItem(MultiplayerPlaylistItem item);
|
||||
|
@ -154,6 +154,14 @@ namespace osu.Game.Online.Multiplayer
|
||||
return connection.InvokeAsync(nameof(IMultiplayerServer.StartMatch));
|
||||
}
|
||||
|
||||
public override Task AbortLoad()
|
||||
{
|
||||
if (!IsConnected.Value)
|
||||
return Task.CompletedTask;
|
||||
|
||||
return connection.InvokeAsync(nameof(IMultiplayerServer.AbortLoad));
|
||||
}
|
||||
|
||||
public override Task AddPlaylistItem(MultiplayerPlaylistItem item)
|
||||
{
|
||||
if (!IsConnected.Value)
|
||||
|
@ -1,6 +1,7 @@
|
||||
// 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;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
@ -18,8 +19,24 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
{
|
||||
base.OnResuming(last);
|
||||
|
||||
if (client.Room != null && client.LocalUser?.State != MultiplayerUserState.Spectating)
|
||||
client.ChangeState(MultiplayerUserState.Idle);
|
||||
if (client.Room == null)
|
||||
return;
|
||||
|
||||
Debug.Assert(client.LocalUser != null);
|
||||
|
||||
switch (client.LocalUser.State)
|
||||
{
|
||||
case MultiplayerUserState.Spectating:
|
||||
break;
|
||||
|
||||
case MultiplayerUserState.WaitingForLoad:
|
||||
client.AbortLoad();
|
||||
break;
|
||||
|
||||
default:
|
||||
client.ChangeState(MultiplayerUserState.Idle);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected override string ScreenTitle => "Multiplayer";
|
||||
|
@ -242,6 +242,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
public override Task ChangeState(MultiplayerUserState newState)
|
||||
{
|
||||
Debug.Assert(Room != null);
|
||||
|
||||
if (newState == MultiplayerUserState.Idle && LocalUser?.State == MultiplayerUserState.WaitingForLoad)
|
||||
return Task.CompletedTask;
|
||||
|
||||
ChangeUserState(api.LocalUser.Value.Id, newState);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
@ -303,6 +308,16 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
return ((IMultiplayerClient)this).LoadRequested();
|
||||
}
|
||||
|
||||
public override Task AbortLoad()
|
||||
{
|
||||
Debug.Assert(Room != null);
|
||||
Debug.Assert(LocalUser != null);
|
||||
|
||||
ChangeUserState(LocalUser.UserID, MultiplayerUserState.Idle);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task AddUserPlaylistItem(int userId, MultiplayerPlaylistItem item)
|
||||
{
|
||||
Debug.Assert(Room != null);
|
||||
|
Loading…
Reference in New Issue
Block a user