documentation

This commit is contained in:
Harrison Deng 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. /// Called every frame if the state of the screen this transition is placed upon is in the enter transition phase.
/// </summary> /// </summary>
/// <param name="delta">The time passed in seconds since the last frame.</param> /// <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> /// <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> /// <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> /// <summary>
/// Called every frame if the state of the screen this transition is placed upon is in the exit phase. /// Called every frame if the state of the screen this transition is placed upon is in the exit phase.
/// </summary> /// </summary>
/// <param name="delta">The time passed in seconds since the last frame.</param> /// <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> /// <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> /// <summary>
/// Called once every frame while transition is active. Meant to draw transition. /// 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; float deltaf = (float)delta;
if (rotate) if (rotate)
{ {
DoRotate(deltaf); DoRotate(deltaf);
} }
if (assetsLoaded) if (waiting)
{ {
if (progR < 254 || progG < 254 || progB < 254) if (progR < 254 || progG < 254 || progB < 254)
{ {
@ -106,7 +106,7 @@ namespace RecrownedAthenaeum.ScreenSystem
return false; return false;
} }
public bool ExitingTransition(double delta, bool assetsLoaded) public bool ExitingTransition(double delta, bool waiting)
{ {
float deltaf = (float)delta; float deltaf = (float)delta;
if (rotate) if (rotate)

View File

@ -26,9 +26,6 @@ namespace RecrownedAthenaeum.ScreenSystem
/// <summary> /// <summary>
/// Called only once after initialization to give required parameters. /// Called only once after initialization to give required parameters.
/// </summary> /// </summary>
/// <param name="graphicsDevice"></param>
/// <param name="screenSize"></param>
/// <param name="camera"></param>
public virtual void Initiate(GraphicsDevice graphicsDevice, Rectangle screenSize, Camera2D camera) public virtual void Initiate(GraphicsDevice graphicsDevice, Rectangle screenSize, Camera2D camera)
{ {
this.Camera = camera; this.Camera = camera;
@ -37,11 +34,19 @@ namespace RecrownedAthenaeum.ScreenSystem
Initiated = true; Initiated = true;
} }
/// <summary>
/// Called to update the screen.
/// </summary>
/// <param name="gameTime">Game time information.</param>
public virtual void Update(GameTime gameTime) 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) public virtual void Draw(SpriteBatch spriteBatch)
{ {
foreach (ITransition transition in Transitions) foreach (ITransition transition in Transitions)
@ -51,33 +56,33 @@ namespace RecrownedAthenaeum.ScreenSystem
} }
/// <summary> /// <summary>
/// Updates the transition. /// Updates the transition based on the current state of the screen.
/// </summary> /// </summary>
/// <param name="delta">Time passed since last frame in seconds.</param> /// <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> /// <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> /// <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) switch (State)
{ {
case ScreenState.EnterTransition: case ScreenState.EnterTransition:
EnteringTransition(delta, assetsLoaded); EnteringTransition(delta, waiting);
break; break;
case ScreenState.ExitTransition: case ScreenState.ExitTransition:
return ExitingTransition(delta, assetsLoaded); return ExitingTransition(delta, waiting);
} }
return false; return false;
} }
private void EnteringTransition(double delta, bool assetsLoaded) private void EnteringTransition(double delta, bool waiting)
{ {
bool complete = true; bool complete = true;
for (int transitionID = 0; transitionID < Transitions.Count; transitionID++) for (int transitionID = 0; transitionID < Transitions.Count; transitionID++)
{ {
ITransition transition = Transitions[transitionID]; ITransition transition = Transitions[transitionID];
if (!transition.EnteringTransition(delta, assetsLoaded)) if (!transition.EnteringTransition(delta, waiting))
{ {
complete = false; 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; bool complete = true;
foreach (ITransition transition in Transitions) foreach (ITransition transition in Transitions)
{ {
if (!transition.ExitingTransition(delta, assetsLoaded)) if (!transition.ExitingTransition(delta, waiting))
{ {
complete = false; 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() 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) public virtual void AssetLoadStateChange(bool state)
{ {
@ -125,12 +137,20 @@ namespace RecrownedAthenaeum.ScreenSystem
public ScreenState State { get; private set; } 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) public void StartExitTransition(bool UseRenderTargetForExitTransition = false)
{ {
this.UseRenderTargetForExitTransition = UseRenderTargetForExitTransition; this.UseRenderTargetForExitTransition = UseRenderTargetForExitTransition;
State = ScreenState.ExitTransition; 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) public virtual void UpdatePreviousScreenFrame(RenderTarget2D previousScreenFrame)
{ {
foreach (ITransition transition in Transitions) foreach (ITransition transition in Transitions)

View File

@ -6,19 +6,30 @@ using System.Diagnostics;
namespace RecrownedAthenaeum.ScreenSystem 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 public class ScreenManager : IDisposable
{ {
bool disposed = false; 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 GraphicsDeviceManager graphics;
private Screen previousScreen; private Screen previousScreen;
private RenderTarget2D previousScreenRenderTarget; private RenderTarget2D previousScreenRenderTarget;
private Screen currentScreen; private Screen currentScreen;
private Camera2D camera; private Camera2D camera;
private bool firstScreenChangeComplete; private bool firstScreenChangeComplete;
private bool resizing;
/// <summary>
/// Currently displayed screen.
/// </summary>
public Screen Screen public Screen Screen
{ {
get 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) public ScreenManager(GraphicsDeviceManager graphicsDeviceManager, Camera2D camera)
{ {
this.graphics = graphicsDeviceManager; this.graphics = graphicsDeviceManager;
this.camera = camera; 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) switch (Screen.State)
{ {
case ScreenState.EnterTransition: case ScreenState.EnterTransition:
if (previousScreen != null && previousScreen.UseRenderTargetForExitTransition) 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; break;
case ScreenState.ExitTransition: case ScreenState.ExitTransition:
if (Screen.UseRenderTargetForExitTransition || Screen.UpdateTransition(gameTime.ElapsedGameTime.TotalSeconds, assetsDone)) if (Screen.UseRenderTargetForExitTransition || Screen.UpdateTransition(gameTime.ElapsedGameTime.TotalSeconds, waiting))
{ {
if (!firstScreenChangeComplete) if (!firstScreenChangeComplete)
{ {
@ -91,6 +112,10 @@ namespace RecrownedAthenaeum.ScreenSystem
Screen.Update(gameTime); Screen.Update(gameTime);
} }
/// <summary>
/// Renders screen into window.
/// </summary>
/// <param name="spriteBatch">Uses this batch to render.</param>
public void DrawCurrentScreen(SpriteBatch spriteBatch) public void DrawCurrentScreen(SpriteBatch spriteBatch)
{ {
graphics.GraphicsDevice.Clear(Screen.BackgroundColor); graphics.GraphicsDevice.Clear(Screen.BackgroundColor);
@ -109,22 +134,33 @@ namespace RecrownedAthenaeum.ScreenSystem
spriteBatch.End(); 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) public void Resize(LoadingScreen loadingScreen)
{ {
Screen.AssetLoadStateChange(true); if (resizing) throw new InvalidOperationException("Already resizing.");
resizing = true;
Screen.AssetLoadStateChange(false);
Screen = loadingScreen; Screen = loadingScreen;
previousScreenRenderTarget.Dispose(); previousScreenRenderTarget.Dispose();
previousScreenRenderTarget = null; previousScreenRenderTarget = null;
} }
/// <summary>
/// Notifies all screen that assets have completed being loaded after a resize.
/// </summary>
public void PostResize() 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() public void Dispose()

View File

@ -14,29 +14,46 @@ namespace RecrownedAthenaeum.UI.Modular
public string Name; public string Name;
public Color color = Color.White; public Color color = Color.White;
/// <summary>
/// Called every frame to update this module. Calculations and movement should go here.
/// </summary>
/// <param name="gameTime">Game time information.</param>
public virtual void Update(GameTime gameTime) public virtual void Update(GameTime gameTime)
{ {
} }
/// <summary>
/// Called every frame to draw this module. Anything that needs to be drawn should go here.
/// </summary>
/// <param name="batch">Batch used to draw.</param>
public virtual void Draw(SpriteBatch batch) public virtual void Draw(SpriteBatch batch)
{ {
} }
public Rectangle ConvertToParentCoordinates(Rectangle bounds) /// <summary>
/// Converts the given rectangle to the coordinates of the parent.
/// </summary>
/// <param name="rectangle">Rectangle to convert.</param>
/// <returns></returns>
public Rectangle ConvertToParentCoordinates(Rectangle rectangle)
{ {
if (Parent != null) if (Parent != null)
{ {
Rectangle parentHitbox = Parent.ConvertToParentCoordinates(bounds); Rectangle parentHitbox = Parent.ConvertToParentCoordinates(rectangle);
int tX = bounds.X + parentHitbox.X; int tX = rectangle.X + parentHitbox.X;
int tY = bounds.Y + parentHitbox.Y; int tY = rectangle.Y + parentHitbox.Y;
return new Rectangle(tX, tY, bounds.Width, bounds.Height); return new Rectangle(tX, tY, rectangle.Width, rectangle.Height);
} else } else
{ {
return bounds; return rectangle;
} }
} }
/// <summary>
/// Removes this module from the parent.
/// </summary>
public void RemoveFromParent() public void RemoveFromParent()
{ {
if (Parent == null) if (Parent == null)

View File

@ -65,6 +65,10 @@ namespace RecrownedAthenaeum.UI.Modular
} }
} }
/// <summary>
/// Adds module(s) to this group.
/// </summary>
/// <param name="addModules">The module(s) to add.</param>
public void AddModule(params UIModule[] addModules) public void AddModule(params UIModule[] addModules)
{ {
foreach (UIModule module in addModules) foreach (UIModule module in addModules)
@ -78,6 +82,10 @@ namespace RecrownedAthenaeum.UI.Modular
} }
} }
/// <summary>
/// Removes given module from group.
/// </summary>
/// <param name="module">module to remove.</param>
public void RemoveModule(UIModule module) public void RemoveModule(UIModule module)
{ {
module.Parent = null; module.Parent = null;