1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-20 06:12:55 +08:00

Simplify AutoStart and Host checks

This commit is contained in:
Dean Herbert 2022-03-25 15:41:01 +09:00
parent de4c04ef80
commit b1f0f89fdd
4 changed files with 10 additions and 8 deletions

View File

@ -31,6 +31,8 @@ namespace osu.Game.Online.Multiplayer
[Key(5)]
public TimeSpan AutoStartDuration { get; set; }
public bool AutoStartEnabled => AutoStartDuration != TimeSpan.Zero;
public bool Equals(MultiplayerRoomSettings? other)
{
if (ReferenceEquals(this, other)) return true;

View File

@ -109,7 +109,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
clickOperation = ongoingOperationTracker.BeginOperation();
// Ensure the current user becomes ready before being able to do anything else (start match, stop countdown, unready).
if (!isReady() || !Client.IsHost || Room.Settings.AutoStartDuration != TimeSpan.Zero)
if (!isReady() || !Client.IsHost || Room.Settings.AutoStartEnabled)
{
toggleReady();
return;
@ -172,19 +172,19 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
int newCountReady = Room.Users.Count(u => u.State == MultiplayerUserState.Ready);
int newCountTotal = Room.Users.Count(u => u.State != MultiplayerUserState.Spectating);
if (Room.Countdown != null || Room.Settings.AutoStartDuration != TimeSpan.Zero)
countdownButton.Alpha = 0;
if (!Client.IsHost || Room.Countdown != null || Room.Settings.AutoStartEnabled)
countdownButton.Hide();
else
{
switch (localUser?.State)
{
default:
countdownButton.Alpha = 0;
countdownButton.Hide();
break;
case MultiplayerUserState.Spectating:
case MultiplayerUserState.Ready:
countdownButton.Alpha = Room.Host?.Equals(localUser) == true ? 1 : 0;
countdownButton.Show();
break;
}
}
@ -197,7 +197,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
// When the local user is the host and spectating the match, the "start match" state should be enabled if any users are ready.
if (localUser?.State == MultiplayerUserState.Spectating)
enabled.Value &= Room.Host?.Equals(localUser) == true && newCountReady > 0;
enabled.Value &= Client.IsHost && newCountReady > 0;
if (newCountReady == countReady)
return;

View File

@ -168,7 +168,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
{
get
{
if (room?.Countdown != null && multiplayerClient.IsHost && multiplayerClient.LocalUser?.State == MultiplayerUserState.Ready && room.Settings.AutoStartDuration == TimeSpan.Zero)
if (room?.Countdown != null && multiplayerClient.IsHost && multiplayerClient.LocalUser?.State == MultiplayerUserState.Ready && !room.Settings.AutoStartEnabled)
return "Cancel countdown";
return base.TooltipText;

View File

@ -134,7 +134,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
case MultiplayerRoomState.Open:
// If there are no remaining ready users or the host is not ready, stop any existing countdown.
// Todo: This doesn't yet support non-match-start countdowns.
if (Room.Settings.AutoStartDuration != TimeSpan.Zero)
if (Room.Settings.AutoStartEnabled)
{
bool shouldHaveCountdown = !APIRoom.Playlist.GetCurrentItem()!.Expired && Room.Users.Any(u => u.State == MultiplayerUserState.Ready);