PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/Scenes/UserInterfaces/Screen.cs

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