2020-12-20 23:04:06 +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.
using System.Linq ;
using NUnit.Framework ;
2021-04-07 19:46:30 +08:00
using osu.Framework.Allocation ;
using osu.Framework.Audio ;
using osu.Framework.Platform ;
2020-12-20 23:04:06 +08:00
using osu.Framework.Screens ;
using osu.Framework.Testing ;
2021-04-07 19:46:30 +08:00
using osu.Game.Beatmaps ;
using osu.Game.Online.Multiplayer ;
2020-12-25 12:38:11 +08:00
using osu.Game.Online.Rooms ;
2021-04-07 19:46:30 +08:00
using osu.Game.Rulesets ;
2020-12-20 23:04:06 +08:00
using osu.Game.Rulesets.Osu ;
2021-04-16 15:16:28 +08:00
using osu.Game.Screens.OnlinePlay.Components ;
2020-12-25 23:50:00 +08:00
using osu.Game.Screens.OnlinePlay.Multiplayer ;
using osu.Game.Screens.OnlinePlay.Multiplayer.Match ;
2020-12-20 23:04:06 +08:00
using osu.Game.Tests.Beatmaps ;
2021-04-07 19:46:30 +08:00
using osu.Game.Tests.Resources ;
using osu.Game.Users ;
2020-12-20 23:04:06 +08:00
using osuTK.Input ;
2020-12-25 12:20:37 +08:00
namespace osu.Game.Tests.Visual.Multiplayer
2020-12-20 23:04:06 +08:00
{
2020-12-25 12:38:11 +08:00
public class TestSceneMultiplayerMatchSubScreen : MultiplayerTestScene
2020-12-20 23:04:06 +08:00
{
2020-12-25 12:38:11 +08:00
private MultiplayerMatchSubScreen screen ;
2020-12-20 23:04:06 +08:00
2021-04-07 19:46:30 +08:00
private BeatmapManager beatmaps ;
private RulesetStore rulesets ;
private BeatmapSetInfo importedSet ;
2020-12-25 12:38:11 +08:00
public TestSceneMultiplayerMatchSubScreen ( )
2020-12-20 23:04:06 +08:00
: base ( false )
{
}
2021-04-07 19:46:30 +08:00
[BackgroundDependencyLoader]
private void load ( GameHost host , AudioManager audio )
{
Dependencies . Cache ( rulesets = new RulesetStore ( ContextFactory ) ) ;
Dependencies . Cache ( beatmaps = new BeatmapManager ( LocalStorage , ContextFactory , rulesets , null , audio , host , Beatmap . Default ) ) ;
beatmaps . Import ( TestResources . GetQuickTestBeatmapForImport ( ) ) . Wait ( ) ;
importedSet = beatmaps . GetAllUsableBeatmapSetsEnumerable ( IncludedDetails . All ) . First ( ) ;
}
2020-12-20 23:04:06 +08:00
[SetUp]
public new void Setup ( ) = > Schedule ( ( ) = >
{
Room . Name . Value = "Test Room" ;
} ) ;
[SetUpSteps]
public void SetupSteps ( )
{
2020-12-25 12:38:11 +08:00
AddStep ( "load match" , ( ) = > LoadScreen ( screen = new MultiplayerMatchSubScreen ( Room ) ) ) ;
2020-12-20 23:04:06 +08:00
AddUntilStep ( "wait for load" , ( ) = > screen . IsCurrentScreen ( ) ) ;
}
[Test]
public void TestSettingValidity ( )
{
2020-12-25 12:38:11 +08:00
AddAssert ( "create button not enabled" , ( ) = > ! this . ChildrenOfType < MultiplayerMatchSettingsOverlay . CreateOrUpdateButton > ( ) . Single ( ) . Enabled . Value ) ;
2020-12-20 23:04:06 +08:00
AddStep ( "set playlist" , ( ) = >
{
Room . Playlist . Add ( new PlaylistItem
{
Beatmap = { Value = new TestBeatmap ( new OsuRuleset ( ) . RulesetInfo ) . BeatmapInfo } ,
Ruleset = { Value = new OsuRuleset ( ) . RulesetInfo } ,
} ) ;
} ) ;
2020-12-25 12:38:11 +08:00
AddAssert ( "create button enabled" , ( ) = > this . ChildrenOfType < MultiplayerMatchSettingsOverlay . CreateOrUpdateButton > ( ) . Single ( ) . Enabled . Value ) ;
2020-12-20 23:04:06 +08:00
}
[Test]
public void TestCreatedRoom ( )
{
AddStep ( "set playlist" , ( ) = >
{
Room . Playlist . Add ( new PlaylistItem
{
Beatmap = { Value = new TestBeatmap ( new OsuRuleset ( ) . RulesetInfo ) . BeatmapInfo } ,
Ruleset = { Value = new OsuRuleset ( ) . RulesetInfo } ,
} ) ;
} ) ;
AddStep ( "click create button" , ( ) = >
{
2020-12-25 12:38:11 +08:00
InputManager . MoveMouseTo ( this . ChildrenOfType < MultiplayerMatchSettingsOverlay . CreateOrUpdateButton > ( ) . Single ( ) ) ;
2020-12-20 23:04:06 +08:00
InputManager . Click ( MouseButton . Left ) ;
} ) ;
2021-04-08 20:38:58 +08:00
AddUntilStep ( "wait for join" , ( ) = > Client . Room ! = null ) ;
2020-12-20 23:04:06 +08:00
}
2021-04-07 19:46:30 +08:00
[Test]
public void TestStartMatchWhileSpectating ( )
{
AddStep ( "set playlist" , ( ) = >
{
Room . Playlist . Add ( new PlaylistItem
{
Beatmap = { Value = beatmaps . GetWorkingBeatmap ( importedSet . Beatmaps . First ( ) ) . BeatmapInfo } ,
Ruleset = { Value = new OsuRuleset ( ) . RulesetInfo } ,
} ) ;
} ) ;
AddStep ( "click create button" , ( ) = >
{
InputManager . MoveMouseTo ( this . ChildrenOfType < MultiplayerMatchSettingsOverlay . CreateOrUpdateButton > ( ) . Single ( ) ) ;
InputManager . Click ( MouseButton . Left ) ;
} ) ;
2021-04-08 20:38:58 +08:00
AddUntilStep ( "wait for room join" , ( ) = > Client . Room ! = null ) ;
2021-04-07 19:46:30 +08:00
AddStep ( "join other user (ready)" , ( ) = >
{
Client . AddUser ( new User { Id = 55 } ) ;
Client . ChangeUserState ( 55 , MultiplayerUserState . Ready ) ;
} ) ;
AddStep ( "click spectate button" , ( ) = >
{
InputManager . MoveMouseTo ( this . ChildrenOfType < MultiplayerSpectateButton > ( ) . Single ( ) ) ;
InputManager . Click ( MouseButton . Left ) ;
} ) ;
2021-04-16 15:16:28 +08:00
AddUntilStep ( "wait for ready button to be enabled" , ( ) = > this . ChildrenOfType < MultiplayerReadyButton > ( ) . Single ( ) . ChildrenOfType < ReadyButton > ( ) . Single ( ) . Enabled . Value ) ;
2021-04-07 19:46:30 +08:00
AddStep ( "click ready button" , ( ) = >
{
InputManager . MoveMouseTo ( this . ChildrenOfType < MultiplayerReadyButton > ( ) . Single ( ) ) ;
InputManager . Click ( MouseButton . Left ) ;
} ) ;
2021-04-12 12:42:14 +08:00
AddUntilStep ( "match started" , ( ) = > Client . Room ? . State = = MultiplayerRoomState . WaitingForLoad ) ;
2021-04-07 19:46:30 +08:00
}
2020-12-20 23:04:06 +08:00
}
}