2022-04-24 04:15:31 +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 ;
using osu.Framework.Extensions ;
2022-05-08 04:47:19 +08:00
using osu.Framework.Graphics.Containers ;
2022-04-24 04:15:31 +08:00
using osu.Framework.Graphics.UserInterface ;
using osu.Framework.Testing ;
using osu.Game.Overlays.Settings ;
using osu.Game.Rulesets.Mods ;
using osu.Game.Rulesets.Osu.Mods ;
using osu.Game.Screens.Play ;
using osu.Game.Screens.Play.HUD.HitErrorMeters ;
using osu.Game.Skinning.Editor ;
using osu.Game.Tests.Beatmaps.IO ;
using osuTK.Input ;
using static osu . Game . Tests . Visual . Navigation . TestSceneScreenNavigation ;
namespace osu.Game.Tests.Visual.Navigation
{
2022-05-08 04:43:45 +08:00
public class TestSceneSkinEditorNavigation : OsuGameTestScene
2022-04-24 04:15:31 +08:00
{
2022-05-08 04:41:48 +08:00
private TestPlaySongSelect songSelect ;
private SkinEditor skinEditor = > Game . ChildrenOfType < SkinEditor > ( ) . FirstOrDefault ( ) ;
2022-04-24 04:15:31 +08:00
2022-05-08 04:41:48 +08:00
private void advanceToSongSelect ( )
2022-04-24 04:15:31 +08:00
{
PushAndConfirm ( ( ) = > songSelect = new TestPlaySongSelect ( ) ) ;
AddUntilStep ( "wait for song select" , ( ) = > songSelect . BeatmapSetsLoaded ) ;
AddStep ( "import beatmap" , ( ) = > BeatmapImportHelper . LoadQuickOszIntoOsu ( Game ) . WaitSafely ( ) ) ;
AddUntilStep ( "wait for selected" , ( ) = > ! Game . Beatmap . IsDefault ) ;
2022-05-08 04:41:48 +08:00
}
2022-04-24 04:15:31 +08:00
2022-05-08 04:41:48 +08:00
private void openSkinEditor ( )
{
2022-04-24 04:15:31 +08:00
AddStep ( "open skin editor" , ( ) = >
{
InputManager . PressKey ( Key . ControlLeft ) ;
InputManager . PressKey ( Key . ShiftLeft ) ;
InputManager . Key ( Key . S ) ;
InputManager . ReleaseKey ( Key . ControlLeft ) ;
InputManager . ReleaseKey ( Key . ShiftLeft ) ;
} ) ;
2022-05-08 04:41:48 +08:00
AddUntilStep ( "skin editor loaded" , ( ) = > skinEditor ! = null ) ;
2022-04-24 04:15:31 +08:00
}
[Test]
public void TestEditComponentDuringGameplay ( )
{
2022-05-08 04:41:48 +08:00
advanceToSongSelect ( ) ;
openSkinEditor ( ) ;
2022-04-24 04:15:31 +08:00
switchToGameplayScene ( ) ;
BarHitErrorMeter hitErrorMeter = null ;
AddUntilStep ( "select bar hit error blueprint" , ( ) = >
{
var blueprint = skinEditor . ChildrenOfType < SkinBlueprint > ( ) . FirstOrDefault ( b = > b . Item is BarHitErrorMeter ) ;
if ( blueprint = = null )
return false ;
hitErrorMeter = ( BarHitErrorMeter ) blueprint . Item ;
skinEditor . SelectedComponents . Clear ( ) ;
skinEditor . SelectedComponents . Add ( blueprint . Item ) ;
return true ;
} ) ;
AddAssert ( "value is default" , ( ) = > hitErrorMeter . JudgementLineThickness . IsDefault ) ;
AddStep ( "hover first slider" , ( ) = >
{
InputManager . MoveMouseTo (
skinEditor . ChildrenOfType < SkinSettingsToolbox > ( ) . First ( )
. ChildrenOfType < SettingsSlider < float > > ( ) . First ( )
. ChildrenOfType < SliderBar < float > > ( ) . First ( )
) ;
} ) ;
AddStep ( "adjust slider via keyboard" , ( ) = > InputManager . Key ( Key . Left ) ) ;
AddAssert ( "value is less than default" , ( ) = > hitErrorMeter . JudgementLineThickness . Value < hitErrorMeter . JudgementLineThickness . Default ) ;
}
2022-04-24 04:16:06 +08:00
[Test]
public void TestAutoplayCompatibleModsRetainedOnEnteringGameplay ( )
{
2022-05-08 04:41:48 +08:00
advanceToSongSelect ( ) ;
openSkinEditor ( ) ;
2022-04-24 04:16:06 +08:00
AddStep ( "select DT" , ( ) = > Game . SelectedMods . Value = new Mod [ ] { new OsuModDoubleTime ( ) } ) ;
switchToGameplayScene ( ) ;
AddAssert ( "DT still selected" , ( ) = > ( ( Player ) Game . ScreenStack . CurrentScreen ) . Mods . Value . Single ( ) is OsuModDoubleTime ) ;
}
[Test]
public void TestAutoplayIncompatibleModsRemovedOnEnteringGameplay ( )
{
2022-05-08 04:41:48 +08:00
advanceToSongSelect ( ) ;
openSkinEditor ( ) ;
2022-04-24 04:16:06 +08:00
AddStep ( "select no fail and spun out" , ( ) = > Game . SelectedMods . Value = new Mod [ ] { new OsuModNoFail ( ) , new OsuModSpunOut ( ) } ) ;
switchToGameplayScene ( ) ;
AddAssert ( "no mod selected" , ( ) = > ! ( ( Player ) Game . ScreenStack . CurrentScreen ) . Mods . Value . Any ( ) ) ;
}
[Test]
public void TestDuplicateAutoplayModRemovedOnEnteringGameplay ( )
{
2022-05-08 04:41:48 +08:00
advanceToSongSelect ( ) ;
openSkinEditor ( ) ;
2022-04-24 04:16:06 +08:00
AddStep ( "select autoplay" , ( ) = > Game . SelectedMods . Value = new Mod [ ] { new OsuModAutoplay ( ) } ) ;
switchToGameplayScene ( ) ;
AddAssert ( "no mod selected" , ( ) = > ! ( ( Player ) Game . ScreenStack . CurrentScreen ) . Mods . Value . Any ( ) ) ;
}
[Test]
public void TestCinemaModRemovedOnEnteringGameplay ( )
{
2022-05-08 04:41:48 +08:00
advanceToSongSelect ( ) ;
openSkinEditor ( ) ;
2022-04-24 04:16:06 +08:00
AddStep ( "select cinema" , ( ) = > Game . SelectedMods . Value = new Mod [ ] { new OsuModCinema ( ) } ) ;
switchToGameplayScene ( ) ;
AddAssert ( "no mod selected" , ( ) = > ! ( ( Player ) Game . ScreenStack . CurrentScreen ) . Mods . Value . Any ( ) ) ;
}
2022-05-08 04:47:19 +08:00
[Test]
public void TestModOverlayClosesOnOpeningSkinEditor ( )
{
advanceToSongSelect ( ) ;
AddStep ( "open mod overlay" , ( ) = > songSelect . ModSelectOverlay . Show ( ) ) ;
openSkinEditor ( ) ;
AddUntilStep ( "mod overlay closed" , ( ) = > songSelect . ModSelectOverlay . State . Value = = Visibility . Hidden ) ;
}
2022-04-24 04:15:31 +08:00
private void switchToGameplayScene ( )
{
AddStep ( "Click gameplay scene button" , ( ) = > skinEditor . ChildrenOfType < SkinEditorSceneLibrary . SceneButton > ( ) . First ( b = > b . Text = = "Gameplay" ) . TriggerClick ( ) ) ;
AddUntilStep ( "wait for player" , ( ) = >
{
DismissAnyNotifications ( ) ;
return Game . ScreenStack . CurrentScreen is Player ;
} ) ;
}
}
}