1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-19 10:52:55 +08:00
osu-lazer/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoom.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

217 lines
8.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;
using osu.Game.Graphics.Sprites;
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 partial class TestSceneDrawableRoom : OsuTestScene
2018-12-27 12:30:36 +08:00
{
[Cached]
protected readonly OverlayColourProvider ColourProvider = new OverlayColourProvider(OverlayColourScheme.Plum);
2024-11-13 15:55:18 +08:00
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
{
2024-11-13 15:55:18 +08:00
FillFlowContainer rooms = null!;
2021-08-03 19:32:51 +08:00
AddStep("create rooms", () =>
2021-07-06 17:23:37 +08:00
{
PlaylistItem item1 = new PlaylistItem(new TestBeatmap(new OsuRuleset().RulesetInfo)
{
BeatmapInfo = { StarRating = 2.5 }
}.BeatmapInfo);
PlaylistItem item2 = new PlaylistItem(new TestBeatmap(new OsuRuleset().RulesetInfo)
{
BeatmapInfo = { StarRating = 4.5 }
}.BeatmapInfo);
PlaylistItem item3 = new PlaylistItem(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);
Child = rooms = 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
{
2024-11-13 15:55:18 +08:00
Name = "Multiplayer room",
2024-11-13 17:48:13 +08:00
Status = new RoomStatusOpen(),
EndDate = DateTimeOffset.Now.AddDays(1),
2024-11-13 17:36:47 +08:00
Type = MatchType.HeadToHead,
2024-11-14 16:57:32 +08:00
Playlist = [item1],
CurrentPlaylistItem = item1
2021-08-03 19:32:51 +08:00
}),
2021-09-29 19:24:49 +08:00
createLoungeRoom(new Room
{
2024-11-13 15:55:18 +08:00
Name = "Private room",
2024-11-13 17:48:13 +08:00
Status = new RoomStatusOpenPrivate(),
Password = "*",
EndDate = DateTimeOffset.Now.AddDays(1),
2024-11-13 17:36:47 +08:00
Type = MatchType.HeadToHead,
2024-11-14 16:57:32 +08:00
Playlist = [item3],
CurrentPlaylistItem = item3
}),
createLoungeRoom(new Room
2021-08-03 19:32:51 +08:00
{
2024-11-13 15:55:18 +08:00
Name = "Playlist room with multiple beatmaps",
2024-11-13 17:48:13 +08:00
Status = new RoomStatusPlaying(),
EndDate = DateTimeOffset.Now.AddDays(1),
2024-11-14 16:57:32 +08:00
Playlist = [item1, item2],
CurrentPlaylistItem = item1
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
{
2024-11-13 15:55:18 +08:00
Name = "Finished room",
2024-11-13 17:48:13 +08:00
Status = new RoomStatusEnded(),
EndDate = DateTimeOffset.Now,
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
{
2024-11-13 15:55:18 +08:00
Name = "Spotlight room",
2024-11-13 17:48:13 +08:00
Status = new RoomStatusOpen(),
2024-11-13 17:27:32 +08:00
Category = RoomCategory.Spotlight,
2021-08-03 19:32:51 +08:00
}),
2022-05-27 19:18:46 +08:00
createLoungeRoom(new Room
{
2024-11-13 15:55:18 +08:00
Name = "Featured artist room",
2024-11-13 17:48:13 +08:00
Status = new RoomStatusOpen(),
2024-11-13 17:27:32 +08:00
Category = RoomCategory.FeaturedArtist,
2022-05-27 19:18:46 +08:00
}),
2021-08-03 19:32:51 +08:00
}
};
});
2022-05-27 19:58:13 +08:00
AddUntilStep("wait for panel load", () => rooms.Count == 6);
AddUntilStep("correct status text", () => rooms.ChildrenOfType<OsuSpriteText>().Count(s => s.Text.ToString().StartsWith("Currently playing", StringComparison.Ordinal)) == 2);
2022-05-27 19:58:13 +08:00
AddUntilStep("correct status text", () => rooms.ChildrenOfType<OsuSpriteText>().Count(s => s.Text.ToString().StartsWith("Ready to play", StringComparison.Ordinal)) == 4);
2021-07-06 17:23:37 +08:00
}
[Test]
public void TestEnableAndDisablePassword()
{
2024-11-13 15:55:18 +08:00
DrawableRoom drawableRoom = null!;
Room room = null!;
2021-09-29 19:24:49 +08:00
AddStep("create room", () => Child = drawableRoom = createLoungeRoom(room = new Room
{
2024-11-13 15:55:18 +08:00
Name = "Room with password",
2024-11-13 17:48:13 +08:00
Status = new RoomStatusOpen(),
2024-11-13 17:36:47 +08:00
Type = 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 = "password");
AddAssert("password icon visible", () => Precision.AlmostEquals(1, drawableRoom.ChildrenOfType<DrawableRoom.PasswordProtectedIcon>().Single().Alpha));
AddStep("unset password", () => room.Password = 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
{
2024-11-13 15:55:18 +08:00
Name = "A host-only room",
2024-11-13 17:57:51 +08:00
QueueMode = QueueMode.HostOnly,
2024-11-13 17:36:47 +08:00
Type = MatchType.HeadToHead,
})
{
2024-11-13 15:55:18 +08:00
SelectedItem = new Bindable<PlaylistItem?>()
},
new DrawableMatchRoom(new Room
{
2024-11-13 15:55:18 +08:00
Name = "An all-players, team-versus room",
2024-11-13 17:57:51 +08:00
QueueMode = QueueMode.AllPlayers,
2024-11-13 17:36:47 +08:00
Type = MatchType.TeamVersus
})
{
2024-11-13 15:55:18 +08:00
SelectedItem = new Bindable<PlaylistItem?>()
},
new DrawableMatchRoom(new Room
{
2024-11-13 15:55:18 +08:00
Name = "A round-robin room",
2024-11-13 17:57:51 +08:00
QueueMode = QueueMode.AllPlayersRoundRobin,
2024-11-13 17:36:47 +08:00
Type = MatchType.HeadToHead
})
{
2024-11-13 15:55:18 +08:00
SelectedItem = new Bindable<PlaylistItem?>()
},
}
});
}
2021-09-29 19:24:49 +08:00
private DrawableRoom createLoungeRoom(Room room)
2021-08-03 19:32:51 +08:00
{
2024-11-13 16:32:32 +08:00
room.Host ??= new APIUser { Username = "peppy", Id = 2 };
2021-08-03 19:32:51 +08:00
if (room.RecentParticipants.Count == 0)
{
room.RecentParticipants = Enumerable.Range(0, 20).Select(i => new APIUser
2021-08-03 19:32:51 +08:00
{
Id = i,
Username = $"User {i}"
}).ToArray();
2021-08-03 19:32:51 +08:00
}
return new DrawableLoungeRoom(room)
{
MatchingFilter = true,
SelectedRoom = selectedRoom
};
2021-08-03 19:32:51 +08:00
}
2018-12-27 12:30:36 +08:00
}
}