2021-07-13 14:10:44 +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.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Testing;
|
2021-11-04 17:02:44 +08:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2021-07-13 14:10:44 +08:00
|
|
|
using osu.Game.Online.Rooms;
|
2021-07-13 15:02:18 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
2021-07-13 14:10:44 +08:00
|
|
|
using osu.Game.Tests.Visual.OnlinePlay;
|
|
|
|
using osu.Game.Users.Drawables;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Multiplayer
|
|
|
|
{
|
2021-09-29 18:15:58 +08:00
|
|
|
public partial class TestSceneDrawableRoomParticipantsList : OnlinePlayTestScene
|
2021-07-13 14:10:44 +08:00
|
|
|
{
|
2024-11-13 15:55:18 +08:00
|
|
|
private DrawableRoomParticipantsList list = null!;
|
2021-07-13 14:10:44 +08:00
|
|
|
|
2022-07-29 14:27:39 +08:00
|
|
|
public override void SetUpSteps()
|
2021-07-13 14:10:44 +08:00
|
|
|
{
|
2022-07-29 14:27:39 +08:00
|
|
|
base.SetUpSteps();
|
|
|
|
|
|
|
|
AddStep("create list", () =>
|
2021-09-29 18:34:40 +08:00
|
|
|
{
|
2022-07-29 14:27:39 +08:00
|
|
|
SelectedRoom.Value = new Room
|
2021-09-29 18:34:40 +08:00
|
|
|
{
|
2024-11-13 15:55:18 +08:00
|
|
|
Name = "test room",
|
2024-11-13 16:32:32 +08:00
|
|
|
Host = new APIUser
|
2021-09-29 18:34:40 +08:00
|
|
|
{
|
2024-11-13 16:32:32 +08:00
|
|
|
Id = 2,
|
|
|
|
Username = "peppy",
|
2021-09-29 18:34:40 +08:00
|
|
|
}
|
2022-07-29 14:27:39 +08:00
|
|
|
};
|
2021-07-13 14:10:44 +08:00
|
|
|
|
2024-11-13 16:32:32 +08:00
|
|
|
Child = list = new DrawableRoomParticipantsList(SelectedRoom.Value)
|
2022-07-29 14:27:39 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
NumberOfCircles = 4
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
2021-07-13 14:10:44 +08:00
|
|
|
|
|
|
|
[Test]
|
2021-08-12 17:10:06 +08:00
|
|
|
public void TestCircleCountNearLimit()
|
|
|
|
{
|
|
|
|
AddStep("add 8 users", () =>
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
addUser(i);
|
|
|
|
});
|
2021-08-12 17:47:22 +08:00
|
|
|
|
2021-08-12 17:10:06 +08:00
|
|
|
AddStep("set 8 circles", () => list.NumberOfCircles = 8);
|
2021-09-29 18:15:58 +08:00
|
|
|
AddAssert("0 hidden users", () => list.ChildrenOfType<DrawableRoomParticipantsList.HiddenUserCount>().Single().Count == 0);
|
2021-08-12 17:10:06 +08:00
|
|
|
|
|
|
|
AddStep("add one more user", () => addUser(9));
|
2021-09-29 18:15:58 +08:00
|
|
|
AddAssert("2 hidden users", () => list.ChildrenOfType<DrawableRoomParticipantsList.HiddenUserCount>().Single().Count == 2);
|
2021-08-12 17:10:06 +08:00
|
|
|
|
|
|
|
AddStep("remove first user", () => removeUserAt(0));
|
2021-09-29 18:15:58 +08:00
|
|
|
AddAssert("0 hidden users", () => list.ChildrenOfType<DrawableRoomParticipantsList.HiddenUserCount>().Single().Count == 0);
|
2021-08-12 17:10:06 +08:00
|
|
|
|
|
|
|
AddStep("add one more user", () => addUser(9));
|
2021-09-29 18:15:58 +08:00
|
|
|
AddAssert("2 hidden users", () => list.ChildrenOfType<DrawableRoomParticipantsList.HiddenUserCount>().Single().Count == 2);
|
2021-08-12 17:10:06 +08:00
|
|
|
|
|
|
|
AddStep("remove last user", () => removeUserAt(8));
|
2021-09-29 18:15:58 +08:00
|
|
|
AddAssert("0 hidden users", () => list.ChildrenOfType<DrawableRoomParticipantsList.HiddenUserCount>().Single().Count == 0);
|
2021-08-12 17:10:06 +08:00
|
|
|
}
|
|
|
|
|
2021-08-12 17:47:22 +08:00
|
|
|
[Test]
|
|
|
|
public void TestHiddenUsersBecomeDisplayed()
|
|
|
|
{
|
|
|
|
AddStep("add 8 users", () =>
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
addUser(i);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("set 3 circles", () => list.NumberOfCircles = 3);
|
|
|
|
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
AddStep("remove user", () => removeUserAt(0));
|
2021-09-30 11:01:28 +08:00
|
|
|
int remainingUsers = 8 - i;
|
2021-08-12 17:47:22 +08:00
|
|
|
|
2021-09-30 11:01:28 +08:00
|
|
|
int displayedUsers = remainingUsers > 4 ? 3 : remainingUsers;
|
2021-08-12 17:47:22 +08:00
|
|
|
AddAssert($"{displayedUsers} avatars displayed", () => list.ChildrenOfType<UpdateableAvatar>().Count() == displayedUsers);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-12 17:10:06 +08:00
|
|
|
[Test]
|
|
|
|
public void TestCircleCount()
|
2021-07-13 14:10:44 +08:00
|
|
|
{
|
|
|
|
AddStep("add 50 users", () =>
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 50; i++)
|
2021-08-05 21:49:41 +08:00
|
|
|
addUser(i);
|
2021-07-13 14:10:44 +08:00
|
|
|
});
|
|
|
|
|
2021-08-12 17:10:06 +08:00
|
|
|
AddStep("set 3 circles", () => list.NumberOfCircles = 3);
|
2021-09-30 11:01:28 +08:00
|
|
|
AddAssert("3 users displayed", () => list.ChildrenOfType<UpdateableAvatar>().Count() == 3);
|
2021-09-29 18:15:58 +08:00
|
|
|
AddAssert("48 hidden users", () => list.ChildrenOfType<DrawableRoomParticipantsList.HiddenUserCount>().Single().Count == 48);
|
2021-07-13 14:10:44 +08:00
|
|
|
|
2021-08-12 17:10:06 +08:00
|
|
|
AddStep("set 10 circles", () => list.NumberOfCircles = 10);
|
2021-09-30 11:01:28 +08:00
|
|
|
AddAssert("10 users displayed", () => list.ChildrenOfType<UpdateableAvatar>().Count() == 10);
|
2021-09-29 18:15:58 +08:00
|
|
|
AddAssert("41 hidden users", () => list.ChildrenOfType<DrawableRoomParticipantsList.HiddenUserCount>().Single().Count == 41);
|
2021-07-13 14:10:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestAddAndRemoveUsers()
|
|
|
|
{
|
|
|
|
AddStep("add 50 users", () =>
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 50; i++)
|
2021-08-05 21:49:41 +08:00
|
|
|
addUser(i);
|
2021-07-13 14:10:44 +08:00
|
|
|
});
|
|
|
|
|
2021-08-05 21:49:41 +08:00
|
|
|
AddStep("remove from start", () => removeUserAt(0));
|
2021-09-30 11:01:28 +08:00
|
|
|
AddAssert("4 circles displayed", () => list.ChildrenOfType<UpdateableAvatar>().Count() == 4);
|
2021-09-29 18:15:58 +08:00
|
|
|
AddAssert("46 hidden users", () => list.ChildrenOfType<DrawableRoomParticipantsList.HiddenUserCount>().Single().Count == 46);
|
2021-07-13 14:10:44 +08:00
|
|
|
|
2024-11-21 19:26:44 +08:00
|
|
|
AddStep("remove from end", () => removeUserAt(SelectedRoom.Value!.RecentParticipants.Count - 1));
|
2021-09-30 11:01:28 +08:00
|
|
|
AddAssert("4 circles displayed", () => list.ChildrenOfType<UpdateableAvatar>().Count() == 4);
|
2021-09-29 18:15:58 +08:00
|
|
|
AddAssert("45 hidden users", () => list.ChildrenOfType<DrawableRoomParticipantsList.HiddenUserCount>().Single().Count == 45);
|
2021-07-13 14:10:44 +08:00
|
|
|
|
2021-08-05 21:49:41 +08:00
|
|
|
AddRepeatStep("remove 45 users", () => removeUserAt(0), 45);
|
2021-09-30 11:01:28 +08:00
|
|
|
AddAssert("4 circles displayed", () => list.ChildrenOfType<UpdateableAvatar>().Count() == 4);
|
2021-09-29 18:15:58 +08:00
|
|
|
AddAssert("0 hidden users", () => list.ChildrenOfType<DrawableRoomParticipantsList.HiddenUserCount>().Single().Count == 0);
|
|
|
|
AddAssert("hidden users bubble hidden", () => list.ChildrenOfType<DrawableRoomParticipantsList.HiddenUserCount>().Single().Alpha < 0.5f);
|
2021-07-13 14:10:44 +08:00
|
|
|
|
2021-08-05 21:49:41 +08:00
|
|
|
AddStep("remove another user", () => removeUserAt(0));
|
2021-09-30 11:01:28 +08:00
|
|
|
AddAssert("3 circles displayed", () => list.ChildrenOfType<UpdateableAvatar>().Count() == 3);
|
2021-09-29 18:15:58 +08:00
|
|
|
AddAssert("0 hidden users", () => list.ChildrenOfType<DrawableRoomParticipantsList.HiddenUserCount>().Single().Count == 0);
|
2021-07-13 14:10:44 +08:00
|
|
|
|
2021-08-05 21:49:41 +08:00
|
|
|
AddRepeatStep("remove the remaining two users", () => removeUserAt(0), 2);
|
2021-09-30 11:01:28 +08:00
|
|
|
AddAssert("1 circle displayed", () => list.ChildrenOfType<UpdateableAvatar>().Count() == 1);
|
2021-07-13 14:10:44 +08:00
|
|
|
}
|
2021-08-05 21:49:41 +08:00
|
|
|
|
|
|
|
private void addUser(int id)
|
|
|
|
{
|
2024-11-21 19:26:44 +08:00
|
|
|
SelectedRoom.Value!.RecentParticipants = SelectedRoom.Value!.RecentParticipants.Append(new APIUser
|
2021-08-05 21:49:41 +08:00
|
|
|
{
|
|
|
|
Id = id,
|
|
|
|
Username = $"User {id}"
|
2024-11-14 14:07:16 +08:00
|
|
|
}).ToArray();
|
2024-11-21 19:26:44 +08:00
|
|
|
SelectedRoom.Value!.ParticipantCount++;
|
2021-08-05 21:49:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void removeUserAt(int index)
|
|
|
|
{
|
2024-11-21 19:26:44 +08:00
|
|
|
SelectedRoom.Value!.RecentParticipants = SelectedRoom.Value!.RecentParticipants.Where(u => !u.Equals(SelectedRoom.Value!.RecentParticipants[index])).ToArray();
|
|
|
|
SelectedRoom.Value!.ParticipantCount--;
|
2021-08-05 21:49:41 +08:00
|
|
|
}
|
2021-07-13 14:10:44 +08:00
|
|
|
}
|
|
|
|
}
|