documentation

This commit is contained in:
2019-01-13 23:23:03 -06:00
parent 4ac011f3cf
commit 32c2f25196
6 changed files with 117 additions and 36 deletions

View File

@@ -15,18 +15,18 @@ namespace RecrownedAthenaeum.ScreenSystem
/// Called every frame if the state of the screen this transition is placed upon is in the enter transition phase.
/// </summary>
/// <param name="delta">The time passed in seconds since the last frame.</param>
/// <param name="assetsLoaded">Whether or not if all assets have been loaded by the <see cref="ContentSystem"/>.</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 assetsLoaded);
bool EnteringTransition(double delta, bool waiting);
/// <summary>
/// Called every frame if the state of the screen this transition is placed upon is in the exit phase.
/// </summary>
/// <param name="delta">The time passed in seconds since the last frame.</param>
/// <param name="assetsLoaded">Whether or not if all assets have been loaded by the <see cref="ContentSystem"/>.</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 assetsLoaded);
bool ExitingTransition(double delta, bool waiting);
/// <summary>
/// Called once every frame while transition is active. Meant to draw transition.

View File

@@ -69,14 +69,14 @@ namespace RecrownedAthenaeum.ScreenSystem
}
public bool EnteringTransition(double delta, bool assetsLoaded)
public bool EnteringTransition(double delta, bool waiting)
{
float deltaf = (float)delta;
if (rotate)
{
DoRotate(deltaf);
}
if (assetsLoaded)
if (waiting)
{
if (progR < 254 || progG < 254 || progB < 254)
{
@@ -106,7 +106,7 @@ namespace RecrownedAthenaeum.ScreenSystem
return false;
}
public bool ExitingTransition(double delta, bool assetsLoaded)
public bool ExitingTransition(double delta, bool waiting)
{
float deltaf = (float)delta;
if (rotate)

View File

@@ -26,9 +26,6 @@ namespace RecrownedAthenaeum.ScreenSystem
/// <summary>
/// Called only once after initialization to give required parameters.
/// </summary>
/// <param name="graphicsDevice"></param>
/// <param name="screenSize"></param>
/// <param name="camera"></param>
public virtual void Initiate(GraphicsDevice graphicsDevice, Rectangle screenSize, Camera2D camera)
{
this.Camera = camera;
@@ -37,11 +34,19 @@ namespace RecrownedAthenaeum.ScreenSystem
Initiated = true;
}
/// <summary>
/// Called to update the screen.
/// </summary>
/// <param name="gameTime">Game time information.</param>
public virtual void Update(GameTime gameTime)
{
}
/// <summary>
/// Called to draw this screen.
/// </summary>
/// <param name="spriteBatch">SpriteBatch to use.</param>
public virtual void Draw(SpriteBatch spriteBatch)
{
foreach (ITransition transition in Transitions)
@@ -51,33 +56,33 @@ namespace RecrownedAthenaeum.ScreenSystem
}
/// <summary>
/// Updates the transition.
/// Updates the transition based on the current state of the screen.
/// </summary>
/// <param name="delta">Time passed since last frame in seconds.</param>
/// <param name="assetsLoaded">If waiting on assets.</param>
/// <param name="waiting">If the this transition should wait.</param>
/// <param name="previousScreenExitFrame">The previous screen's frame. May be null.</param>
/// <returns>Only returns true if exit transition is complete. Returns false otherwise.</returns>
public bool UpdateTransition(double delta, bool assetsLoaded)
public bool UpdateTransition(double delta, bool waiting)
{
switch (State)
{
case ScreenState.EnterTransition:
EnteringTransition(delta, assetsLoaded);
EnteringTransition(delta, waiting);
break;
case ScreenState.ExitTransition:
return ExitingTransition(delta, assetsLoaded);
return ExitingTransition(delta, waiting);
}
return false;
}
private void EnteringTransition(double delta, bool assetsLoaded)
private void EnteringTransition(double delta, bool waiting)
{
bool complete = true;
for (int transitionID = 0; transitionID < Transitions.Count; transitionID++)
{
ITransition transition = Transitions[transitionID];
if (!transition.EnteringTransition(delta, assetsLoaded))
if (!transition.EnteringTransition(delta, waiting))
{
complete = false;
}
@@ -88,12 +93,12 @@ namespace RecrownedAthenaeum.ScreenSystem
}
}
private bool ExitingTransition(double delta, bool assetsLoaded)
private bool ExitingTransition(double delta, bool waiting)
{
bool complete = true;
foreach (ITransition transition in Transitions)
{
if (!transition.ExitingTransition(delta, assetsLoaded))
if (!transition.ExitingTransition(delta, waiting))
{
complete = false;
}
@@ -113,11 +118,18 @@ namespace RecrownedAthenaeum.ScreenSystem
}
}
/// <summary>
/// Called when this screen is no longer the displayed screen.
/// </summary>
public virtual void Hide()
{
}
/// <summary>
/// Called whenever the status of assets changes from being loaded to unloaded or unloaded to loaded.
/// </summary>
/// <param name="state">True for loaded, false for unloaded.</param>
public virtual void AssetLoadStateChange(bool state)
{
@@ -125,12 +137,20 @@ namespace RecrownedAthenaeum.ScreenSystem
public ScreenState State { get; private set; }
/// <summary>
/// Call this to begin exit transition.
/// </summary>
/// <param name="UseRenderTargetForExitTransition">Whether or not to use a render target for the next screen to use.</param>
public void StartExitTransition(bool UseRenderTargetForExitTransition = false)
{
this.UseRenderTargetForExitTransition = UseRenderTargetForExitTransition;
State = ScreenState.ExitTransition;
}
/// <summary>
/// Called everytime the previous screen frame buffer updates. Used for transition purposes.
/// </summary>
/// <param name="previousScreenFrame">The previous screen's render buffer.</param>
public virtual void UpdatePreviousScreenFrame(RenderTarget2D previousScreenFrame)
{
foreach (ITransition transition in Transitions)

View File

@@ -6,19 +6,30 @@ using System.Diagnostics;
namespace RecrownedAthenaeum.ScreenSystem
{
public delegate void FirstScreenChange(Screen screen);
/// <summary>
/// Called when the first screen is being shown.
/// </summary>
/// <param name="screen">The screen to show after the loading screen.</param>
public delegate void ShowFirstScreen(Screen screen);
public class ScreenManager : IDisposable
{
bool disposed = false;
public event FirstScreenChange RequireNextScreenEvent;
/// <summary>
/// Called when the first loading screen is done, and needs to show the landing screen.
/// </summary>
public event ShowFirstScreen ShowFirstScreenEvent;
private GraphicsDeviceManager graphics;
private Screen previousScreen;
private RenderTarget2D previousScreenRenderTarget;
private Screen currentScreen;
private Camera2D camera;
private bool firstScreenChangeComplete;
private bool resizing;
/// <summary>
/// Currently displayed screen.
/// </summary>
public Screen Screen
{
get
@@ -46,25 +57,35 @@ namespace RecrownedAthenaeum.ScreenSystem
}
}
/// <summary>
/// Creates a screen manager that helps manage multiple screens and their transitions.
/// </summary>
/// <param name="graphicsDeviceManager">The graphics device manager to be used.</param>
/// <param name="camera">The camera to be used to perform the correct translations and transformations.</param>
public ScreenManager(GraphicsDeviceManager graphicsDeviceManager, Camera2D camera)
{
this.graphics = graphicsDeviceManager;
this.camera = camera;
}
public void UpdateCurrentScreen(GameTime gameTime, bool assetsDone)
/// <summary>
/// Updates the screens. Should be called once every frame.
/// </summary>
/// <param name="gameTime">Contains the time that has passed from the last frame.</param>
/// <param name="waiting">Whether or not there is something a transition should be waiting for. Usually used to wait for assets to complete loading.</param>
public void UpdateCurrentScreen(GameTime gameTime, bool waiting)
{
switch (Screen.State)
{
case ScreenState.EnterTransition:
if (previousScreen != null && previousScreen.UseRenderTargetForExitTransition)
{
previousScreen.UpdateTransition(gameTime.ElapsedGameTime.TotalSeconds, assetsDone);
previousScreen.UpdateTransition(gameTime.ElapsedGameTime.TotalSeconds, waiting);
}
Screen.UpdateTransition(gameTime.ElapsedGameTime.TotalSeconds, assetsDone);
Screen.UpdateTransition(gameTime.ElapsedGameTime.TotalSeconds, waiting);
break;
case ScreenState.ExitTransition:
if (Screen.UseRenderTargetForExitTransition || Screen.UpdateTransition(gameTime.ElapsedGameTime.TotalSeconds, assetsDone))
if (Screen.UseRenderTargetForExitTransition || Screen.UpdateTransition(gameTime.ElapsedGameTime.TotalSeconds, waiting))
{
if (!firstScreenChangeComplete)
{
@@ -91,6 +112,10 @@ namespace RecrownedAthenaeum.ScreenSystem
Screen.Update(gameTime);
}
/// <summary>
/// Renders screen into window.
/// </summary>
/// <param name="spriteBatch">Uses this batch to render.</param>
public void DrawCurrentScreen(SpriteBatch spriteBatch)
{
graphics.GraphicsDevice.Clear(Screen.BackgroundColor);
@@ -109,22 +134,33 @@ namespace RecrownedAthenaeum.ScreenSystem
spriteBatch.End();
}
/// <summary>
/// Should be called when resize is occurring to change to a loading screen.
/// This will notify the screen of the status of the assets, change the screen to a loading screen, and dispose of the previous screen buffer.
/// </summary>
/// <param name="loadingScreen">The loading screen to change to.</param>
public void Resize(LoadingScreen loadingScreen)
{
Screen.AssetLoadStateChange(true);
if (resizing) throw new InvalidOperationException("Already resizing.");
resizing = true;
Screen.AssetLoadStateChange(false);
Screen = loadingScreen;
previousScreenRenderTarget.Dispose();
previousScreenRenderTarget = null;
}
/// <summary>
/// Notifies all screen that assets have completed being loaded after a resize.
/// </summary>
public void PostResize()
{
Screen.AssetLoadStateChange(false);
if (!resizing) throw new InvalidOperationException("Was never resizing.");
Screen.AssetLoadStateChange(true);
}
public void OnFirstScreenChange(Screen screen)
private void OnFirstScreenChange(Screen screen)
{
RequireNextScreenEvent?.Invoke(screen);
ShowFirstScreenEvent?.Invoke(screen);
}
public void Dispose()