PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/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
  1. using Delta.Engine;
  2. using Delta.InputSystem;
  3. using Delta.Rendering.Basics.Materials;
  4. using Delta.Scenes.UserInterfaces;
  5. using Delta.Scenes.UserInterfaces.Controls;
  6. using Delta.Utilities.Datatypes;
  7. using NUnit.Framework;
  8. namespace Delta.Scenes.Tests
  9. {
  10. /// <summary>
  11. /// UI screen tests
  12. /// </summary>
  13. internal static class UIScreenTests
  14. {
  15. #region UseSceneBackground (LongRunning)
  16. /// <summary>
  17. /// Use scene background
  18. /// </summary>
  19. [Test, Category("Visual")]
  20. public static void UseSceneBackground()
  21. {
  22. // Create a UI screen (with starting a new scene)
  23. Screen mainScreen = new Screen("<TestScreen>")
  24. {
  25. // and set the background we want to see
  26. Background = new Material2DColored(Color.Gold),
  27. };
  28. mainScreen.Open();
  29. Application.Start(delegate
  30. {
  31. });
  32. }
  33. #endregion
  34. #region OpenAndClosingOverlayScreen (LongRunning)
  35. /// <summary>
  36. /// Open and closing overlay screen
  37. /// </summary>
  38. [Test, Category("Visual")]
  39. public static void OpenAndClosingOverlayScreen()
  40. {
  41. // Just create a normal screen (with starting a new scene)
  42. Screen mainScreen = new Screen("<TestMainScreen>");
  43. mainScreen.Open();
  44. // and a overlay screen in it
  45. Screen overlayScreen = new Screen("<TestOverlayScreen>")
  46. {
  47. Scene = mainScreen.Scene,
  48. IsOverlayScreen = true,
  49. };
  50. overlayScreen.Open();
  51. // Start the application
  52. Application.Start(delegate
  53. {
  54. // and let close the overlay screen by the space key
  55. // -> the scene shouldn't crash anymore if any e.g. mouse input is done
  56. if (Input.Keyboard.SpaceReleased)
  57. {
  58. overlayScreen.Close();
  59. } // if
  60. });
  61. }
  62. #endregion
  63. #region OpenTwoNormalScreens (LongRunning)
  64. /// <summary>
  65. /// Open two normal screens
  66. /// </summary>
  67. [Test, Category("Visual")]
  68. public static void OpenTwoNormalScreens()
  69. {
  70. // Create and open a normal screen(with starting a new scene)
  71. Screen firstScreen = new Screen("<FirstScreen>");
  72. firstScreen.Add(new Label
  73. {
  74. Name = "FirstScreenLabel",
  75. LocalArea = Rectangle.FromCenter(0.5f, 0.45f, 0.2f, 0.05f),
  76. Text = "First screen",
  77. });
  78. firstScreen.Open();
  79. // and open another one per 'Space' key
  80. Screen secondScreen = null;
  81. // Start the application
  82. Application.Start(delegate
  83. {
  84. // and let close the overlay scene by the space key
  85. // -> the scene shouldn't crash anymore if any e.g. mouse input is done
  86. if (Input.Keyboard.SpaceReleased)
  87. {
  88. // First time open the second screen now
  89. if (secondScreen == null)
  90. {
  91. secondScreen = new Screen("<SecondScreen>");
  92. secondScreen.Add(new Label
  93. {
  94. Name = "SecondScreenLabel",
  95. LocalArea = Rectangle.FromCenter(0.5f, 0.55f, 0.2f, 0.05f),
  96. Text = "Second screen",
  97. });
  98. secondScreen.Open();
  99. } // if
  100. // and close it on the second time again
  101. else
  102. {
  103. secondScreen.Close();
  104. secondScreen = null;
  105. } // else
  106. } // if
  107. });
  108. }
  109. #endregion
  110. #region SwitchSolidScenes (LongRunning)
  111. /// <summary>
  112. /// Switch solid scenes
  113. /// </summary>
  114. [Test, Category("Visual")]
  115. public static void SwitchSolidScenes()
  116. {
  117. // Create the (solid) menu screen (with starting a new scene)
  118. Screen mainScreen = new Screen("<MainScreen>");
  119. // with a open button
  120. Button openButton = new Button
  121. {
  122. LocalArea = Rectangle.FromCenter(0.25f, 0.5f, 0.3f, 0.05f),
  123. Text = "Open sub scene",
  124. };
  125. // that opens the sub scene on clicking
  126. openButton.Clicked += delegate(BaseControl sender1, CommandTrigger input)
  127. {
  128. #region Opening the sub scene
  129. // Create the (solid) sub screen
  130. Screen subScreen = new Screen("<SubScreen>")
  131. {
  132. Scene = mainScreen.Scene,
  133. };
  134. // with a close button
  135. Button closeButton = new Button
  136. {
  137. LocalArea = Rectangle.FromCenter(0.75f, 0.5f, 0.3f, 0.05f),
  138. Text = "Close sub scene",
  139. };
  140. // that closes the sub scene and jumps back to the main scene on
  141. // clicking
  142. closeButton.Clicked += delegate(BaseControl sender2,
  143. CommandTrigger input2)
  144. {
  145. subScreen.Close();
  146. input2.IsHandled = true;
  147. };
  148. subScreen.Add(closeButton);
  149. subScreen.Open();
  150. input.IsHandled = true;
  151. #endregion
  152. };
  153. mainScreen.Add(openButton);
  154. mainScreen.Open();
  155. // Start the application
  156. Application.Start(delegate
  157. {
  158. // Now test if even opening the main scene still works after closing
  159. // the sub-screen by the keyboard (-> reported issue)
  160. if (Input.Keyboard.SpaceReleased)
  161. {
  162. if (Scene.Current.Name.Contains("SubScreen"))
  163. {
  164. Scene.Current.Dispose();
  165. } // if
  166. } // if
  167. });
  168. }
  169. #endregion
  170. }
  171. }