2019-01-24 17:43:03 +09: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-04-13 18:19:50 +09:00
2018-03-02 15:34:31 +09:00
using NUnit.Framework ;
2017-09-18 22:32:49 +09:00
using osu.Framework.Allocation ;
using osu.Framework.Configuration ;
2018-05-10 15:49:37 +09:00
using osu.Framework.Configuration.Tracking ;
using osu.Framework.Graphics ;
2017-09-18 22:32:49 +09:00
using osu.Game.Overlays ;
2019-07-11 15:09:06 +09:00
using osu.Game.Overlays.OSD ;
2018-04-13 18:19:50 +09:00
2019-03-25 01:02:36 +09:00
namespace osu.Game.Tests.Visual.UserInterface
2017-09-18 22:32:49 +09:00
{
2018-03-02 15:34:31 +09:00
[TestFixture]
2019-05-14 22:37:25 +03:00
public class TestSceneOnScreenDisplay : OsuTestScene
2017-09-18 22:32:49 +09:00
{
2018-05-10 15:49:37 +09:00
[BackgroundDependencyLoader]
private void load ( )
{
var config = new TestConfigManager ( ) ;
var osd = new TestOnScreenDisplay ( ) ;
osd . BeginTracking ( this , config ) ;
Add ( osd ) ;
2018-04-13 18:19:50 +09:00
2019-07-11 15:15:34 +09:00
AddStep ( "Display empty osd toast" , ( ) = > osd . Display ( new EmptyToast ( ) ) ) ;
2019-08-12 12:09:09 +02:00
AddAssert ( "Toast width is 240" , ( ) = > osd . Child . Width = = 240 ) ;
AddStep ( "Display toast with lengthy text" , ( ) = > osd . Display ( new LengthyToast ( ) ) ) ;
AddAssert ( "Toast width is greater than 240" , ( ) = > osd . Child . Width > 240 ) ;
2021-12-09 21:15:00 -08:00
AddRepeatStep ( "Change toggle (no bind)" , ( ) = > config . ToggleSetting ( TestConfigSetting . ToggleSettingNoKeyBind ) , 2 ) ;
AddRepeatStep ( "Change toggle (with bind)" , ( ) = > config . ToggleSetting ( TestConfigSetting . ToggleSettingWithKeyBind ) , 2 ) ;
AddRepeatStep ( "Change enum (no bind)" , ( ) = > config . IncrementEnumSetting ( TestConfigSetting . EnumSettingNoKeyBind ) , 3 ) ;
AddRepeatStep ( "Change enum (with bind)" , ( ) = > config . IncrementEnumSetting ( TestConfigSetting . EnumSettingWithKeyBind ) , 3 ) ;
2018-05-10 15:49:37 +09:00
}
private class TestConfigManager : ConfigManager < TestConfigSetting >
2017-09-18 22:32:49 +09:00
{
2018-05-10 15:49:37 +09:00
public TestConfigManager ( )
{
InitialiseDefaults ( ) ;
}
protected override void InitialiseDefaults ( )
{
2021-12-09 21:15:00 -08:00
SetDefault ( TestConfigSetting . ToggleSettingNoKeyBind , false ) ;
SetDefault ( TestConfigSetting . EnumSettingNoKeyBind , EnumSetting . Setting1 ) ;
SetDefault ( TestConfigSetting . ToggleSettingWithKeyBind , false ) ;
SetDefault ( TestConfigSetting . EnumSettingWithKeyBind , EnumSetting . Setting1 ) ;
2018-04-13 18:19:50 +09:00
2018-05-10 15:49:37 +09:00
base . InitialiseDefaults ( ) ;
}
2018-04-13 18:19:50 +09:00
2021-03-17 16:10:16 +09:00
public void ToggleSetting ( TestConfigSetting setting ) = > SetValue ( setting , ! Get < bool > ( setting ) ) ;
2018-04-13 18:19:50 +09:00
2018-05-10 15:49:37 +09:00
public void IncrementEnumSetting ( TestConfigSetting setting )
{
var nextValue = Get < EnumSetting > ( setting ) + 1 ;
if ( nextValue > EnumSetting . Setting4 )
nextValue = EnumSetting . Setting1 ;
2021-03-17 16:10:16 +09:00
SetValue ( setting , nextValue ) ;
2018-05-10 15:49:37 +09:00
}
2018-04-13 18:19:50 +09:00
2018-05-10 15:49:37 +09:00
public override TrackedSettings CreateTrackedSettings ( ) = > new TrackedSettings
{
2021-12-09 21:15:00 -08:00
new TrackedSetting < bool > ( TestConfigSetting . ToggleSettingNoKeyBind , b = > new SettingDescription ( b , "toggle setting with no keybind" , b ? "enabled" : "disabled" ) ) ,
new TrackedSetting < EnumSetting > ( TestConfigSetting . EnumSettingNoKeyBind , v = > new SettingDescription ( v , "enum setting with no keybind" , v . ToString ( ) ) ) ,
new TrackedSetting < bool > ( TestConfigSetting . ToggleSettingWithKeyBind , b = > new SettingDescription ( b , "toggle setting with keybind" , b ? "enabled" : "disabled" , "fake keybind" ) ) ,
new TrackedSetting < EnumSetting > ( TestConfigSetting . EnumSettingWithKeyBind , v = > new SettingDescription ( v , "enum setting with keybind" , v . ToString ( ) , "fake keybind" ) ) ,
2018-05-10 15:49:37 +09:00
} ;
2018-04-13 18:19:50 +09:00
2018-05-10 15:49:37 +09:00
protected override void PerformLoad ( )
{
}
protected override bool PerformSave ( ) = > false ;
2017-09-18 22:32:49 +09:00
}
2018-04-13 18:19:50 +09:00
2018-05-10 15:49:37 +09:00
private enum TestConfigSetting
2017-09-18 22:32:49 +09:00
{
2021-12-09 21:15:00 -08:00
ToggleSettingNoKeyBind ,
EnumSettingNoKeyBind ,
ToggleSettingWithKeyBind ,
EnumSettingWithKeyBind
2017-09-18 22:32:49 +09:00
}
2018-04-13 18:19:50 +09:00
2018-05-10 15:49:37 +09:00
private enum EnumSetting
{
Setting1 ,
Setting2 ,
Setting3 ,
Setting4
}
2019-07-11 15:15:34 +09:00
private class EmptyToast : Toast
{
2019-07-12 08:50:53 +02:00
public EmptyToast ( )
: base ( "" , "" , "" )
{
}
2019-07-11 15:15:34 +09:00
}
2019-08-12 12:09:09 +02:00
private class LengthyToast : Toast
{
public LengthyToast ( )
: base ( "Toast with a very very very long text" , "A very very very very very very long text also" , "A very very very very very long shortcut" )
{
}
}
2018-05-10 15:49:37 +09:00
private class TestOnScreenDisplay : OnScreenDisplay
2017-09-18 22:32:49 +09:00
{
2018-07-09 17:53:39 +09:00
protected override void DisplayTemporarily ( Drawable toDisplay ) = > toDisplay . FadeIn ( ) . ResizeHeightTo ( 110 ) ;
2017-09-18 22:32:49 +09:00
}
}
}