2021-12-08 17:12:33 +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-12-08 17:12:33 +00:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Audio;
|
2022-01-03 08:02:15 +00:00
|
|
|
using osu.Framework.Extensions;
|
2021-12-08 17:12:33 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Platform;
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Beatmaps;
|
2021-12-09 05:11:29 +00:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2021-12-08 17:12:33 +00:00
|
|
|
using osu.Game.Online.Multiplayer;
|
|
|
|
using osu.Game.Online.Rooms;
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Screens.OnlinePlay;
|
|
|
|
using osu.Game.Screens.OnlinePlay.Multiplayer.Match.Playlist;
|
|
|
|
using osu.Game.Tests.Resources;
|
|
|
|
using osuTK;
|
|
|
|
|
2021-12-09 17:09:31 +00:00
|
|
|
namespace osu.Game.Tests.Visual.Multiplayer
|
2021-12-08 17:12:33 +00:00
|
|
|
{
|
|
|
|
public class TestSceneMultiplayerQueueList : MultiplayerTestScene
|
|
|
|
{
|
2021-12-10 11:08:59 +00:00
|
|
|
private MultiplayerQueueList playlist;
|
2021-12-08 17:12:33 +00:00
|
|
|
private BeatmapManager beatmaps;
|
|
|
|
private RulesetStore rulesets;
|
|
|
|
private BeatmapSetInfo importedSet;
|
|
|
|
private BeatmapInfo importedBeatmap;
|
|
|
|
|
|
|
|
[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, API, audio, Resources, host, Beatmap.Default));
|
|
|
|
Dependencies.Cache(Realm);
|
2021-12-08 17:12:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void SetUpSteps()
|
|
|
|
{
|
|
|
|
base.SetUpSteps();
|
|
|
|
|
|
|
|
AddStep("create playlist", () =>
|
|
|
|
{
|
|
|
|
Child = playlist = new MultiplayerQueueList
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(500, 300),
|
2022-02-16 00:43:28 +00:00
|
|
|
Items = { BindTarget = MultiplayerClient.APIRoom!.Playlist }
|
2021-12-08 17:12:33 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("import beatmap", () =>
|
|
|
|
{
|
2022-01-03 08:02:15 +00:00
|
|
|
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
|
2021-12-17 09:26:12 +00:00
|
|
|
importedSet = beatmaps.GetAllUsableBeatmapSets().First();
|
2022-01-27 06:19:48 +00:00
|
|
|
importedBeatmap = importedSet.Beatmaps.First(b => b.Ruleset.OnlineID == 0);
|
2021-12-08 17:12:33 +00:00
|
|
|
});
|
|
|
|
|
2022-02-16 00:43:28 +00:00
|
|
|
AddStep("change to all players mode", () => MultiplayerClient.ChangeSettings(new MultiplayerRoomSettings { QueueMode = QueueMode.AllPlayers }).WaitSafely());
|
2021-12-08 17:12:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2021-12-09 05:11:29 +00:00
|
|
|
public void TestDeleteButtonAlwaysVisibleForHost()
|
2021-12-08 17:12:33 +00:00
|
|
|
{
|
2022-02-16 00:43:28 +00:00
|
|
|
AddStep("set all players queue mode", () => MultiplayerClient.ChangeSettings(new MultiplayerRoomSettings { QueueMode = QueueMode.AllPlayers }).WaitSafely());
|
|
|
|
AddUntilStep("wait for queue mode change", () => MultiplayerClient.APIRoom?.QueueMode.Value == QueueMode.AllPlayers);
|
2021-12-08 17:12:33 +00:00
|
|
|
|
|
|
|
addPlaylistItem(() => API.LocalUser.Value.OnlineID);
|
2021-12-09 05:11:29 +00:00
|
|
|
assertDeleteButtonVisibility(1, true);
|
2021-12-08 17:12:33 +00:00
|
|
|
addPlaylistItem(() => 1234);
|
2021-12-09 05:11:29 +00:00
|
|
|
assertDeleteButtonVisibility(2, true);
|
2021-12-08 17:12:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2021-12-09 05:11:29 +00:00
|
|
|
public void TestDeleteButtonOnlyVisibleForItemOwnerIfNotHost()
|
2021-12-08 17:12:33 +00:00
|
|
|
{
|
2022-02-16 00:43:28 +00:00
|
|
|
AddStep("set all players queue mode", () => MultiplayerClient.ChangeSettings(new MultiplayerRoomSettings { QueueMode = QueueMode.AllPlayers }).WaitSafely());
|
|
|
|
AddUntilStep("wait for queue mode change", () => MultiplayerClient.APIRoom?.QueueMode.Value == QueueMode.AllPlayers);
|
2021-12-08 17:12:33 +00:00
|
|
|
|
2022-02-16 00:43:28 +00:00
|
|
|
AddStep("join other user", () => MultiplayerClient.AddUser(new APIUser { Id = 1234 }));
|
|
|
|
AddStep("set other user as host", () => MultiplayerClient.TransferHost(1234));
|
2021-12-09 05:11:29 +00:00
|
|
|
|
2021-12-08 17:12:33 +00:00
|
|
|
addPlaylistItem(() => API.LocalUser.Value.OnlineID);
|
|
|
|
assertDeleteButtonVisibility(1, true);
|
|
|
|
addPlaylistItem(() => 1234);
|
|
|
|
assertDeleteButtonVisibility(2, false);
|
|
|
|
|
2022-02-16 00:43:28 +00:00
|
|
|
AddStep("set local user as host", () => MultiplayerClient.TransferHost(API.LocalUser.Value.OnlineID));
|
2021-12-09 05:11:29 +00:00
|
|
|
assertDeleteButtonVisibility(1, true);
|
|
|
|
assertDeleteButtonVisibility(2, true);
|
2021-12-08 17:12:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2021-12-09 05:11:29 +00:00
|
|
|
public void TestCurrentItemDoesNotHaveDeleteButton()
|
2021-12-08 17:12:33 +00:00
|
|
|
{
|
2022-02-16 00:43:28 +00:00
|
|
|
AddStep("set all players queue mode", () => MultiplayerClient.ChangeSettings(new MultiplayerRoomSettings { QueueMode = QueueMode.AllPlayers }).WaitSafely());
|
|
|
|
AddUntilStep("wait for queue mode change", () => MultiplayerClient.APIRoom?.QueueMode.Value == QueueMode.AllPlayers);
|
2021-12-08 17:12:33 +00:00
|
|
|
|
2021-12-09 05:11:29 +00:00
|
|
|
addPlaylistItem(() => API.LocalUser.Value.OnlineID);
|
2021-12-10 11:08:59 +00:00
|
|
|
|
2021-12-08 17:12:33 +00:00
|
|
|
assertDeleteButtonVisibility(0, false);
|
2021-12-09 05:11:29 +00:00
|
|
|
assertDeleteButtonVisibility(1, true);
|
|
|
|
|
2022-02-16 00:43:28 +00:00
|
|
|
AddStep("finish current item", () => MultiplayerClient.FinishCurrentItem().WaitSafely());
|
|
|
|
AddUntilStep("wait for next item to be selected", () => MultiplayerClient.Room?.Settings.PlaylistItemId == 2);
|
2021-12-22 00:55:16 +00:00
|
|
|
AddUntilStep("wait for two items in playlist", () => playlist.ChildrenOfType<DrawableRoomPlaylistItem>().Count() == 2);
|
2021-12-21 09:38:31 +00:00
|
|
|
|
|
|
|
assertDeleteButtonVisibility(0, false);
|
2021-12-09 05:11:29 +00:00
|
|
|
assertDeleteButtonVisibility(1, false);
|
2021-12-08 17:12:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void addPlaylistItem(Func<int> userId)
|
|
|
|
{
|
|
|
|
long itemId = -1;
|
|
|
|
|
|
|
|
AddStep("add playlist item", () =>
|
|
|
|
{
|
2022-02-15 14:33:26 +00:00
|
|
|
MultiplayerPlaylistItem item = new MultiplayerPlaylistItem(new PlaylistItem(importedBeatmap));
|
2021-12-08 17:12:33 +00:00
|
|
|
|
2022-02-16 00:43:28 +00:00
|
|
|
MultiplayerClient.AddUserPlaylistItem(userId(), item).WaitSafely();
|
2021-12-08 17:12:33 +00:00
|
|
|
|
|
|
|
itemId = item.ID;
|
|
|
|
});
|
|
|
|
|
|
|
|
AddUntilStep("item arrived in playlist", () => playlist.ChildrenOfType<RearrangeableListItem<PlaylistItem>>().Any(i => i.Model.ID == itemId));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void assertDeleteButtonVisibility(int index, bool visible)
|
2021-12-22 00:55:16 +00:00
|
|
|
=> AddUntilStep($"delete button {index} {(visible ? "is" : "is not")} visible", () =>
|
|
|
|
{
|
|
|
|
var button = playlist.ChildrenOfType<DrawableRoomPlaylistItem.PlaylistRemoveButton>().ElementAtOrDefault(index);
|
|
|
|
return (button?.Alpha > 0) == visible;
|
|
|
|
});
|
2021-12-08 17:12:33 +00:00
|
|
|
}
|
|
|
|
}
|