2021-12-09 01:12:33 +08: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.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Audio;
|
2022-01-03 16:02:15 +08:00
|
|
|
using osu.Framework.Extensions;
|
2021-12-09 01:12:33 +08: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 13:11:29 +08:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2021-12-09 01:12:33 +08: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-10 01:09:31 +08:00
|
|
|
namespace osu.Game.Tests.Visual.Multiplayer
|
2021-12-09 01:12:33 +08:00
|
|
|
{
|
|
|
|
public partial class TestSceneMultiplayerQueueList : MultiplayerTestScene
|
|
|
|
{
|
2024-11-14 16:57:32 +08:00
|
|
|
private MultiplayerQueueList playlist = null!;
|
|
|
|
private BeatmapManager beatmaps = null!;
|
|
|
|
private BeatmapSetInfo importedSet = null!;
|
|
|
|
private BeatmapInfo importedBeatmap = null!;
|
2021-12-09 01:12:33 +08:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(GameHost host, AudioManager audio)
|
|
|
|
{
|
2022-07-28 15:19:05 +08:00
|
|
|
Dependencies.Cache(new RealmRulesetStore(Realm));
|
|
|
|
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, API, audio, Resources, host, Beatmap.Default));
|
2022-01-25 11:58:15 +08:00
|
|
|
Dependencies.Cache(Realm);
|
2021-12-09 01:12:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void SetUpSteps()
|
|
|
|
{
|
|
|
|
base.SetUpSteps();
|
|
|
|
|
|
|
|
AddStep("create playlist", () =>
|
|
|
|
{
|
2024-11-21 19:26:44 +08:00
|
|
|
Child = playlist = new MultiplayerQueueList(SelectedRoom.Value!)
|
2021-12-09 01:12:33 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(500, 300),
|
2024-11-14 16:57:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
MultiplayerClient.ClientAPIRoom!.PropertyChanged += (_, e) =>
|
|
|
|
{
|
|
|
|
if (e.PropertyName == nameof(Room.Playlist))
|
|
|
|
playlist.Items.ReplaceRange(0, playlist.Items.Count, MultiplayerClient.ClientAPIRoom.Playlist);
|
2021-12-09 01:12:33 +08:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("import beatmap", () =>
|
|
|
|
{
|
2022-01-03 16:02:15 +08:00
|
|
|
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
|
2021-12-17 17:26:12 +08:00
|
|
|
importedSet = beatmaps.GetAllUsableBeatmapSets().First();
|
2022-01-27 14:19:48 +08:00
|
|
|
importedBeatmap = importedSet.Beatmaps.First(b => b.Ruleset.OnlineID == 0);
|
2021-12-09 01:12:33 +08:00
|
|
|
});
|
|
|
|
|
2022-02-16 08:43:28 +08:00
|
|
|
AddStep("change to all players mode", () => MultiplayerClient.ChangeSettings(new MultiplayerRoomSettings { QueueMode = QueueMode.AllPlayers }).WaitSafely());
|
2021-12-09 01:12:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2021-12-09 13:11:29 +08:00
|
|
|
public void TestDeleteButtonAlwaysVisibleForHost()
|
2021-12-09 01:12:33 +08:00
|
|
|
{
|
2022-02-16 08:43:28 +08:00
|
|
|
AddStep("set all players queue mode", () => MultiplayerClient.ChangeSettings(new MultiplayerRoomSettings { QueueMode = QueueMode.AllPlayers }).WaitSafely());
|
2024-11-13 17:57:51 +08:00
|
|
|
AddUntilStep("wait for queue mode change", () => MultiplayerClient.ClientAPIRoom?.QueueMode == QueueMode.AllPlayers);
|
2021-12-09 01:12:33 +08:00
|
|
|
|
|
|
|
addPlaylistItem(() => API.LocalUser.Value.OnlineID);
|
2021-12-09 13:11:29 +08:00
|
|
|
assertDeleteButtonVisibility(1, true);
|
2021-12-09 01:12:33 +08:00
|
|
|
addPlaylistItem(() => 1234);
|
2021-12-09 13:11:29 +08:00
|
|
|
assertDeleteButtonVisibility(2, true);
|
2021-12-09 01:12:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2021-12-09 13:11:29 +08:00
|
|
|
public void TestDeleteButtonOnlyVisibleForItemOwnerIfNotHost()
|
2021-12-09 01:12:33 +08:00
|
|
|
{
|
2022-02-16 08:43:28 +08:00
|
|
|
AddStep("set all players queue mode", () => MultiplayerClient.ChangeSettings(new MultiplayerRoomSettings { QueueMode = QueueMode.AllPlayers }).WaitSafely());
|
2024-11-13 17:57:51 +08:00
|
|
|
AddUntilStep("wait for queue mode change", () => MultiplayerClient.ClientAPIRoom?.QueueMode == QueueMode.AllPlayers);
|
2021-12-09 01:12:33 +08:00
|
|
|
|
2022-02-16 08:43:28 +08:00
|
|
|
AddStep("join other user", () => MultiplayerClient.AddUser(new APIUser { Id = 1234 }));
|
|
|
|
AddStep("set other user as host", () => MultiplayerClient.TransferHost(1234));
|
2021-12-09 13:11:29 +08:00
|
|
|
|
2021-12-09 01:12:33 +08:00
|
|
|
addPlaylistItem(() => API.LocalUser.Value.OnlineID);
|
|
|
|
assertDeleteButtonVisibility(1, true);
|
|
|
|
addPlaylistItem(() => 1234);
|
|
|
|
assertDeleteButtonVisibility(2, false);
|
|
|
|
|
2022-02-16 08:43:28 +08:00
|
|
|
AddStep("set local user as host", () => MultiplayerClient.TransferHost(API.LocalUser.Value.OnlineID));
|
2021-12-09 13:11:29 +08:00
|
|
|
assertDeleteButtonVisibility(1, true);
|
|
|
|
assertDeleteButtonVisibility(2, true);
|
2021-12-09 01:12:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2022-10-17 18:34:05 +08:00
|
|
|
public void TestSingleItemDoesNotHaveDeleteButton()
|
|
|
|
{
|
|
|
|
AddStep("set all players queue mode", () => MultiplayerClient.ChangeSettings(new MultiplayerRoomSettings { QueueMode = QueueMode.AllPlayers }).WaitSafely());
|
2024-11-13 17:57:51 +08:00
|
|
|
AddUntilStep("wait for queue mode change", () => MultiplayerClient.ClientAPIRoom?.QueueMode == QueueMode.AllPlayers);
|
2022-10-17 18:34:05 +08:00
|
|
|
|
|
|
|
assertDeleteButtonVisibility(0, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestCurrentItemHasDeleteButtonIfNotSingle()
|
2021-12-09 01:12:33 +08:00
|
|
|
{
|
2022-02-16 08:43:28 +08:00
|
|
|
AddStep("set all players queue mode", () => MultiplayerClient.ChangeSettings(new MultiplayerRoomSettings { QueueMode = QueueMode.AllPlayers }).WaitSafely());
|
2024-11-13 17:57:51 +08:00
|
|
|
AddUntilStep("wait for queue mode change", () => MultiplayerClient.ClientAPIRoom?.QueueMode == QueueMode.AllPlayers);
|
2021-12-09 01:12:33 +08:00
|
|
|
|
2021-12-09 13:11:29 +08:00
|
|
|
addPlaylistItem(() => API.LocalUser.Value.OnlineID);
|
2021-12-10 19:08:59 +08:00
|
|
|
|
2022-10-17 18:34:05 +08:00
|
|
|
assertDeleteButtonVisibility(0, true);
|
2021-12-09 13:11:29 +08:00
|
|
|
assertDeleteButtonVisibility(1, true);
|
|
|
|
|
2022-02-16 08:43:28 +08:00
|
|
|
AddStep("finish current item", () => MultiplayerClient.FinishCurrentItem().WaitSafely());
|
2022-07-01 17:58:22 +08:00
|
|
|
AddUntilStep("wait for next item to be selected", () => MultiplayerClient.ClientRoom?.Settings.PlaylistItemId == 2);
|
2021-12-22 08:55:16 +08:00
|
|
|
AddUntilStep("wait for two items in playlist", () => playlist.ChildrenOfType<DrawableRoomPlaylistItem>().Count() == 2);
|
2021-12-21 17:38:31 +08:00
|
|
|
|
|
|
|
assertDeleteButtonVisibility(0, false);
|
2021-12-09 13:11:29 +08:00
|
|
|
assertDeleteButtonVisibility(1, false);
|
2021-12-09 01:12:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void addPlaylistItem(Func<int> userId)
|
|
|
|
{
|
|
|
|
long itemId = -1;
|
|
|
|
|
|
|
|
AddStep("add playlist item", () =>
|
|
|
|
{
|
2023-05-25 19:09:40 +08:00
|
|
|
MultiplayerPlaylistItem item = TestMultiplayerClient.CreateMultiplayerPlaylistItem(new PlaylistItem(importedBeatmap));
|
2021-12-09 01:12:33 +08:00
|
|
|
|
2022-02-16 08:43:28 +08:00
|
|
|
MultiplayerClient.AddUserPlaylistItem(userId(), item).WaitSafely();
|
2021-12-09 01:12:33 +08: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 08:55:16 +08: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-09 01:12:33 +08:00
|
|
|
}
|
|
|
|
}
|