2022-12-01 18:57:50 +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.
2024-05-10 07:21:06 +08:00
using System ;
2024-06-29 15:19:58 +08:00
using System.Linq ;
2022-12-01 18:57:50 +08:00
using NUnit.Framework ;
2024-06-29 15:19:58 +08:00
using osu.Framework.Allocation ;
2022-12-01 18:57:50 +08:00
using osu.Framework.Graphics ;
2024-06-29 15:19:58 +08:00
using osu.Framework.Graphics.Containers ;
2023-09-04 12:49:29 +08:00
using osu.Framework.Graphics.Cursor ;
2024-06-29 15:19:58 +08:00
using osu.Framework.Graphics.Sprites ;
2022-12-01 23:29:52 +08:00
using osu.Framework.Testing ;
2024-06-29 15:19:58 +08:00
using osu.Game.Graphics ;
using osu.Game.Graphics.UserInterface ;
2022-12-03 01:44:21 +08:00
using osu.Game.Overlays ;
using osu.Game.Overlays.Mods ;
2024-05-16 09:36:14 +08:00
using osu.Game.Screens.Footer ;
using osu.Game.Screens.SelectV2.Footer ;
2022-12-01 18:57:50 +08:00
2024-05-16 09:36:14 +08:00
namespace osu.Game.Tests.Visual.UserInterface
2022-12-01 18:57:50 +08:00
{
2024-05-16 09:36:14 +08:00
public partial class TestSceneScreenFooter : OsuManualInputManagerTestScene
2022-12-01 18:57:50 +08:00
{
2024-06-29 15:19:58 +08:00
private DependencyProvidingContainer contentContainer = null ! ;
2024-05-16 11:26:59 +08:00
private ScreenFooter screenFooter = null ! ;
2024-07-10 16:51:49 +08:00
private TestModSelectOverlay modOverlay = null ! ;
2022-12-03 01:44:21 +08:00
2022-12-01 18:57:50 +08:00
[SetUp]
public void SetUp ( ) = > Schedule ( ( ) = >
{
2024-06-29 15:19:58 +08:00
screenFooter = new ScreenFooter ( ) ;
Child = contentContainer = new DependencyProvidingContainer
2022-12-01 18:57:50 +08:00
{
2024-06-29 15:19:58 +08:00
RelativeSizeAxes = Axes . Both ,
CachedDependencies = new ( Type , object ) [ ]
2024-05-16 11:26:59 +08:00
{
2024-06-29 15:19:58 +08:00
( typeof ( ScreenFooter ) , screenFooter )
2024-05-16 11:26:59 +08:00
} ,
2024-06-29 15:19:58 +08:00
Children = new Drawable [ ]
2022-12-03 01:44:21 +08:00
{
2024-07-10 16:51:49 +08:00
modOverlay = new TestModSelectOverlay ( ) ,
2024-06-29 15:19:58 +08:00
new PopoverContainer
{
RelativeSizeAxes = Axes . Both ,
Depth = float . MinValue ,
Child = screenFooter ,
} ,
2022-12-03 01:44:21 +08:00
} ,
2022-12-01 18:57:50 +08:00
} ;
2022-12-01 20:13:37 +08:00
2024-05-16 11:26:59 +08:00
screenFooter . SetButtons ( new ScreenFooterButton [ ]
2022-12-01 23:29:52 +08:00
{
2024-07-10 16:51:49 +08:00
new ScreenFooterButtonMods ( modOverlay ) { Current = SelectedMods } ,
2024-05-16 11:26:59 +08:00
new ScreenFooterButtonRandom ( ) ,
new ScreenFooterButtonOptions ( ) ,
2022-12-01 23:29:52 +08:00
} ) ;
2022-12-01 18:57:50 +08:00
} ) ;
2023-09-05 15:44:22 +08:00
[SetUpSteps]
public void SetUpSteps ( )
{
2024-05-16 11:26:59 +08:00
AddStep ( "show footer" , ( ) = > screenFooter . Show ( ) ) ;
2023-09-05 15:44:22 +08:00
}
2024-05-16 11:26:59 +08:00
/// <summary>
/// Transition when moving from a screen with no buttons to a screen with buttons.
/// </summary>
2024-05-10 07:21:06 +08:00
[Test]
2024-05-16 11:26:59 +08:00
public void TestButtonsIn ( )
2024-05-10 07:21:06 +08:00
{
}
2024-05-16 11:26:59 +08:00
/// <summary>
/// Transition when moving from a screen with buttons to a screen with no buttons.
/// </summary>
2023-09-05 15:44:22 +08:00
[Test]
2024-05-16 11:26:59 +08:00
public void TestButtonsOut ( )
2023-09-05 15:44:22 +08:00
{
2024-05-16 11:26:59 +08:00
AddStep ( "clear buttons" , ( ) = > screenFooter . SetButtons ( Array . Empty < ScreenFooterButton > ( ) ) ) ;
2023-09-05 15:44:22 +08:00
}
2024-05-16 11:26:59 +08:00
/// <summary>
/// Transition when moving from a screen with buttons to a screen with buttons.
/// </summary>
2022-12-01 18:57:50 +08:00
[Test]
2024-05-16 11:26:59 +08:00
public void TestReplaceButtons ( )
2022-12-01 18:57:50 +08:00
{
2024-05-16 11:26:59 +08:00
AddStep ( "replace buttons" , ( ) = > screenFooter . SetButtons ( new [ ]
2022-12-01 23:29:52 +08:00
{
2024-05-16 11:26:59 +08:00
new ScreenFooterButton { Text = "One" , Action = ( ) = > { } } ,
new ScreenFooterButton { Text = "Two" , Action = ( ) = > { } } ,
new ScreenFooterButton { Text = "Three" , Action = ( ) = > { } } ,
} ) ) ;
2022-12-01 23:29:52 +08:00
}
2024-06-29 15:19:58 +08:00
[Test]
public void TestExternalOverlayContent ( )
{
TestShearedOverlayContainer externalOverlay = null ! ;
AddStep ( "add overlay" , ( ) = > contentContainer . Add ( externalOverlay = new TestShearedOverlayContainer ( ) ) ) ;
AddStep ( "set buttons" , ( ) = > screenFooter . SetButtons ( new [ ]
{
new ScreenFooterButton ( externalOverlay )
{
AccentColour = Dependencies . Get < OsuColour > ( ) . Orange1 ,
Icon = FontAwesome . Solid . Toolbox ,
Text = "One" ,
} ,
new ScreenFooterButton { Text = "Two" , Action = ( ) = > { } } ,
new ScreenFooterButton { Text = "Three" , Action = ( ) = > { } } ,
} ) ) ;
AddWaitStep ( "wait for transition" , 3 ) ;
AddStep ( "show overlay" , ( ) = > externalOverlay . Show ( ) ) ;
AddAssert ( "content displayed in footer" , ( ) = > screenFooter . ChildrenOfType < TestShearedOverlayContainer . TestFooterContent > ( ) . Single ( ) . IsPresent ) ;
AddUntilStep ( "other buttons hidden" , ( ) = > screenFooter . ChildrenOfType < ScreenFooterButton > ( ) . Skip ( 1 ) . All ( b = > b . Child . Parent ! . Y > 0 ) ) ;
AddStep ( "hide overlay" , ( ) = > externalOverlay . Hide ( ) ) ;
AddUntilStep ( "content hidden from footer" , ( ) = > screenFooter . ChildrenOfType < TestShearedOverlayContainer . TestFooterContent > ( ) . SingleOrDefault ( ) ? . IsPresent ! = true ) ;
AddUntilStep ( "other buttons returned" , ( ) = > screenFooter . ChildrenOfType < ScreenFooterButton > ( ) . Skip ( 1 ) . All ( b = > b . ChildrenOfType < Container > ( ) . First ( ) . Y = = 0 ) ) ;
}
[Test]
public void TestTemporarilyShowFooter ( )
{
TestShearedOverlayContainer externalOverlay = null ! ;
AddStep ( "hide footer" , ( ) = > screenFooter . Hide ( ) ) ;
AddStep ( "remove buttons" , ( ) = > screenFooter . SetButtons ( Array . Empty < ScreenFooterButton > ( ) ) ) ;
AddStep ( "add external overlay" , ( ) = > contentContainer . Add ( externalOverlay = new TestShearedOverlayContainer ( ) ) ) ;
AddStep ( "show external overlay" , ( ) = > externalOverlay . Show ( ) ) ;
AddAssert ( "footer shown" , ( ) = > screenFooter . State . Value = = Visibility . Visible ) ;
AddAssert ( "content displayed in footer" , ( ) = > screenFooter . ChildrenOfType < TestShearedOverlayContainer . TestFooterContent > ( ) . Single ( ) . IsPresent ) ;
AddStep ( "hide external overlay" , ( ) = > externalOverlay . Hide ( ) ) ;
AddAssert ( "footer hidden" , ( ) = > screenFooter . State . Value = = Visibility . Hidden ) ;
AddUntilStep ( "content hidden from footer" , ( ) = > screenFooter . ChildrenOfType < TestShearedOverlayContainer . TestFooterContent > ( ) . SingleOrDefault ( ) ? . IsPresent ! = true ) ;
AddStep ( "show footer" , ( ) = > screenFooter . Show ( ) ) ;
AddAssert ( "content still hidden from footer" , ( ) = > screenFooter . ChildrenOfType < TestShearedOverlayContainer . TestFooterContent > ( ) . SingleOrDefault ( ) ? . IsPresent ! = true ) ;
AddStep ( "show external overlay" , ( ) = > externalOverlay . Show ( ) ) ;
AddAssert ( "footer still visible" , ( ) = > screenFooter . State . Value = = Visibility . Visible ) ;
AddStep ( "hide external overlay" , ( ) = > externalOverlay . Hide ( ) ) ;
AddAssert ( "footer still visible" , ( ) = > screenFooter . State . Value = = Visibility . Visible ) ;
AddStep ( "hide footer" , ( ) = > screenFooter . Hide ( ) ) ;
AddStep ( "show external overlay" , ( ) = > externalOverlay . Show ( ) ) ;
}
[Test]
public void TestBackButton ( )
{
TestShearedOverlayContainer externalOverlay = null ! ;
AddStep ( "hide footer" , ( ) = > screenFooter . Hide ( ) ) ;
AddStep ( "remove buttons" , ( ) = > screenFooter . SetButtons ( Array . Empty < ScreenFooterButton > ( ) ) ) ;
AddStep ( "add external overlay" , ( ) = > contentContainer . Add ( externalOverlay = new TestShearedOverlayContainer ( ) ) ) ;
AddStep ( "show external overlay" , ( ) = > externalOverlay . Show ( ) ) ;
AddAssert ( "footer shown" , ( ) = > screenFooter . State . Value = = Visibility . Visible ) ;
AddStep ( "press back" , ( ) = > this . ChildrenOfType < ScreenBackButton > ( ) . Single ( ) . TriggerClick ( ) ) ;
AddAssert ( "overlay hidden" , ( ) = > externalOverlay . State . Value = = Visibility . Hidden ) ;
AddAssert ( "footer hidden" , ( ) = > screenFooter . State . Value = = Visibility . Hidden ) ;
AddStep ( "show external overlay" , ( ) = > externalOverlay . Show ( ) ) ;
AddStep ( "set block count" , ( ) = > externalOverlay . BackButtonCount = 1 ) ;
AddStep ( "press back" , ( ) = > this . ChildrenOfType < ScreenBackButton > ( ) . Single ( ) . TriggerClick ( ) ) ;
AddAssert ( "overlay still visible" , ( ) = > externalOverlay . State . Value = = Visibility . Visible ) ;
AddAssert ( "footer still shown" , ( ) = > screenFooter . State . Value = = Visibility . Visible ) ;
AddStep ( "press back again" , ( ) = > this . ChildrenOfType < ScreenBackButton > ( ) . Single ( ) . TriggerClick ( ) ) ;
AddAssert ( "overlay hidden" , ( ) = > externalOverlay . State . Value = = Visibility . Hidden ) ;
AddAssert ( "footer hidden" , ( ) = > screenFooter . State . Value = = Visibility . Hidden ) ;
}
2024-07-10 16:51:49 +08:00
[Test]
public void TestLoadOverlayAfterFooterIsDisplayed ( )
{
TestShearedOverlayContainer externalOverlay = null ! ;
AddStep ( "show mod overlay" , ( ) = > modOverlay . Show ( ) ) ;
AddUntilStep ( "mod footer content shown" , ( ) = > this . ChildrenOfType < ModSelectFooterContent > ( ) . SingleOrDefault ( ) ? . IsPresent , ( ) = > Is . True ) ;
AddStep ( "add external overlay" , ( ) = > contentContainer . Add ( externalOverlay = new TestShearedOverlayContainer ( ) ) ) ;
AddUntilStep ( "wait for load" , ( ) = > externalOverlay . IsLoaded ) ;
AddAssert ( "mod footer content still shown" , ( ) = > this . ChildrenOfType < ModSelectFooterContent > ( ) . SingleOrDefault ( ) ? . IsPresent , ( ) = > Is . True ) ;
AddAssert ( "external overlay content not shown" , ( ) = > this . ChildrenOfType < TestShearedOverlayContainer . TestFooterContent > ( ) . SingleOrDefault ( ) ? . IsPresent , ( ) = > Is . Not . True ) ;
AddStep ( "hide mod overlay" , ( ) = > modOverlay . Hide ( ) ) ;
AddUntilStep ( "mod footer content hidden" , ( ) = > this . ChildrenOfType < ModSelectFooterContent > ( ) . SingleOrDefault ( ) ? . IsPresent , ( ) = > Is . Not . True ) ;
AddAssert ( "external overlay content still not shown" , ( ) = > this . ChildrenOfType < TestShearedOverlayContainer . TestFooterContent > ( ) . SingleOrDefault ( ) ? . IsPresent , ( ) = > Is . Not . True ) ;
}
2024-05-16 11:26:59 +08:00
private partial class TestModSelectOverlay : UserModSelectOverlay
2022-12-01 23:29:52 +08:00
{
2024-05-16 11:26:59 +08:00
protected override bool ShowPresets = > true ;
2024-06-29 15:19:58 +08:00
}
2024-05-16 12:20:55 +08:00
2024-06-29 15:19:58 +08:00
private partial class TestShearedOverlayContainer : ShearedOverlayContainer
{
public TestShearedOverlayContainer ( )
: base ( OverlayColourScheme . Orange )
{
}
[BackgroundDependencyLoader]
private void load ( )
2024-05-16 12:20:55 +08:00
{
2024-06-29 15:19:58 +08:00
Header . Title = "Test overlay" ;
Header . Description = "An overlay that is made purely for testing purposes." ;
}
public int BackButtonCount ;
public override bool OnBackButton ( )
{
if ( BackButtonCount > 0 )
{
BackButtonCount - - ;
return true ;
}
return false ;
}
2024-07-10 16:12:52 +08:00
public override VisibilityContainer CreateFooterContent ( ) = > new TestFooterContent ( ) ;
2024-06-29 15:19:58 +08:00
public partial class TestFooterContent : VisibilityContainer
{
[BackgroundDependencyLoader]
private void load ( )
{
RelativeSizeAxes = Axes . Both ;
InternalChild = new FillFlowContainer
{
AutoSizeAxes = Axes . Both ,
Children = new [ ]
{
new ShearedButton ( 200 ) { Text = "Action #1" , Action = ( ) = > { } } ,
new ShearedButton ( 140 ) { Text = "Action #2" , Action = ( ) = > { } } ,
}
} ;
}
protected override void PopIn ( )
{
this . MoveToY ( 0 , 400 , Easing . OutQuint )
. FadeIn ( 400 , Easing . OutQuint ) ;
}
protected override void PopOut ( )
{
this . MoveToY ( - 20f , 200 , Easing . OutQuint )
. FadeOut ( 200 , Easing . OutQuint ) ;
}
2024-05-16 12:20:55 +08:00
}
2022-12-03 01:44:21 +08:00
}
2022-12-01 18:57:50 +08:00
}
}