PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 3ms RepoModel.GetById 37ms app.codeStats 1ms

/Scenes/UserInterfaces/Screen.cs

#
C# | 88 lines | 51 code | 8 blank | 29 comment | 9 complexity | 8435a78ea7ac2f0c15b79c6527bbc972 MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using Delta.Scenes.UserInterfaces.Controls;
 4
 5namespace Delta.Scenes.UserInterfaces
 6{
 7	/// <summary>
 8	/// The first concrete implementation of an UI screen which can keep all
 9	/// required UI controls for the interaction with and navigation for the
10	/// user. It also provides background image which is drawn based on the given
11	/// screen area.
12	/// </summary>
13	public class Screen : BaseScreen
14	{
15		#region Constructors
16		/// <summary>
17		/// Creates a custom screen to be filled with UI by the caller. Note: This
18		/// is usually just used for unit-testing, but games and applications will
19		/// also use it when they are not loading scenes and screens via content.
20		/// </summary>
21		public Screen()
22			: this("<DynamicCreated>", false)
23		{
24		}
25
26		/// <summary>
27		/// Creates an user interface screen from the content file with all stored
28		/// controls. Note: If the 'screenContentName' value is empty or null or
29		/// starts with "&gt;" (like "&gt;DummyScreen&lt;"), then the new screen
30		/// will be empty and has to be filled and opened by the caller
31		///  (automaticallyOpenScreen will be ignored).
32		/// </summary>
33		/// <param name="screenContentName">
34		/// Scene name to load. Use the empty constructor to create scenes
35		/// dynamically without content!
36		/// </param>
37		/// <param name="automaticallyOpenScreen"></param>
38		public Screen(string screenContentName,
39			bool automaticallyOpenScreen = true)
40			: base(screenContentName)
41		{
42			if (automaticallyOpenScreen &&
43				String.IsNullOrEmpty(screenContentName) == false &&
44				screenContentName.StartsWith("<") == false)
45			{
46				Open();
47			}
48		}
49		#endregion
50
51		#region Methods (Private)
52
53		#region GetRadioButtons
54		/// <summary>
55		/// Get all RadioButton's which have the same (given) "GroupControl".
56		/// Currently only needed in the RadioButton class.
57		/// </summary>
58		/// <param name="searchingGroupTag">Searching group tag</param>
59		/// <returns>Array of radio buttons for this group tag</returns>
60		internal RadioButton[] GetRadioButtons(object searchingGroupTag)
61		{
62			List<RadioButton> foundButtons = new List<RadioButton>();
63
64			for (int index = 0; index < Controls.Count; index++)
65			{
66				Panel panel = Controls[index] as Panel;
67				if (panel != null)
68				{
69					foundButtons.AddRange(panel.GetChildrenOfType<RadioButton>());
70					continue;
71				} // if
72
73				RadioButton radioButton = Controls[index] as RadioButton;
74				if (radioButton != null &&
75				    radioButton.GroupObject == searchingGroupTag)
76				{
77					foundButtons.Add(radioButton);
78					continue;
79				} // if
80			} // for
81
82			return foundButtons.ToArray();
83		}
84		#endregion
85
86		#endregion
87	}
88}