Screen.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System;
  2. using Microsoft.Xna.Framework;
  3. namespace MonoGame.Extended.Screens;
  4. /// <summary>
  5. /// Represents an abstract base class for game screens that can be managed by a <see cref="ScreenManager"/>.
  6. /// </summary>
  7. /// <remarks>
  8. /// <para>
  9. /// Screens provide a way to organize game logic into discrete states such as menus, gameplay, loading screens,
  10. /// or different game areas.
  11. /// </para>
  12. /// <para>
  13. /// When screen are used with a <see cref="Screens.ScreenManager"/>, multiple screens can be active
  14. /// simultaneously in the manager's screen stack based on their <see cref="UpdateWhenInactive"/> and
  15. /// <see cref="DrawWhenInactive"/> properties.
  16. /// </para>
  17. /// </remarks>
  18. public abstract class Screen : IDisposable
  19. {
  20. /// <summary>
  21. /// Gets the <see cref="Screens.ScreenManager"/> that manages this screen or <see langword="null"/> if the
  22. /// screen is not managed.
  23. /// </summary>
  24. public ScreenManager ScreenManager { get; internal set; }
  25. /// <summary>
  26. /// Gets a value indicating whether this screen is currently the active screen.
  27. /// </summary>
  28. public bool IsActive { get; internal set; }
  29. /// <summary>
  30. /// Gets or sets a value indicating whether this screen should continue to update when it is not the active screen.
  31. /// </summary>
  32. /// <remarks>
  33. /// This property allows background screens to continue processing logic even when they are not the topmost
  34. /// screen in the screen stack of a screen manager. This is useful for scenarios were persistent game systems
  35. /// should run regardless of screen state.
  36. /// </remarks>
  37. public bool UpdateWhenInactive { get; set; }
  38. /// <summary>
  39. /// Gets or sets a value indicating whether this screen should continue to draw when it is not the active screen.
  40. /// </summary>
  41. /// <remarks>
  42. /// This property allows background screens to continue rendering even when they are not the topmost screen
  43. /// in the screen stack of a screen manager. This is useful for creating layered visual effects where multiple
  44. /// screens nee dto be visible simultaneously such as a game world visible behind a semi-transparent menu or
  45. /// overlay.
  46. /// </remarks>
  47. public bool DrawWhenInactive { get; set; }
  48. /// <summary>
  49. /// Releases all resources used by the screen.
  50. /// </summary>
  51. /// <remarks>
  52. /// The base implementation does nothing.
  53. /// </remarks>
  54. public virtual void Dispose() { }
  55. /// <summary>
  56. /// Initializes the screen.
  57. /// </summary>
  58. /// <remarks>
  59. /// When the screen is added to a <see cref="Screens.ScreenManager"/>, this method will be called automatically
  60. /// when the screen is first shown.
  61. /// The base implementation does nothing.
  62. /// </remarks>
  63. public virtual void Initialize() { }
  64. /// <summary>
  65. /// Loads content and resources needed by the screen.
  66. /// </summary>
  67. /// <remarks>
  68. /// When the screen is added to a <see cref="Screens.ScreenManager"/>, this method will be called automatically
  69. /// after <see cref="Initialize()"/> when the screen is first shown.
  70. /// The base implementation does nothing.
  71. /// </remarks>
  72. public virtual void LoadContent() { }
  73. /// <summary>
  74. /// Unloads content and resources used by the screen.
  75. /// </summary>
  76. /// <remarks>
  77. /// When the screen is added to a <see cref="Screens.ScreenManager"/>, this method is called automatically when
  78. /// the screen is closed.
  79. /// The base implementation does nothing.
  80. /// </remarks>
  81. public virtual void UnloadContent() { }
  82. /// <summary>
  83. /// Updates the screen's logic.
  84. /// </summary>
  85. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  86. /// <remarks>
  87. /// When added to a <see cref="Screens.ScreenManager"/>, this method is called automatically every frame when
  88. /// either the <see cref="IsActive"/> or <see cref="UpdateWhenInactive"/> properties are <see langword="true"/>.
  89. /// </remarks>
  90. public abstract void Update(GameTime gameTime);
  91. /// <summary>
  92. /// Draws the screen's visual content.
  93. /// </summary>
  94. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  95. /// <remarks>
  96. /// When added to a <see cref="Screens.ScreenManager"/>, this method is called automatically every frame when
  97. /// either the <see cref="IsActive"/> or <see cref="DrawWhenInactive"/> properties are <see langword="true"/>.
  98. /// </remarks>
  99. public abstract void Draw(GameTime gameTime);
  100. }