Even more documentation.
This commit is contained in:
@@ -3,11 +3,14 @@ using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace RecrownedAthenaeum.ScreenSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Contracts a transition that the <see cref="ScreenManager"/> can use.
|
||||
/// </summary>
|
||||
public interface ITransition
|
||||
{
|
||||
/// <summary>
|
||||
/// Called once when the transition is needed.
|
||||
/// <param name="Dimensions">The dimensions of the screen.</param>
|
||||
/// <param name="dimensions">The dimensions of the screen.</param>
|
||||
/// </summary>
|
||||
void InitiateTransition(Rectangle dimensions);
|
||||
|
||||
@@ -16,9 +19,8 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
/// </summary>
|
||||
/// <param name="delta">The time passed in seconds since the last frame.</param>
|
||||
/// <param name="waiting">Whether or not this transition is waiting on something. Usually the <see cref="ContentSystem"/>.</param>
|
||||
/// <param name="previousScreenExitFrame">The frame being rendered by the screen as it exits. This can be null.</param>
|
||||
/// <returns>If this returns true, then it is considered that this transition is complete.</returns>
|
||||
bool EnteringTransition(double delta, bool waiting);
|
||||
bool UpdateEnteringTransition(double delta, bool waiting);
|
||||
|
||||
/// <summary>
|
||||
/// Called every frame if the state of the screen this transition is placed upon is in the exit phase.
|
||||
@@ -26,7 +28,7 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
/// <param name="delta">The time passed in seconds since the last frame.</param>
|
||||
/// <param name="waiting">Whether or not this transition is waiting on something. Usually the <see cref="ContentSystem"/>.</param>
|
||||
/// <returns>If this returns true, then it is considered that this transition is complete.</returns>
|
||||
bool ExitingTransition(double delta, bool waiting);
|
||||
bool UpdateExitingTransition(double delta, bool waiting);
|
||||
|
||||
/// <summary>
|
||||
/// Called once every frame while transition is active. Meant to draw transition.
|
||||
|
@@ -5,6 +5,9 @@ using System;
|
||||
|
||||
namespace RecrownedAthenaeum.ScreenSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// A screen specifically meant to fill in loading times.
|
||||
/// </summary>
|
||||
public class LoadingScreen : Screen, ITransition
|
||||
{
|
||||
private const float ENTER_TIME = 2f;
|
||||
@@ -22,6 +25,13 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
readonly bool rotate;
|
||||
Vector2 origin;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a loading screen.
|
||||
/// </summary>
|
||||
/// <param name="game">The game itself to adjust mouse settings and such.</param>
|
||||
/// <param name="screenImage"></param>
|
||||
/// <param name="proportion"></param>
|
||||
/// <param name="rotate"></param>
|
||||
public LoadingScreen(Game game, Texture2D screenImage, float proportion, bool rotate = false) : base(true)
|
||||
{
|
||||
this.game = game;
|
||||
@@ -31,18 +41,24 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
Transitions.Add(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Show()
|
||||
{
|
||||
game.IsMouseVisible = false;
|
||||
base.Show();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Hide()
|
||||
{
|
||||
game.IsMouseVisible = true;
|
||||
base.Hide();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets things to correct values for start of transition.
|
||||
/// </summary>
|
||||
/// <param name="dimensions">The window dimensions.</param>
|
||||
public void InitiateTransition(Rectangle dimensions)
|
||||
{
|
||||
color = Color.White;
|
||||
@@ -63,13 +79,22 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws the transition.
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">Batch to use.</param>
|
||||
public void DrawTransition(SpriteBatch spriteBatch)
|
||||
{
|
||||
spriteBatch.Draw(texture, textureBounds, null, color, rotation, origin, SpriteEffects.None, 0f);
|
||||
}
|
||||
|
||||
|
||||
public bool EnteringTransition(double delta, bool waiting)
|
||||
/// <summary>
|
||||
/// Updates the entering transition.
|
||||
/// </summary>
|
||||
/// <param name="delta">Time passed between frames.</param>
|
||||
/// <param name="waiting">Whether or not this transition should be waiting.</param>
|
||||
/// <returns>Whether or not transition is complete.</returns>
|
||||
public bool UpdateEnteringTransition(double delta, bool waiting)
|
||||
{
|
||||
float deltaf = (float)delta;
|
||||
if (rotate)
|
||||
@@ -106,7 +131,13 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool ExitingTransition(double delta, bool waiting)
|
||||
/// <summary>
|
||||
/// Updates the exiting transition.
|
||||
/// </summary>
|
||||
/// <param name="delta">Time passed between frames.</param>
|
||||
/// <param name="waiting">Whether or not this transition should be waiting.</param>
|
||||
/// <returns>Whether or not transition is complete.</returns>
|
||||
public bool UpdateExitingTransition(double delta, bool waiting)
|
||||
{
|
||||
float deltaf = (float)delta;
|
||||
if (rotate)
|
||||
|
@@ -5,18 +5,72 @@ using System.Collections.Generic;
|
||||
|
||||
namespace RecrownedAthenaeum.ScreenSystem
|
||||
{
|
||||
public enum ScreenState { EnterTransition, ExitTransition, Normal }
|
||||
/// <summary>
|
||||
/// Represents one of the poosible states a screen can be in.
|
||||
/// </summary>
|
||||
public enum ScreenState {
|
||||
/// <summary>
|
||||
/// Screen is transitioning in.
|
||||
/// </summary>
|
||||
EnterTransition,
|
||||
/// <summary>
|
||||
/// Screen is transitioning out.
|
||||
/// </summary>
|
||||
ExitTransition,
|
||||
/// <summary>
|
||||
/// Screen is currently displayed normally without transition.
|
||||
/// </summary>
|
||||
Normal
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A screen represents a virtual system of management that controls an system of items to be displayed.
|
||||
/// </summary>
|
||||
public class Screen
|
||||
{
|
||||
public List<ITransition> Transitions;
|
||||
public bool UseRenderTargetForExitTransition;
|
||||
/// <summary>
|
||||
/// Transitions to apply.
|
||||
/// </summary>
|
||||
public readonly List<ITransition> Transitions;
|
||||
/// <summary>
|
||||
/// Whether or not to continue rendering this screen onto a buffer for the benifit of the next screen to use as a transition.
|
||||
/// </summary>
|
||||
public bool UseRenderTargetForExitTransition { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The background color to be used to clear the screen.
|
||||
/// </summary>
|
||||
public Color BackgroundColor;
|
||||
public GraphicsDevice GraphicsDevice { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The next screen to be displayed after exit transition finishes. May be null, leading to transition to previous screen or loading screen.
|
||||
/// </summary>
|
||||
public Screen NextScreen { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The current window size.
|
||||
/// </summary>
|
||||
public Rectangle ScreenSize { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not screen have been initiated.
|
||||
/// </summary>
|
||||
public bool Initiated { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The 2D camera to be used for the screen.
|
||||
/// </summary>
|
||||
public Camera2D Camera { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Current state of the screen.
|
||||
/// </summary>
|
||||
public ScreenState State { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new screen.
|
||||
/// </summary>
|
||||
/// <param name="useEnterTransition">True to start in entering transition state.</param>
|
||||
public Screen(bool useEnterTransition = false)
|
||||
{
|
||||
State = useEnterTransition ? ScreenState.EnterTransition : ScreenState.Normal;
|
||||
@@ -26,11 +80,10 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
/// <summary>
|
||||
/// Called only once after initialization to give required parameters.
|
||||
/// </summary>
|
||||
public virtual void Initiate(GraphicsDevice graphicsDevice, Rectangle screenSize, Camera2D camera)
|
||||
public virtual void Initiate(Rectangle screenSize, Camera2D camera)
|
||||
{
|
||||
this.Camera = camera;
|
||||
this.ScreenSize = screenSize;
|
||||
GraphicsDevice = graphicsDevice;
|
||||
Initiated = true;
|
||||
}
|
||||
|
||||
@@ -82,7 +135,7 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
for (int transitionID = 0; transitionID < Transitions.Count; transitionID++)
|
||||
{
|
||||
ITransition transition = Transitions[transitionID];
|
||||
if (!transition.EnteringTransition(delta, waiting))
|
||||
if (!transition.UpdateEnteringTransition(delta, waiting))
|
||||
{
|
||||
complete = false;
|
||||
}
|
||||
@@ -98,7 +151,7 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
bool complete = true;
|
||||
foreach (ITransition transition in Transitions)
|
||||
{
|
||||
if (!transition.ExitingTransition(delta, waiting))
|
||||
if (!transition.UpdateExitingTransition(delta, waiting))
|
||||
{
|
||||
complete = false;
|
||||
}
|
||||
@@ -135,7 +188,6 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
|
||||
}
|
||||
|
||||
public ScreenState State { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Call this to begin exit transition.
|
||||
|
@@ -12,6 +12,9 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
/// <param name="screen">The screen to show after the loading screen.</param>
|
||||
public delegate void ShowFirstScreen(Screen screen);
|
||||
|
||||
/// <summary>
|
||||
/// A manager for screens. Helps with transitions and updating screens as well as resizes.
|
||||
/// </summary>
|
||||
public class ScreenManager : IDisposable
|
||||
{
|
||||
bool disposed = false;
|
||||
@@ -42,7 +45,7 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
currentScreen = value;
|
||||
if (!Screen.Initiated)
|
||||
{
|
||||
Screen.Initiate(graphics.GraphicsDevice, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight), camera);
|
||||
Screen.Initiate(new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight), camera);
|
||||
}
|
||||
if (previousScreen != null && previousScreenRenderTarget == null && previousScreen.UseRenderTargetForExitTransition)
|
||||
{
|
||||
@@ -163,12 +166,19 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
ShowFirstScreenEvent?.Invoke(screen);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes this.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An overridable dispose.
|
||||
/// </summary>
|
||||
/// <param name="disposing">True of user invoked dispose called.</param>
|
||||
public virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposed) return;
|
||||
@@ -178,5 +188,13 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
}
|
||||
disposing = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Destructor.
|
||||
/// </summary>
|
||||
~ScreenManager()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user