2018-11-30 02:41:06 +00:00
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
2018-12-04 13:45:09 +00:00
|
|
|
|
using RecrownedAthenaeum.Camera;
|
2018-11-30 02:41:06 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
2018-12-04 13:45:09 +00:00
|
|
|
|
namespace RecrownedAthenaeum.ScreenSystem
|
2018-11-30 02:41:06 +00:00
|
|
|
|
{
|
|
|
|
|
public enum ScreenState { EnterTransition, ExitTransition, Normal }
|
|
|
|
|
|
|
|
|
|
public class Screen
|
|
|
|
|
{
|
|
|
|
|
public List<ITransition> Transitions;
|
|
|
|
|
public bool UseRenderTargetForExitTransition;
|
|
|
|
|
public Color BackgroundColor;
|
|
|
|
|
public GraphicsDevice GraphicsDevice { get; private set; }
|
|
|
|
|
public Screen NextScreen { get; set; }
|
|
|
|
|
public Rectangle ScreenSize { get; private set; }
|
|
|
|
|
public bool Initiated { get; private set; }
|
|
|
|
|
public Camera2D Camera { get; private set; }
|
|
|
|
|
public Screen(bool useEnterTransition = false)
|
|
|
|
|
{
|
|
|
|
|
State = useEnterTransition ? ScreenState.EnterTransition : ScreenState.Normal;
|
|
|
|
|
Transitions = new List<ITransition>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Called only once after initialization to give required parameters.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual void Initiate(GraphicsDevice graphicsDevice, Rectangle screenSize, Camera2D camera)
|
|
|
|
|
{
|
|
|
|
|
this.Camera = camera;
|
|
|
|
|
this.ScreenSize = screenSize;
|
|
|
|
|
GraphicsDevice = graphicsDevice;
|
|
|
|
|
Initiated = true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 05:23:03 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Called to update the screen.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="gameTime">Game time information.</param>
|
2018-11-30 02:41:06 +00:00
|
|
|
|
public virtual void Update(GameTime gameTime)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 05:23:03 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Called to draw this screen.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="spriteBatch">SpriteBatch to use.</param>
|
2018-11-30 02:41:06 +00:00
|
|
|
|
public virtual void Draw(SpriteBatch spriteBatch)
|
|
|
|
|
{
|
|
|
|
|
foreach (ITransition transition in Transitions)
|
|
|
|
|
{
|
|
|
|
|
transition.DrawTransition(spriteBatch);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-01-14 05:23:03 +00:00
|
|
|
|
/// Updates the transition based on the current state of the screen.
|
2018-11-30 02:41:06 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="delta">Time passed since last frame in seconds.</param>
|
2019-01-14 05:23:03 +00:00
|
|
|
|
/// <param name="waiting">If the this transition should wait.</param>
|
2018-11-30 02:41:06 +00:00
|
|
|
|
/// <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>
|
2019-01-14 05:23:03 +00:00
|
|
|
|
public bool UpdateTransition(double delta, bool waiting)
|
2018-11-30 02:41:06 +00:00
|
|
|
|
{
|
|
|
|
|
switch (State)
|
|
|
|
|
{
|
|
|
|
|
case ScreenState.EnterTransition:
|
2019-01-14 05:23:03 +00:00
|
|
|
|
EnteringTransition(delta, waiting);
|
2018-11-30 02:41:06 +00:00
|
|
|
|
break;
|
|
|
|
|
case ScreenState.ExitTransition:
|
2019-01-14 05:23:03 +00:00
|
|
|
|
return ExitingTransition(delta, waiting);
|
2018-11-30 02:41:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 05:23:03 +00:00
|
|
|
|
private void EnteringTransition(double delta, bool waiting)
|
2018-11-30 02:41:06 +00:00
|
|
|
|
{
|
|
|
|
|
bool complete = true;
|
|
|
|
|
for (int transitionID = 0; transitionID < Transitions.Count; transitionID++)
|
|
|
|
|
{
|
|
|
|
|
ITransition transition = Transitions[transitionID];
|
2019-01-14 05:23:03 +00:00
|
|
|
|
if (!transition.EnteringTransition(delta, waiting))
|
2018-11-30 02:41:06 +00:00
|
|
|
|
{
|
|
|
|
|
complete = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (complete && State != ScreenState.ExitTransition)
|
|
|
|
|
{
|
|
|
|
|
State = ScreenState.Normal;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 05:23:03 +00:00
|
|
|
|
private bool ExitingTransition(double delta, bool waiting)
|
2018-11-30 02:41:06 +00:00
|
|
|
|
{
|
|
|
|
|
bool complete = true;
|
|
|
|
|
foreach (ITransition transition in Transitions)
|
|
|
|
|
{
|
2019-01-14 05:23:03 +00:00
|
|
|
|
if (!transition.ExitingTransition(delta, waiting))
|
2018-11-30 02:41:06 +00:00
|
|
|
|
{
|
|
|
|
|
complete = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return complete;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Called when the screen is shown.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual void Show()
|
|
|
|
|
{
|
|
|
|
|
foreach (ITransition transition in Transitions)
|
|
|
|
|
{
|
|
|
|
|
transition.InitiateTransition(ScreenSize);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 05:23:03 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Called when this screen is no longer the displayed screen.
|
|
|
|
|
/// </summary>
|
2018-11-30 02:41:06 +00:00
|
|
|
|
public virtual void Hide()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 05:23:03 +00:00
|
|
|
|
/// <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>
|
2018-11-30 02:41:06 +00:00
|
|
|
|
public virtual void AssetLoadStateChange(bool state)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ScreenState State { get; private set; }
|
|
|
|
|
|
2019-01-14 05:23:03 +00:00
|
|
|
|
/// <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>
|
2018-11-30 02:41:06 +00:00
|
|
|
|
public void StartExitTransition(bool UseRenderTargetForExitTransition = false)
|
|
|
|
|
{
|
|
|
|
|
this.UseRenderTargetForExitTransition = UseRenderTargetForExitTransition;
|
|
|
|
|
State = ScreenState.ExitTransition;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 05:23:03 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Called everytime the previous screen frame buffer updates. Used for transition purposes.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="previousScreenFrame">The previous screen's render buffer.</param>
|
2018-11-30 02:41:06 +00:00
|
|
|
|
public virtual void UpdatePreviousScreenFrame(RenderTarget2D previousScreenFrame)
|
|
|
|
|
{
|
|
|
|
|
foreach (ITransition transition in Transitions)
|
|
|
|
|
{
|
|
|
|
|
transition.UpdatePreviousScreenFrame(previousScreenFrame);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|