1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 20:53:04 +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)] [Key(5)]
public TimeSpan AutoStartDuration { get; set; } public TimeSpan AutoStartDuration { get; set; }
public bool AutoStartEnabled => AutoStartDuration != TimeSpan.Zero;
public bool Equals(MultiplayerRoomSettings? other) public bool Equals(MultiplayerRoomSettings? other)
{ {
if (ReferenceEquals(this, other)) return true; if (ReferenceEquals(this, other)) return true;

View File

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

View File

@ -168,7 +168,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
{ {
get 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 "Cancel countdown";
return base.TooltipText; return base.TooltipText;

View File

@ -134,7 +134,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
case MultiplayerRoomState.Open: case MultiplayerRoomState.Open:
// If there are no remaining ready users or the host is not ready, stop any existing countdown. // 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. // 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); bool shouldHaveCountdown = !APIRoom.Playlist.GetCurrentItem()!.Expired && Room.Users.Any(u => u.State == MultiplayerUserState.Ready);