1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 20:03:21 +08:00

Fix multiplayer screen buttons showing no text when local user not available

This commit is contained in:
Dean Herbert 2021-07-13 17:59:35 +09:00
parent e70744ee37
commit e791669c40
2 changed files with 11 additions and 23 deletions

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Diagnostics;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
@ -72,25 +71,20 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
{ {
var localUser = Client.LocalUser; var localUser = Client.LocalUser;
if (localUser == null) int newCountReady = Room?.Users.Count(u => u.State == MultiplayerUserState.Ready) ?? 0;
return; int newCountTotal = Room?.Users.Count(u => u.State != MultiplayerUserState.Spectating) ?? 0;
Debug.Assert(Room != null); switch (localUser?.State)
int newCountReady = Room.Users.Count(u => u.State == MultiplayerUserState.Ready);
int newCountTotal = Room.Users.Count(u => u.State != MultiplayerUserState.Spectating);
string countText = $"({newCountReady} / {newCountTotal} ready)";
switch (localUser.State)
{ {
case MultiplayerUserState.Idle: default:
button.Text = "Ready"; button.Text = "Ready";
updateButtonColour(true); updateButtonColour(true);
break; break;
case MultiplayerUserState.Spectating: case MultiplayerUserState.Spectating:
case MultiplayerUserState.Ready: case MultiplayerUserState.Ready:
string countText = $"({newCountReady} / {newCountTotal} ready)";
if (Room?.Host?.Equals(localUser) == true) if (Room?.Host?.Equals(localUser) == true)
{ {
button.Text = $"Start match {countText}"; button.Text = $"Start match {countText}";
@ -108,7 +102,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
bool enableButton = Client.Room?.State == MultiplayerRoomState.Open && !operationInProgress.Value; bool enableButton = Client.Room?.State == MultiplayerRoomState.Open && !operationInProgress.Value;
// 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)
enableButton &= Room?.Host?.Equals(localUser) == true && newCountReady > 0; enableButton &= Room?.Host?.Equals(localUser) == true && newCountReady > 0;
button.Enabled.Value = enableButton; button.Enabled.Value = enableButton;

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Diagnostics;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -57,14 +56,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
private void updateState() private void updateState()
{ {
var localUser = Client.LocalUser; switch (Client.LocalUser?.State)
if (localUser == null)
return;
Debug.Assert(Room != null);
switch (localUser.State)
{ {
default: default:
button.Text = "Spectate"; button.Text = "Spectate";
@ -81,7 +73,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
break; break;
} }
button.Enabled.Value = Client.Room?.State != MultiplayerRoomState.Closed && !operationInProgress.Value; button.Enabled.Value = Client.Room != null
&& Client.Room.State != MultiplayerRoomState.Closed
&& !operationInProgress.Value;
} }
private class ButtonWithTrianglesExposed : TriangleButton private class ButtonWithTrianglesExposed : TriangleButton