1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 00:07:24 +08:00
osu-lazer/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoom.cs

118 lines
4.7 KiB
C#
Raw Normal View History

// 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.
2018-12-27 12:30:36 +08:00
2020-12-18 14:18:06 +08:00
using System;
2021-07-13 14:10:44 +08:00
using System.Linq;
using NUnit.Framework;
2021-08-03 19:32:51 +08:00
using osu.Framework.Allocation;
using osu.Framework.Bindables;
2018-12-27 12:30:36 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Framework.Utils;
2021-07-06 17:23:37 +08:00
using osu.Game.Graphics.UserInterface;
2020-12-25 12:38:11 +08:00
using osu.Game.Online.Rooms;
using osu.Game.Online.Rooms.RoomStatuses;
using osu.Game.Screens.OnlinePlay.Lounge.Components;
2021-07-12 15:28:22 +08:00
using osu.Game.Users;
2021-07-06 19:04:32 +08:00
using osuTK;
2018-12-27 12:30:36 +08:00
2019-03-25 00:02:36 +08:00
namespace osu.Game.Tests.Visual.Multiplayer
2018-12-27 12:30:36 +08:00
{
2021-07-06 17:10:40 +08:00
public class TestSceneDrawableRoom : OsuTestScene
2018-12-27 12:30:36 +08:00
{
2021-08-03 19:32:51 +08:00
[Cached]
private readonly Bindable<Room> selectedRoom = new Bindable<Room>();
2021-07-06 17:23:37 +08:00
2021-08-03 19:32:51 +08:00
[Test]
public void TestMultipleStatuses()
2021-07-06 17:23:37 +08:00
{
2021-08-03 19:32:51 +08:00
AddStep("create rooms", () =>
2021-07-06 17:23:37 +08:00
{
2021-08-03 19:32:51 +08:00
Child = new FillFlowContainer
2021-07-13 14:10:44 +08:00
{
2021-08-03 19:32:51 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.9f),
Spacing = new Vector2(10),
Children = new Drawable[]
{
createDrawableRoom(new Room
{
Name = { Value = "Room 1" },
Status = { Value = new RoomStatusOpen() },
EndDate = { Value = DateTimeOffset.Now.AddDays(1) },
}),
createDrawableRoom(new Room
{
Name = { Value = "Room 2" },
Status = { Value = new RoomStatusPlaying() },
EndDate = { Value = DateTimeOffset.Now.AddDays(1) },
}),
createDrawableRoom(new Room
{
Name = { Value = "Room 3" },
Status = { Value = new RoomStatusEnded() },
EndDate = { Value = DateTimeOffset.Now },
}),
createDrawableRoom(new Room
{
Name = { Value = "Room 4 (realtime)" },
Status = { Value = new RoomStatusOpen() },
Category = { Value = RoomCategory.Realtime },
}),
createDrawableRoom(new Room
{
Name = { Value = "Room 4 (spotlight)" },
Status = { Value = new RoomStatusOpen() },
Category = { Value = RoomCategory.Spotlight },
}),
}
};
});
2021-07-06 17:23:37 +08:00
}
[Test]
public void TestEnableAndDisablePassword()
{
DrawableRoom drawableRoom = null;
Room room = null;
2021-08-03 19:32:51 +08:00
AddStep("create room", () => Child = drawableRoom = createDrawableRoom(room = new Room
{
Name = { Value = "Room with password" },
Status = { Value = new RoomStatusOpen() },
Category = { Value = RoomCategory.Realtime },
2021-08-03 19:32:51 +08:00
}));
AddAssert("password icon hidden", () => Precision.AlmostEquals(0, drawableRoom.ChildrenOfType<DrawableRoom.PasswordProtectedIcon>().Single().Alpha));
AddStep("set password", () => room.Password.Value = "password");
AddAssert("password icon visible", () => Precision.AlmostEquals(1, drawableRoom.ChildrenOfType<DrawableRoom.PasswordProtectedIcon>().Single().Alpha));
AddStep("unset password", () => room.Password.Value = string.Empty);
AddAssert("password icon hidden", () => Precision.AlmostEquals(0, drawableRoom.ChildrenOfType<DrawableRoom.PasswordProtectedIcon>().Single().Alpha));
}
2021-08-03 19:32:51 +08:00
private DrawableRoom createDrawableRoom(Room room)
{
room.Host.Value ??= new User { Username = "peppy", Id = 2 };
if (room.RecentParticipants.Count == 0)
{
room.RecentParticipants.AddRange(Enumerable.Range(0, 20).Select(i => new User
{
Id = i,
Username = $"User {i}"
}));
}
var drawableRoom = new DrawableRoom(room) { MatchingFilter = true };
drawableRoom.Action = () => drawableRoom.State = drawableRoom.State == SelectionState.Selected ? SelectionState.NotSelected : SelectionState.Selected;
return drawableRoom;
}
2018-12-27 12:30:36 +08:00
}
}