2019-01-24 16:43:03 +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.
2018-12-27 12:30:36 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
2020-12-18 14:18:06 +08:00
using System ;
2021-07-13 14:10:44 +08:00
using System.Linq ;
2021-08-03 19:02:31 +08:00
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 ;
2021-08-03 19:02:31 +08:00
using osu.Framework.Testing ;
using osu.Framework.Utils ;
2022-04-11 12:43:43 +08:00
using osu.Game.Graphics.Sprites ;
2021-11-04 17:02:44 +08:00
using osu.Game.Online.API.Requests.Responses ;
2021-12-07 17:53:08 +08:00
using osu.Game.Online.Multiplayer ;
2020-12-25 12:38:11 +08:00
using osu.Game.Online.Rooms ;
using osu.Game.Online.Rooms.RoomStatuses ;
2021-08-12 16:02:55 +08:00
using osu.Game.Overlays ;
2021-08-05 19:56:14 +08:00
using osu.Game.Rulesets.Osu ;
2021-08-18 19:53:17 +08:00
using osu.Game.Screens.OnlinePlay.Lounge ;
2020-12-25 23:50:00 +08:00
using osu.Game.Screens.OnlinePlay.Lounge.Components ;
2021-12-07 17:53:08 +08:00
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
{
2021-08-12 16:02:55 +08:00
[Cached]
protected readonly OverlayColourProvider ColourProvider = new OverlayColourProvider ( OverlayColourScheme . Plum ) ;
2021-08-19 15:49:08 +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
{
2022-04-11 12:43:43 +08:00
FillFlowContainer rooms = null ;
2021-08-03 19:32:51 +08:00
AddStep ( "create rooms" , ( ) = >
2021-07-06 17:23:37 +08:00
{
2022-04-11 12:43:43 +08:00
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
{
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 =
{
2022-02-15 22:33:26 +08:00
new PlaylistItem ( new TestBeatmap ( new OsuRuleset ( ) . RulesetInfo )
2021-08-05 19:56:14 +08:00
{
2022-02-15 22:33:26 +08:00
BeatmapInfo =
2021-08-05 19:56:14 +08:00
{
2022-02-15 22:33:26 +08:00
StarRating = 2.5
2021-08-05 19:56:14 +08:00
}
2022-02-15 22:33:26 +08:00
} . BeatmapInfo )
2021-08-05 19:56:14 +08:00
}
2021-08-03 19:32:51 +08:00
} ) ,
2021-09-29 19:24:49 +08:00
createLoungeRoom ( new Room
2021-11-04 00:32:18 +08:00
{
2024-05-03 17:25:50 +08:00
Name = { Value = "Private room" } ,
Status = { Value = new RoomStatusOpenPrivate ( ) } ,
HasPassword = { Value = true } ,
2021-11-04 00:32:18 +08:00
EndDate = { Value = DateTimeOffset . Now . AddDays ( 1 ) } ,
Type = { Value = MatchType . HeadToHead } ,
Playlist =
{
2022-02-15 22:33:26 +08:00
new PlaylistItem ( new TestBeatmap ( new OsuRuleset ( ) . RulesetInfo )
2021-11-04 00:32:18 +08:00
{
2022-02-15 22:33:26 +08:00
BeatmapInfo =
2021-11-04 00:32:18 +08:00
{
2022-02-15 22:33:26 +08:00
StarRating = 2.5 ,
Metadata =
2021-11-04 00:32:18 +08:00
{
2022-02-15 22:33:26 +08:00
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" ,
}
2021-11-04 00:32:18 +08:00
}
2022-02-15 22:33:26 +08:00
} . BeatmapInfo )
2021-11-04 00:32:18 +08:00
}
} ) ,
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 =
{
2022-02-15 22:33:26 +08:00
new PlaylistItem ( new TestBeatmap ( new OsuRuleset ( ) . RulesetInfo )
2021-08-05 19:56:14 +08:00
{
2022-02-15 22:33:26 +08:00
BeatmapInfo =
2021-08-05 19:56:14 +08:00
{
2022-02-15 22:33:26 +08:00
StarRating = 2.5
2021-08-05 19:56:14 +08:00
}
2022-02-15 22:33:26 +08:00
} . BeatmapInfo ) ,
new PlaylistItem ( new TestBeatmap ( new OsuRuleset ( ) . RulesetInfo )
2021-08-05 19:56:14 +08:00
{
2022-02-15 22:33:26 +08:00
BeatmapInfo =
2021-08-05 19:56:14 +08:00
{
2022-02-15 22:33:26 +08:00
StarRating = 4.5
2021-08-05 19:56:14 +08:00
}
2022-02-15 22:33:26 +08:00
} . BeatmapInfo )
2021-08-05 19:56:14 +08:00
}
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 } ,
} ) ,
2022-05-27 19:18:46 +08:00
createLoungeRoom ( new Room
{
Name = { Value = "Featured artist room" } ,
Status = { Value = new RoomStatusOpen ( ) } ,
Category = { Value = RoomCategory . FeaturedArtist } ,
} ) ,
2021-08-03 19:32:51 +08:00
}
} ;
} ) ;
2022-04-11 12:43:43 +08:00
2022-05-27 19:58:13 +08:00
AddUntilStep ( "wait for panel load" , ( ) = > rooms . Count = = 6 ) ;
2022-04-11 12:43:43 +08:00
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
}
2021-08-03 19:02:31 +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
2021-08-03 19:02:31 +08:00
{
Name = { Value = "Room with password" } ,
Status = { Value = new RoomStatusOpen ( ) } ,
2021-08-19 15:09:17 +08:00
Type = { Value = MatchType . HeadToHead } ,
2021-08-03 19:32:51 +08:00
} ) ) ;
2021-08-03 19:02:31 +08:00
2021-09-29 18:15:58 +08:00
AddUntilStep ( "wait for panel load" , ( ) = > drawableRoom . ChildrenOfType < DrawableRoomParticipantsList > ( ) . Any ( ) ) ;
2021-09-08 23:39:54 +08:00
2021-08-03 19:02:31 +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-12-07 17:53:08 +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
{
2021-11-04 17:02:44 +08:00
room . Host . Value ? ? = new APIUser { Username = "peppy" , Id = 2 } ;
2021-08-03 19:32:51 +08:00
if ( room . RecentParticipants . Count = = 0 )
{
2021-11-04 17:02:44 +08:00
room . RecentParticipants . AddRange ( Enumerable . Range ( 0 , 20 ) . Select ( i = > new APIUser
2021-08-03 19:32:51 +08:00
{
Id = i ,
Username = $"User {i}"
} ) ) ;
}
2021-08-19 15:49:08 +08:00
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
}
}