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-04-13 17:19:50 +08:00
using NUnit.Framework ;
using osu.Framework.Allocation ;
using osu.Framework.Configuration ;
2018-05-10 14:49:37 +08:00
using osu.Framework.Configuration.Tracking ;
using osu.Framework.Graphics ;
2019-07-05 22:25:09 +08:00
using osu.Framework.Graphics.Sprites ;
2018-04-13 17:19:50 +08:00
using osu.Game.Overlays ;
2019-03-25 00:02:36 +08:00
namespace osu.Game.Tests.Visual.UserInterface
2018-04-13 17:19:50 +08:00
{
[TestFixture]
2019-05-15 03:37:25 +08:00
public class TestSceneOnScreenDisplay : OsuTestScene
2018-04-13 17:19:50 +08:00
{
2018-05-10 14:49:37 +08:00
[BackgroundDependencyLoader]
private void load ( )
{
var config = new TestConfigManager ( ) ;
var osd = new TestOnScreenDisplay ( ) ;
osd . BeginTracking ( this , config ) ;
Add ( osd ) ;
2018-04-13 17:19:50 +08:00
2019-07-05 22:04:47 +08:00
AddStep ( "Display empty osd toast" , ( ) = > osd . Display ( new Overlays . OSD . OsdToast ( ) ) ) ;
2019-07-05 22:25:09 +08:00
AddStep ( "Display osd toast with icon and message" , ( ) = > osd . Display ( new Overlays . OSD . OsdIconToast ( "Hey there !" , FontAwesome . Solid . HandSpock ) ) ) ;
2018-05-10 14:49:37 +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 ) ;
}
private class TestConfigManager : ConfigManager < TestConfigSetting >
2018-04-13 17:19:50 +08:00
{
2018-05-10 14:49:37 +08:00
public TestConfigManager ( )
{
InitialiseDefaults ( ) ;
}
protected override void InitialiseDefaults ( )
{
Set ( TestConfigSetting . ToggleSettingNoKeybind , false ) ;
Set ( TestConfigSetting . EnumSettingNoKeybind , EnumSetting . Setting1 ) ;
Set ( TestConfigSetting . ToggleSettingWithKeybind , false ) ;
Set ( TestConfigSetting . EnumSettingWithKeybind , EnumSetting . Setting1 ) ;
2018-04-13 17:19:50 +08:00
2018-05-10 14:49:37 +08:00
base . InitialiseDefaults ( ) ;
}
2018-04-13 17:19:50 +08:00
2018-05-10 14:49:37 +08:00
public void ToggleSetting ( TestConfigSetting setting ) = > Set ( setting , ! Get < bool > ( setting ) ) ;
2018-04-13 17:19:50 +08:00
2018-05-10 14:49:37 +08:00
public void IncrementEnumSetting ( TestConfigSetting setting )
{
var nextValue = Get < EnumSetting > ( setting ) + 1 ;
if ( nextValue > EnumSetting . Setting4 )
nextValue = EnumSetting . Setting1 ;
Set ( setting , nextValue ) ;
}
2018-04-13 17:19:50 +08:00
2018-05-10 14:49:37 +08:00
public override TrackedSettings CreateTrackedSettings ( ) = > new TrackedSettings
{
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-04-13 17:19:50 +08:00
2018-05-10 14:49:37 +08:00
protected override void PerformLoad ( )
{
}
protected override bool PerformSave ( ) = > false ;
2018-04-13 17:19:50 +08:00
}
2018-05-10 14:49:37 +08:00
private enum TestConfigSetting
2018-04-13 17:19:50 +08:00
{
2018-05-10 14:49:37 +08:00
ToggleSettingNoKeybind ,
EnumSettingNoKeybind ,
ToggleSettingWithKeybind ,
EnumSettingWithKeybind
2018-04-13 17:19:50 +08:00
}
2018-05-10 14:49:37 +08:00
private enum EnumSetting
{
Setting1 ,
Setting2 ,
Setting3 ,
Setting4
}
private class TestOnScreenDisplay : OnScreenDisplay
2018-04-13 17:19:50 +08:00
{
2018-07-09 16:53:39 +08:00
protected override void DisplayTemporarily ( Drawable toDisplay ) = > toDisplay . FadeIn ( ) . ResizeHeightTo ( 110 ) ;
2018-04-13 17:19:50 +08:00
}
}
}