/Scenes/Tests/UIScreenTests.cs
C# | 185 lines | 132 code | 14 blank | 39 comment | 6 complexity | 9c025c93362f83e2c576c12f429d476c MD5 | raw file
Possible License(s): Apache-2.0
- using Delta.Engine;
- using Delta.InputSystem;
- using Delta.Rendering.Basics.Materials;
- using Delta.Scenes.UserInterfaces;
- using Delta.Scenes.UserInterfaces.Controls;
- using Delta.Utilities.Datatypes;
- using NUnit.Framework;
-
- namespace Delta.Scenes.Tests
- {
- /// <summary>
- /// UI screen tests
- /// </summary>
- internal static class UIScreenTests
- {
- #region UseSceneBackground (LongRunning)
- /// <summary>
- /// Use scene background
- /// </summary>
- [Test, Category("Visual")]
- public static void UseSceneBackground()
- {
- // Create a UI screen (with starting a new scene)
- Screen mainScreen = new Screen("<TestScreen>")
- {
- // and set the background we want to see
- Background = new Material2DColored(Color.Gold),
- };
- mainScreen.Open();
-
- Application.Start(delegate
- {
- });
- }
- #endregion
-
- #region OpenAndClosingOverlayScreen (LongRunning)
- /// <summary>
- /// Open and closing overlay screen
- /// </summary>
- [Test, Category("Visual")]
- public static void OpenAndClosingOverlayScreen()
- {
- // Just create a normal screen (with starting a new scene)
- Screen mainScreen = new Screen("<TestMainScreen>");
- mainScreen.Open();
-
- // and a overlay screen in it
- Screen overlayScreen = new Screen("<TestOverlayScreen>")
- {
- Scene = mainScreen.Scene,
- IsOverlayScreen = true,
- };
- overlayScreen.Open();
-
- // Start the application
- Application.Start(delegate
- {
- // and let close the overlay screen by the space key
- // -> the scene shouldn't crash anymore if any e.g. mouse input is done
- if (Input.Keyboard.SpaceReleased)
- {
- overlayScreen.Close();
- } // if
- });
- }
- #endregion
-
- #region OpenTwoNormalScreens (LongRunning)
- /// <summary>
- /// Open two normal screens
- /// </summary>
- [Test, Category("Visual")]
- public static void OpenTwoNormalScreens()
- {
- // Create and open a normal screen(with starting a new scene)
- Screen firstScreen = new Screen("<FirstScreen>");
- firstScreen.Add(new Label
- {
- Name = "FirstScreenLabel",
- LocalArea = Rectangle.FromCenter(0.5f, 0.45f, 0.2f, 0.05f),
- Text = "First screen",
- });
- firstScreen.Open();
-
- // and open another one per 'Space' key
- Screen secondScreen = null;
-
- // Start the application
- Application.Start(delegate
- {
- // and let close the overlay scene by the space key
- // -> the scene shouldn't crash anymore if any e.g. mouse input is done
- if (Input.Keyboard.SpaceReleased)
- {
- // First time open the second screen now
- if (secondScreen == null)
- {
- secondScreen = new Screen("<SecondScreen>");
- secondScreen.Add(new Label
- {
- Name = "SecondScreenLabel",
- LocalArea = Rectangle.FromCenter(0.5f, 0.55f, 0.2f, 0.05f),
- Text = "Second screen",
- });
- secondScreen.Open();
- } // if
-
- // and close it on the second time again
- else
- {
- secondScreen.Close();
- secondScreen = null;
- } // else
- } // if
- });
- }
- #endregion
-
- #region SwitchSolidScenes (LongRunning)
- /// <summary>
- /// Switch solid scenes
- /// </summary>
- [Test, Category("Visual")]
- public static void SwitchSolidScenes()
- {
- // Create the (solid) menu screen (with starting a new scene)
- Screen mainScreen = new Screen("<MainScreen>");
-
- // with a open button
- Button openButton = new Button
- {
- LocalArea = Rectangle.FromCenter(0.25f, 0.5f, 0.3f, 0.05f),
- Text = "Open sub scene",
- };
- // that opens the sub scene on clicking
- openButton.Clicked += delegate(BaseControl sender1, CommandTrigger input)
- {
- #region Opening the sub scene
- // Create the (solid) sub screen
- Screen subScreen = new Screen("<SubScreen>")
- {
- Scene = mainScreen.Scene,
- };
-
- // with a close button
- Button closeButton = new Button
- {
- LocalArea = Rectangle.FromCenter(0.75f, 0.5f, 0.3f, 0.05f),
- Text = "Close sub scene",
- };
- // that closes the sub scene and jumps back to the main scene on
- // clicking
- closeButton.Clicked += delegate(BaseControl sender2,
- CommandTrigger input2)
- {
- subScreen.Close();
- input2.IsHandled = true;
- };
- subScreen.Add(closeButton);
- subScreen.Open();
- input.IsHandled = true;
- #endregion
- };
- mainScreen.Add(openButton);
-
- mainScreen.Open();
-
- // Start the application
- Application.Start(delegate
- {
- // Now test if even opening the main scene still works after closing
- // the sub-screen by the keyboard (-> reported issue)
- if (Input.Keyboard.SpaceReleased)
- {
- if (Scene.Current.Name.Contains("SubScreen"))
- {
- Scene.Current.Dispose();
- } // if
- } // if
- });
- }
- #endregion
- }
- }