2021-04-06 12:37:21 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2021-04-07 07:19:10 +00:00
|
|
|
using System.Linq;
|
2021-04-06 12:37:21 +00:00
|
|
|
using NUnit.Framework;
|
2021-04-07 07:19:10 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Bindables;
|
2022-01-03 08:02:15 +00:00
|
|
|
using osu.Framework.Extensions;
|
2021-04-06 12:37:21 +00:00
|
|
|
using osu.Framework.Graphics;
|
2021-04-07 07:19:10 +00:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-03-17 10:05:28 +00:00
|
|
|
using osu.Framework.Graphics.Cursor;
|
2021-04-07 07:19:10 +00:00
|
|
|
using osu.Framework.Platform;
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-11-04 09:02:44 +00:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2021-04-06 12:37:21 +00:00
|
|
|
using osu.Game.Online.Multiplayer;
|
2021-04-07 07:19:10 +00:00
|
|
|
using osu.Game.Online.Rooms;
|
|
|
|
using osu.Game.Rulesets;
|
2021-04-06 12:37:21 +00:00
|
|
|
using osu.Game.Screens.OnlinePlay.Multiplayer.Match;
|
2021-04-07 07:19:10 +00:00
|
|
|
using osu.Game.Tests.Resources;
|
2021-04-06 12:37:21 +00:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Multiplayer
|
|
|
|
{
|
|
|
|
public class TestSceneMultiplayerSpectateButton : MultiplayerTestScene
|
|
|
|
{
|
2021-04-07 07:19:10 +00:00
|
|
|
private MultiplayerSpectateButton spectateButton;
|
2022-03-23 01:37:53 +00:00
|
|
|
private MatchStartControl startControl;
|
2021-04-07 07:19:10 +00:00
|
|
|
|
|
|
|
private readonly Bindable<PlaylistItem> selectedItem = new Bindable<PlaylistItem>();
|
|
|
|
|
|
|
|
private BeatmapSetInfo importedSet;
|
|
|
|
private BeatmapManager beatmaps;
|
|
|
|
private RulesetStore rulesets;
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(GameHost host, AudioManager audio)
|
|
|
|
{
|
2022-02-16 08:13:51 +00:00
|
|
|
Dependencies.Cache(rulesets = new RealmRulesetStore(Realm));
|
2022-01-25 03:58:15 +00:00
|
|
|
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, rulesets, null, audio, Resources, host, Beatmap.Default));
|
|
|
|
Dependencies.Cache(Realm);
|
2022-01-14 10:59:21 +00:00
|
|
|
|
2022-01-03 08:02:15 +00:00
|
|
|
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
|
2021-04-07 07:19:10 +00:00
|
|
|
}
|
|
|
|
|
2021-04-06 12:37:21 +00:00
|
|
|
[SetUp]
|
|
|
|
public new void Setup() => Schedule(() =>
|
|
|
|
{
|
2021-06-25 06:00:10 +00:00
|
|
|
AvailabilityTracker.SelectedItem.BindTo(selectedItem);
|
|
|
|
|
2021-12-17 09:26:12 +00:00
|
|
|
importedSet = beatmaps.GetAllUsableBeatmapSets().First();
|
2021-04-07 07:19:10 +00:00
|
|
|
Beatmap.Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First());
|
2022-02-15 14:33:26 +00:00
|
|
|
selectedItem.Value = new PlaylistItem(Beatmap.Value.BeatmapInfo)
|
2021-04-06 12:37:21 +00:00
|
|
|
{
|
2022-02-15 07:01:14 +00:00
|
|
|
RulesetID = Beatmap.Value.BeatmapInfo.Ruleset.OnlineID,
|
2021-04-07 07:19:10 +00:00
|
|
|
};
|
|
|
|
|
2022-03-17 10:05:28 +00:00
|
|
|
Child = new PopoverContainer
|
2021-04-07 07:19:10 +00:00
|
|
|
{
|
2022-03-17 10:05:28 +00:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Child = new FillFlowContainer
|
2021-04-06 12:37:21 +00:00
|
|
|
{
|
2022-03-17 10:05:28 +00:00
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Children = new Drawable[]
|
2021-04-07 07:19:10 +00:00
|
|
|
{
|
2022-03-17 10:05:28 +00:00
|
|
|
spectateButton = new MultiplayerSpectateButton
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(200, 50),
|
|
|
|
},
|
2022-03-23 01:37:53 +00:00
|
|
|
startControl = new MatchStartControl
|
2022-03-17 10:05:28 +00:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(200, 50),
|
|
|
|
}
|
2021-04-07 07:19:10 +00:00
|
|
|
}
|
2021-04-06 12:37:21 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2021-04-22 15:49:14 +00:00
|
|
|
[TestCase(MultiplayerRoomState.Open)]
|
|
|
|
[TestCase(MultiplayerRoomState.WaitingForLoad)]
|
|
|
|
[TestCase(MultiplayerRoomState.Playing)]
|
|
|
|
public void TestEnabledWhenRoomOpenOrInGameplay(MultiplayerRoomState roomState)
|
2021-04-07 07:35:36 +00:00
|
|
|
{
|
2022-02-16 00:43:28 +00:00
|
|
|
AddStep($"change room to {roomState}", () => MultiplayerClient.ChangeRoomState(roomState));
|
2021-04-07 07:35:36 +00:00
|
|
|
assertSpectateButtonEnablement(true);
|
|
|
|
}
|
|
|
|
|
2021-04-06 12:37:21 +00:00
|
|
|
[TestCase(MultiplayerUserState.Idle)]
|
|
|
|
[TestCase(MultiplayerUserState.Ready)]
|
|
|
|
public void TestToggleWhenIdle(MultiplayerUserState initialState)
|
|
|
|
{
|
2021-12-21 04:20:12 +00:00
|
|
|
ClickButtonWhenEnabled<MultiplayerSpectateButton>();
|
2022-07-01 09:58:22 +00:00
|
|
|
AddUntilStep("user is spectating", () => MultiplayerClient.ClientRoom?.Users[0].State == MultiplayerUserState.Spectating);
|
2021-04-06 12:37:21 +00:00
|
|
|
|
2021-12-21 04:20:12 +00:00
|
|
|
ClickButtonWhenEnabled<MultiplayerSpectateButton>();
|
2022-07-01 09:58:22 +00:00
|
|
|
AddUntilStep("user is idle", () => MultiplayerClient.ClientRoom?.Users[0].State == MultiplayerUserState.Idle);
|
2021-04-06 12:37:21 +00:00
|
|
|
}
|
|
|
|
|
2021-04-07 07:35:36 +00:00
|
|
|
[TestCase(MultiplayerRoomState.Closed)]
|
2021-04-22 15:49:14 +00:00
|
|
|
public void TestDisabledWhenClosed(MultiplayerRoomState roomState)
|
2021-04-07 07:35:36 +00:00
|
|
|
{
|
2022-02-16 00:43:28 +00:00
|
|
|
AddStep($"change room to {roomState}", () => MultiplayerClient.ChangeRoomState(roomState));
|
2021-04-07 07:35:36 +00:00
|
|
|
assertSpectateButtonEnablement(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestReadyButtonDisabledWhenHostAndNoReadyUsers()
|
|
|
|
{
|
2021-12-21 04:20:12 +00:00
|
|
|
ClickButtonWhenEnabled<MultiplayerSpectateButton>();
|
2021-04-07 07:35:36 +00:00
|
|
|
assertReadyButtonEnablement(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestReadyButtonEnabledWhenHostAndUsersReady()
|
|
|
|
{
|
2022-02-16 00:43:28 +00:00
|
|
|
AddStep("add user", () => MultiplayerClient.AddUser(new APIUser { Id = PLAYER_1_ID }));
|
|
|
|
AddStep("set user ready", () => MultiplayerClient.ChangeUserState(PLAYER_1_ID, MultiplayerUserState.Ready));
|
2021-04-07 07:35:36 +00:00
|
|
|
|
2021-12-21 04:20:12 +00:00
|
|
|
ClickButtonWhenEnabled<MultiplayerSpectateButton>();
|
2021-04-07 07:35:36 +00:00
|
|
|
assertReadyButtonEnablement(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestReadyButtonDisabledWhenNotHostAndUsersReady()
|
|
|
|
{
|
|
|
|
AddStep("add user and transfer host", () =>
|
|
|
|
{
|
2022-02-16 00:43:28 +00:00
|
|
|
MultiplayerClient.AddUser(new APIUser { Id = PLAYER_1_ID });
|
|
|
|
MultiplayerClient.TransferHost(PLAYER_1_ID);
|
2021-04-07 07:35:36 +00:00
|
|
|
});
|
|
|
|
|
2022-02-16 00:43:28 +00:00
|
|
|
AddStep("set user ready", () => MultiplayerClient.ChangeUserState(PLAYER_1_ID, MultiplayerUserState.Ready));
|
2021-04-07 07:35:36 +00:00
|
|
|
|
2021-12-21 04:20:12 +00:00
|
|
|
ClickButtonWhenEnabled<MultiplayerSpectateButton>();
|
2021-04-07 07:35:36 +00:00
|
|
|
assertReadyButtonEnablement(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void assertSpectateButtonEnablement(bool shouldBeEnabled)
|
2021-07-06 11:28:49 +00:00
|
|
|
=> AddUntilStep($"spectate button {(shouldBeEnabled ? "is" : "is not")} enabled", () => spectateButton.ChildrenOfType<OsuButton>().Single().Enabled.Value == shouldBeEnabled);
|
2021-04-07 07:35:36 +00:00
|
|
|
|
2021-04-07 07:19:10 +00:00
|
|
|
private void assertReadyButtonEnablement(bool shouldBeEnabled)
|
2022-03-24 05:28:38 +00:00
|
|
|
=> AddUntilStep($"ready button {(shouldBeEnabled ? "is" : "is not")} enabled", () => startControl.ChildrenOfType<MultiplayerReadyButton>().Single().Enabled.Value == shouldBeEnabled);
|
2021-04-06 12:37:21 +00:00
|
|
|
}
|
|
|
|
}
|