PageRenderTime 180ms CodeModel.GetById 70ms app.highlight 46ms RepoModel.GetById 55ms app.codeStats 0ms

/Scenes/Tests/UIScreenTests.cs

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