mirror of
https://github.com/ppy/osu.git
synced 2024-12-13 08:32:57 +08:00
Add initial support for aborting multiplayer games
This commit is contained in:
parent
b2e1a63cd7
commit
894c31753b
@ -82,6 +82,11 @@ namespace osu.Game.Online.Multiplayer
|
||||
/// </summary>
|
||||
Task AbortGameplay();
|
||||
|
||||
/// <summary>
|
||||
/// Real.
|
||||
/// </summary>
|
||||
Task AbortGameplayReal();
|
||||
|
||||
/// <summary>
|
||||
/// Adds an item to the playlist.
|
||||
/// </summary>
|
||||
|
@ -374,6 +374,8 @@ namespace osu.Game.Online.Multiplayer
|
||||
|
||||
public abstract Task AbortGameplay();
|
||||
|
||||
public abstract Task AbortGameplayReal();
|
||||
|
||||
public abstract Task AddPlaylistItem(MultiplayerPlaylistItem item);
|
||||
|
||||
public abstract Task EditPlaylistItem(MultiplayerPlaylistItem item);
|
||||
|
@ -226,6 +226,16 @@ namespace osu.Game.Online.Multiplayer
|
||||
return connection.InvokeAsync(nameof(IMultiplayerServer.AbortGameplay));
|
||||
}
|
||||
|
||||
public override Task AbortGameplayReal()
|
||||
{
|
||||
if (!IsConnected.Value)
|
||||
return Task.CompletedTask;
|
||||
|
||||
Debug.Assert(connection != null);
|
||||
|
||||
return connection.InvokeAsync(nameof(IMultiplayerServer.AbortGameplayReal));
|
||||
}
|
||||
|
||||
public override Task AddPlaylistItem(MultiplayerPlaylistItem item)
|
||||
{
|
||||
if (!IsConnected.Value)
|
||||
|
@ -0,0 +1,33 @@
|
||||
// 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.Graphics.Sprites;
|
||||
using osu.Game.Overlays.Dialog;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
{
|
||||
public partial class ConfirmAbortDialog : PopupDialog
|
||||
{
|
||||
public ConfirmAbortDialog(Action onConfirm, Action onCancel)
|
||||
{
|
||||
HeaderText = "Are you sure you want to go abort the match?";
|
||||
|
||||
Icon = FontAwesome.Solid.ExclamationTriangle;
|
||||
|
||||
Buttons = new PopupDialogButton[]
|
||||
{
|
||||
new PopupDialogDangerousButton
|
||||
{
|
||||
Text = @"Yes",
|
||||
Action = onConfirm
|
||||
},
|
||||
new PopupDialogCancelButton
|
||||
{
|
||||
Text = @"No I didn't mean to",
|
||||
Action = onCancel
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Multiplayer.Countdown;
|
||||
using osu.Game.Overlays;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
@ -28,6 +29,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
[CanBeNull]
|
||||
private IDisposable clickOperation;
|
||||
|
||||
[Resolved(canBeNull: true)]
|
||||
private IDialogOverlay dialogOverlay { get; set; }
|
||||
|
||||
private Sample sampleReady;
|
||||
private Sample sampleReadyAll;
|
||||
private Sample sampleUnready;
|
||||
@ -109,8 +113,23 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
Debug.Assert(clickOperation == null);
|
||||
clickOperation = ongoingOperationTracker.BeginOperation();
|
||||
|
||||
if (isReady() && Client.IsHost && !Room.ActiveCountdowns.Any(c => c is MatchStartCountdown))
|
||||
startMatch();
|
||||
if (Client.IsHost)
|
||||
{
|
||||
if (Room.State == MultiplayerRoomState.Open)
|
||||
{
|
||||
if (isReady() && !Room.ActiveCountdowns.Any(c => c is MatchStartCountdown))
|
||||
startMatch();
|
||||
else
|
||||
toggleReady();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dialogOverlay == null)
|
||||
abortMatch();
|
||||
else
|
||||
dialogOverlay.Push(new ConfirmAbortDialog(abortMatch, endOperation));
|
||||
}
|
||||
}
|
||||
else
|
||||
toggleReady();
|
||||
|
||||
@ -128,6 +147,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
// gameplay was not started due to an exception; unblock button.
|
||||
endOperation();
|
||||
});
|
||||
|
||||
void abortMatch() => Client.AbortGameplayReal().FireAndForget(endOperation, _ => endOperation());
|
||||
}
|
||||
|
||||
private void startCountdown(TimeSpan duration)
|
||||
@ -198,6 +219,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
if (localUser?.State == MultiplayerUserState.Spectating)
|
||||
readyButton.Enabled.Value &= Client.IsHost && newCountReady > 0 && !Room.ActiveCountdowns.Any(c => c is MatchStartCountdown);
|
||||
|
||||
readyButton.Enabled.Value = true;
|
||||
|
||||
if (newCountReady == countReady)
|
||||
return;
|
||||
|
||||
|
@ -158,7 +158,16 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
Text = room.Host?.Equals(localUser) == true
|
||||
? $"Start match {countText}"
|
||||
: $"Waiting for host... {countText}";
|
||||
break;
|
||||
|
||||
case MultiplayerUserState.Idle:
|
||||
if (room.State == MultiplayerRoomState.Open || room.Host?.Equals(localUser) != true)
|
||||
{
|
||||
Text = "Ready";
|
||||
break;
|
||||
}
|
||||
|
||||
Text = "Abort!";
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -204,17 +213,23 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
setYellow();
|
||||
|
||||
break;
|
||||
|
||||
case MultiplayerUserState.Idle:
|
||||
if (room.State == MultiplayerRoomState.Open || room.Host?.Equals(localUser) != true)
|
||||
{
|
||||
setGreen();
|
||||
break;
|
||||
}
|
||||
|
||||
setRed();
|
||||
break;
|
||||
}
|
||||
|
||||
void setYellow()
|
||||
{
|
||||
BackgroundColour = colours.YellowDark;
|
||||
}
|
||||
void setYellow() => BackgroundColour = colours.YellowDark;
|
||||
|
||||
void setGreen()
|
||||
{
|
||||
BackgroundColour = colours.Green;
|
||||
}
|
||||
void setGreen() => BackgroundColour = colours.Green;
|
||||
|
||||
void setRed() => BackgroundColour = colours.Red;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
|
@ -396,6 +396,12 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public override Task AbortGameplayReal()
|
||||
{
|
||||
// Todo:
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task AddUserPlaylistItem(int userId, MultiplayerPlaylistItem item)
|
||||
{
|
||||
Debug.Assert(ServerRoom != null);
|
||||
|
Loading…
Reference in New Issue
Block a user