mirror of https://github.com/ppy/osu
Link up ready button to spectate state
This commit is contained in:
parent
1f57b6884d
commit
6be9c9f0f4
|
@ -18,6 +18,7 @@
|
|||
using osu.Game.Rulesets;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer.Match;
|
||||
using osu.Game.Tests.Resources;
|
||||
using osu.Game.Users;
|
||||
using osuTK;
|
||||
using osuTK.Input;
|
||||
|
||||
|
@ -119,6 +120,12 @@ private void load(GameHost host, AudioManager audio)
|
|||
};
|
||||
});
|
||||
|
||||
[Test]
|
||||
public void TestEnabledWhenRoomOpen()
|
||||
{
|
||||
assertSpectateButtonEnablement(true);
|
||||
}
|
||||
|
||||
[TestCase(MultiplayerUserState.Idle)]
|
||||
[TestCase(MultiplayerUserState.Ready)]
|
||||
public void TestToggleWhenIdle(MultiplayerUserState initialState)
|
||||
|
@ -130,6 +137,47 @@ public void TestToggleWhenIdle(MultiplayerUserState initialState)
|
|||
AddAssert("user is idle", () => Client.Room?.Users[0].State == MultiplayerUserState.Idle);
|
||||
}
|
||||
|
||||
[TestCase(MultiplayerRoomState.WaitingForLoad)]
|
||||
[TestCase(MultiplayerRoomState.Playing)]
|
||||
[TestCase(MultiplayerRoomState.Closed)]
|
||||
public void TestDisabledDuringGameplayOrClosed(MultiplayerRoomState roomState)
|
||||
{
|
||||
AddStep($"change user to {roomState}", () => Client.ChangeRoomState(roomState));
|
||||
assertSpectateButtonEnablement(false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestReadyButtonDisabledWhenHostAndNoReadyUsers()
|
||||
{
|
||||
addClickSpectateButtonStep();
|
||||
assertReadyButtonEnablement(false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestReadyButtonEnabledWhenHostAndUsersReady()
|
||||
{
|
||||
AddStep("add user", () => Client.AddUser(new User { Id = 55 }));
|
||||
AddStep("set user ready", () => Client.ChangeUserState(55, MultiplayerUserState.Ready));
|
||||
|
||||
addClickSpectateButtonStep();
|
||||
assertReadyButtonEnablement(true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestReadyButtonDisabledWhenNotHostAndUsersReady()
|
||||
{
|
||||
AddStep("add user and transfer host", () =>
|
||||
{
|
||||
Client.AddUser(new User { Id = 55 });
|
||||
Client.TransferHost(55);
|
||||
});
|
||||
|
||||
AddStep("set user ready", () => Client.ChangeUserState(55, MultiplayerUserState.Ready));
|
||||
|
||||
addClickSpectateButtonStep();
|
||||
assertReadyButtonEnablement(false);
|
||||
}
|
||||
|
||||
private void addClickSpectateButtonStep() => AddStep("click spectate button", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(spectateButton);
|
||||
|
@ -142,6 +190,9 @@ private void addClickReadyButtonStep() => AddStep("click ready button", () =>
|
|||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
private void assertSpectateButtonEnablement(bool shouldBeEnabled)
|
||||
=> AddAssert($"spectate button {(shouldBeEnabled ? "is" : "is not")} enabled", () => spectateButton.ChildrenOfType<OsuButton>().Single().Enabled.Value == shouldBeEnabled);
|
||||
|
||||
private void assertReadyButtonEnablement(bool shouldBeEnabled)
|
||||
=> AddAssert($"ready button {(shouldBeEnabled ? "is" : "is not")} enabled", () => readyButton.ChildrenOfType<OsuButton>().Single().Enabled.Value == shouldBeEnabled);
|
||||
}
|
||||
|
|
|
@ -78,8 +78,9 @@ private void updateState()
|
|||
Debug.Assert(Room != null);
|
||||
|
||||
int newCountReady = Room.Users.Count(u => u.State == MultiplayerUserState.Ready);
|
||||
int newCountTotal = Room.Users.Count(u => u.State != MultiplayerUserState.Spectating);
|
||||
|
||||
string countText = $"({newCountReady} / {Room.Users.Count} ready)";
|
||||
string countText = $"({newCountReady} / {newCountTotal} ready)";
|
||||
|
||||
switch (localUser.State)
|
||||
{
|
||||
|
@ -88,6 +89,7 @@ private void updateState()
|
|||
updateButtonColour(true);
|
||||
break;
|
||||
|
||||
case MultiplayerUserState.Spectating:
|
||||
case MultiplayerUserState.Ready:
|
||||
if (Room?.Host?.Equals(localUser) == true)
|
||||
{
|
||||
|
@ -105,6 +107,13 @@ private void updateState()
|
|||
|
||||
button.Enabled.Value = 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 (localUser.State == MultiplayerUserState.Spectating)
|
||||
{
|
||||
button.Enabled.Value &= Room?.Host?.Equals(localUser) == true;
|
||||
button.Enabled.Value &= newCountReady > 0;
|
||||
}
|
||||
|
||||
if (newCountReady != countReady)
|
||||
{
|
||||
countReady = newCountReady;
|
||||
|
|
|
@ -58,6 +58,12 @@ public void RemoveUser(User user)
|
|||
});
|
||||
}
|
||||
|
||||
public void ChangeRoomState(MultiplayerRoomState newState)
|
||||
{
|
||||
Debug.Assert(Room != null);
|
||||
((IMultiplayerClient)this).RoomStateChanged(newState);
|
||||
}
|
||||
|
||||
public void ChangeUserState(int userId, MultiplayerUserState newState)
|
||||
{
|
||||
Debug.Assert(Room != null);
|
||||
|
|
Loading…
Reference in New Issue