mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 10:02:59 +08:00
Link up ready button to spectate state
This commit is contained in:
parent
1f57b6884d
commit
6be9c9f0f4
@ -18,6 +18,7 @@ using osu.Game.Online.Rooms;
|
|||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Screens.OnlinePlay.Multiplayer.Match;
|
using osu.Game.Screens.OnlinePlay.Multiplayer.Match;
|
||||||
using osu.Game.Tests.Resources;
|
using osu.Game.Tests.Resources;
|
||||||
|
using osu.Game.Users;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
|
|
||||||
@ -119,6 +120,12 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestEnabledWhenRoomOpen()
|
||||||
|
{
|
||||||
|
assertSpectateButtonEnablement(true);
|
||||||
|
}
|
||||||
|
|
||||||
[TestCase(MultiplayerUserState.Idle)]
|
[TestCase(MultiplayerUserState.Idle)]
|
||||||
[TestCase(MultiplayerUserState.Ready)]
|
[TestCase(MultiplayerUserState.Ready)]
|
||||||
public void TestToggleWhenIdle(MultiplayerUserState initialState)
|
public void TestToggleWhenIdle(MultiplayerUserState initialState)
|
||||||
@ -130,6 +137,47 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
AddAssert("user is idle", () => Client.Room?.Users[0].State == MultiplayerUserState.Idle);
|
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", () =>
|
private void addClickSpectateButtonStep() => AddStep("click spectate button", () =>
|
||||||
{
|
{
|
||||||
InputManager.MoveMouseTo(spectateButton);
|
InputManager.MoveMouseTo(spectateButton);
|
||||||
@ -142,6 +190,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
InputManager.Click(MouseButton.Left);
|
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)
|
private void assertReadyButtonEnablement(bool shouldBeEnabled)
|
||||||
=> AddAssert($"ready button {(shouldBeEnabled ? "is" : "is not")} enabled", () => readyButton.ChildrenOfType<OsuButton>().Single().Enabled.Value == shouldBeEnabled);
|
=> AddAssert($"ready button {(shouldBeEnabled ? "is" : "is not")} enabled", () => readyButton.ChildrenOfType<OsuButton>().Single().Enabled.Value == shouldBeEnabled);
|
||||||
}
|
}
|
||||||
|
@ -78,8 +78,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
Debug.Assert(Room != null);
|
Debug.Assert(Room != null);
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
string countText = $"({newCountReady} / {Room.Users.Count} ready)";
|
string countText = $"({newCountReady} / {newCountTotal} ready)";
|
||||||
|
|
||||||
switch (localUser.State)
|
switch (localUser.State)
|
||||||
{
|
{
|
||||||
@ -88,6 +89,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
updateButtonColour(true);
|
updateButtonColour(true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case MultiplayerUserState.Spectating:
|
||||||
case MultiplayerUserState.Ready:
|
case MultiplayerUserState.Ready:
|
||||||
if (Room?.Host?.Equals(localUser) == true)
|
if (Room?.Host?.Equals(localUser) == true)
|
||||||
{
|
{
|
||||||
@ -105,6 +107,13 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
|||||||
|
|
||||||
button.Enabled.Value = Client.Room?.State == MultiplayerRoomState.Open && !operationInProgress.Value;
|
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)
|
if (newCountReady != countReady)
|
||||||
{
|
{
|
||||||
countReady = newCountReady;
|
countReady = newCountReady;
|
||||||
|
@ -58,6 +58,12 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ChangeRoomState(MultiplayerRoomState newState)
|
||||||
|
{
|
||||||
|
Debug.Assert(Room != null);
|
||||||
|
((IMultiplayerClient)this).RoomStateChanged(newState);
|
||||||
|
}
|
||||||
|
|
||||||
public void ChangeUserState(int userId, MultiplayerUserState newState)
|
public void ChangeUserState(int userId, MultiplayerUserState newState)
|
||||||
{
|
{
|
||||||
Debug.Assert(Room != null);
|
Debug.Assert(Room != null);
|
||||||
|
Loading…
Reference in New Issue
Block a user