1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 03:02:53 +08:00
osu-lazer/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoom.cs

196 lines
8.5 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;
using osu.Game.Online.API.Requests.Responses;
2020-12-25 12:38:11 +08:00
using osu.Game.Online.Rooms;
using osu.Game.Online.Rooms.RoomStatuses;
using osu.Game.Overlays;
2021-08-05 19:56:14 +08:00
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.OnlinePlay.Lounge;
using osu.Game.Screens.OnlinePlay.Lounge.Components;
2021-08-05 19:56:14 +08:00
using osu.Game.Tests.Beatmaps;
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
{
[Cached]
protected readonly OverlayColourProvider ColourProvider = new OverlayColourProvider(OverlayColourScheme.Plum);
private readonly Bindable<Room> selectedRoom = new Bindable<Room>();
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[]
{
2021-09-29 19:24:49 +08:00
createLoungeRoom(new Room
2021-08-03 19:32:51 +08:00
{
2021-09-29 19:24:49 +08:00
Name = { Value = "Multiplayer room" },
2021-08-03 19:32:51 +08:00
Status = { Value = new RoomStatusOpen() },
EndDate = { Value = DateTimeOffset.Now.AddDays(1) },
2021-09-29 19:24:49 +08:00
Type = { Value = MatchType.HeadToHead },
2021-08-05 19:56:14 +08:00
Playlist =
{
new PlaylistItem
{
Beatmap =
{
Value = new TestBeatmap(new OsuRuleset().RulesetInfo)
{
BeatmapInfo =
{
StarRating = 2.5
2021-08-05 19:56:14 +08:00
}
}.BeatmapInfo,
}
}
}
2021-08-03 19:32:51 +08:00
}),
2021-09-29 19:24:49 +08:00
createLoungeRoom(new Room
{
Name = { Value = "Multiplayer room" },
Status = { Value = new RoomStatusOpen() },
EndDate = { Value = DateTimeOffset.Now.AddDays(1) },
Type = { Value = MatchType.HeadToHead },
Playlist =
{
new PlaylistItem
{
Beatmap =
{
Value = new TestBeatmap(new OsuRuleset().RulesetInfo)
{
BeatmapInfo =
{
StarRating = 2.5,
Metadata =
{
Artist = "very very very very very very very very very long artist",
ArtistUnicode = "very very very very very very very very very long artist",
Title = "very very very very very very very very very very very long title",
TitleUnicode = "very very very very very very very very very very very long title",
}
}
}.BeatmapInfo,
}
}
}
}),
createLoungeRoom(new Room
2021-08-03 19:32:51 +08:00
{
2021-09-29 19:24:49 +08:00
Name = { Value = "Playlist room with multiple beatmaps" },
2021-08-03 19:32:51 +08:00
Status = { Value = new RoomStatusPlaying() },
EndDate = { Value = DateTimeOffset.Now.AddDays(1) },
2021-08-05 19:56:14 +08:00
Playlist =
{
new PlaylistItem
{
Beatmap =
{
Value = new TestBeatmap(new OsuRuleset().RulesetInfo)
{
BeatmapInfo =
{
StarRating = 2.5
2021-08-05 19:56:14 +08:00
}
}.BeatmapInfo,
}
},
new PlaylistItem
{
Beatmap =
{
Value = new TestBeatmap(new OsuRuleset().RulesetInfo)
{
BeatmapInfo =
{
StarRating = 4.5
2021-08-05 19:56:14 +08:00
}
}.BeatmapInfo,
}
}
}
2021-08-03 19:32:51 +08:00
}),
2021-09-29 19:24:49 +08:00
createLoungeRoom(new Room
2021-08-03 19:32:51 +08:00
{
2021-09-29 19:24:49 +08:00
Name = { Value = "Finished room" },
2021-08-03 19:32:51 +08:00
Status = { Value = new RoomStatusEnded() },
EndDate = { Value = DateTimeOffset.Now },
}),
2021-09-29 19:24:49 +08:00
createLoungeRoom(new Room
2021-08-03 19:32:51 +08:00
{
2021-09-29 19:24:49 +08:00
Name = { Value = "Spotlight room" },
2021-08-03 19:32:51 +08:00
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-09-29 19:24:49 +08:00
AddStep("create room", () => Child = drawableRoom = createLoungeRoom(room = new Room
{
Name = { Value = "Room with password" },
Status = { Value = new RoomStatusOpen() },
Type = { Value = MatchType.HeadToHead },
2021-08-03 19:32:51 +08:00
}));
AddUntilStep("wait for panel load", () => drawableRoom.ChildrenOfType<DrawableRoomParticipantsList>().Any());
2021-09-08 23:39:54 +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
2021-09-29 19:24:49 +08:00
private DrawableRoom createLoungeRoom(Room room)
2021-08-03 19:32:51 +08:00
{
room.Host.Value ??= new APIUser { Username = "peppy", Id = 2 };
2021-08-03 19:32:51 +08:00
if (room.RecentParticipants.Count == 0)
{
room.RecentParticipants.AddRange(Enumerable.Range(0, 20).Select(i => new APIUser
2021-08-03 19:32:51 +08:00
{
Id = i,
Username = $"User {i}"
}));
}
return new DrawableLoungeRoom(room)
{
MatchingFilter = true,
SelectedRoom = { BindTarget = selectedRoom }
};
2021-08-03 19:32:51 +08:00
}
2018-12-27 12:30:36 +08:00
}
}