1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 05:07:50 +08:00
osu-lazer/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoom.cs

231 lines
9.9 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;
using osu.Game.Online.Multiplayer;
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;
using osu.Game.Screens.OnlinePlay.Match;
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
[Test]
public void TestMultiplayerRooms()
{
AddStep("create rooms", () => Child = new FillFlowContainer
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Direction = FillDirection.Vertical,
Spacing = new Vector2(5),
Children = new[]
{
new DrawableMatchRoom(new Room
{
Name = { Value = "A host-only room" },
QueueMode = { Value = QueueMode.HostOnly },
Type = { Value = MatchType.HeadToHead }
}),
new DrawableMatchRoom(new Room
{
Name = { Value = "An all-players, team-versus room" },
QueueMode = { Value = QueueMode.AllPlayers },
Type = { Value = MatchType.TeamVersus }
}),
new DrawableMatchRoom(new Room
{
Name = { Value = "A round-robin room" },
QueueMode = { Value = QueueMode.AllPlayersRoundRobin },
Type = { Value = MatchType.HeadToHead }
}),
}
});
}
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
}
}