diff --git a/RhythmBullet/RhythmBullet.csproj b/RhythmBullet/RhythmBullet.csproj
index bf9c636..398dffe 100644
--- a/RhythmBullet/RhythmBullet.csproj
+++ b/RhythmBullet/RhythmBullet.csproj
@@ -47,12 +47,13 @@
true
-
+
-
+
+
@@ -62,7 +63,7 @@
-
+
diff --git a/RhythmBullet/RhythmBulletGame.cs b/RhythmBullet/RhythmBulletGame.cs
index c1718af..1c95fd3 100644
--- a/RhythmBullet/RhythmBulletGame.cs
+++ b/RhythmBullet/RhythmBulletGame.cs
@@ -1,15 +1,13 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
-using RhythmBullet.Zer01HD.Game;
using RhythmBullet.Zer01HD.Game.ContentResolvers;
using RhythmBullet.Zer01HD.Game.Preferences;
using RhythmBullet.Zer01HD.Game.Screens;
-using RhythmBullet.Zer01HD.UI;
using RhythmBullet.Zer01HD.Utilities;
using RhythmBullet.Zer01HD.Utilities.ContentSystem;
using RhythmBullet.Zer01HD.Utilities.DataTypes;
-using RhythmBullet.Zer01HD.Utilities.UI;
+using RhythmBullet.Zer01HD.Utilities.UI.ScreenSystem;
using System;
using System.Diagnostics;
@@ -26,17 +24,16 @@ namespace RhythmBullet
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
- public Color BackgroundColor;
public readonly ContentSystem Assets;
readonly ResolutionContentResolver resolutionContentResolver;
public PreferencesManager preferencesManager;
private Screen previousScreen;
+ private RenderTarget2D previousScreenRenderTarget;
private Screen currentScreen;
private bool resizing;
public RhythmBulletGame()
{
graphics = new GraphicsDeviceManager(this);
- BackgroundColor = Color.Black;
Content.RootDirectory = "Content";
Assets = new ContentSystem(Content);
resolutionContentResolver = new ResolutionContentResolver();
@@ -52,31 +49,6 @@ namespace RhythmBullet
graphics.PreferredBackBufferHeight = resolution.Height;
}
- public Screen Screen
- {
- get
- {
- return currentScreen;
- }
- set
- {
- if (currentScreen != null)
- {
- if (value.GetType() != typeof(MainScreen))
- {
- previousScreen = value;
- }
- Screen.Hide();
- }
- currentScreen = value;
- if (!Screen.Initiated)
- {
- Screen.Initiate(new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight), graphics.GraphicsDevice);
- }
- Screen.Show();
- }
- }
-
///
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
@@ -101,7 +73,7 @@ namespace RhythmBullet
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
QueueContent();
- Screen = new LoadingScreen(Content.Load("RhythmBullet"), 0.7f, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));
+ Screen = new LoadingScreen(Content.Load("RhythmBullet"), 0.7f);
}
///
@@ -111,6 +83,7 @@ namespace RhythmBullet
protected override void UnloadContent()
{
Assets.UnloadAll();
+ previousScreenRenderTarget.Dispose();
}
///
@@ -134,23 +107,22 @@ namespace RhythmBullet
case ScreenState.EnterTransition:
if (previousScreen != null && previousScreen.UseRenderTargetForExitTransition)
{
- graphics.GraphicsDevice.SetRenderTarget(previousScreen.RenderTarget);
- previousScreen.ExitingTransition(gameTime.ElapsedGameTime.TotalSeconds, Assets.Done, ref BackgroundColor);
- previousScreen.Draw(spriteBatch);
- graphics.GraphicsDevice.SetRenderTarget(null);
+ previousScreen.UpdateTransition(gameTime.ElapsedGameTime.TotalSeconds, Assets.Done);
}
- Screen.EnteringTransition(gameTime.ElapsedGameTime.TotalSeconds, Assets.Done, ref BackgroundColor, previousScreen?.RenderTarget);
+ Screen.UpdateTransition(gameTime.ElapsedGameTime.TotalSeconds, Assets.Done);
break;
case ScreenState.ExitTransition:
- if (Screen.UseRenderTargetForExitTransition || Screen.ExitingTransition(gameTime.ElapsedGameTime.TotalSeconds, Assets.Done, ref BackgroundColor))
+ if (Screen.UseRenderTargetForExitTransition || Screen.UpdateTransition(gameTime.ElapsedGameTime.TotalSeconds, Assets.Done))
{
if (Screen.NextScreen != null)
{
+ Debug.WriteLine("Changing to the next given screen.");
Screen = Screen.NextScreen;
}
else
{
- Screen = previousScreen != null ? previousScreen : new MainScreen(graphics.GraphicsDevice, BackgroundColor, Assets);
+ Debug.WriteLine("Changing to default screen.");
+ Screen = previousScreen != null ? previousScreen : new MainScreen(graphics.GraphicsDevice, Assets);
}
}
break;
@@ -168,7 +140,17 @@ namespace RhythmBullet
/// Provides a snapshot of timing values.
protected override void Draw(GameTime gameTime)
{
- GraphicsDevice.Clear(BackgroundColor);
+ GraphicsDevice.Clear(Screen.BackgroundColor);
+ if (Screen.State == ScreenState.EnterTransition && previousScreen != null && previousScreen.UseRenderTargetForExitTransition)
+ {
+ graphics.GraphicsDevice.SetRenderTarget(previousScreenRenderTarget);
+ GraphicsDevice.Clear(previousScreen.BackgroundColor);
+ spriteBatch.Begin();
+ previousScreen.Draw(spriteBatch);
+ spriteBatch.End();
+ graphics.GraphicsDevice.SetRenderTarget(null);
+ Screen.UpdatePreviousScreenFrame(previousScreenRenderTarget);
+ }
spriteBatch.Begin();
Screen.Draw(spriteBatch);
spriteBatch.End();
@@ -187,7 +169,9 @@ namespace RhythmBullet
Assets.UnloadAll();
QueueContent();
Screen.AssetLoadStateChange(true);
- Screen = new LoadingScreen(Content.Load("loading_ring"), 0.3f, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight), true);
+ Screen = new LoadingScreen(Content.Load("loading_ring"), 0.3f, true);
+ previousScreenRenderTarget.Dispose();
+ previousScreenRenderTarget = null;
}
private void PostResize()
@@ -202,5 +186,32 @@ namespace RhythmBullet
Assets.Queue("default_cover", false);
Assets.Queue("backgrounds/mainBG");
}
+
+ public Screen Screen
+ {
+ get
+ {
+ return currentScreen;
+ }
+ set
+ {
+ previousScreen = currentScreen;
+ currentScreen = value;
+ if (!Screen.Initiated)
+ {
+ Screen.Initiate(new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));
+ }
+ if (previousScreen != null && previousScreenRenderTarget == null && previousScreen.UseRenderTargetForExitTransition)
+ {
+ previousScreenRenderTarget = new RenderTarget2D(graphics.GraphicsDevice, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
+ }
+ graphics.GraphicsDevice.SetRenderTarget(previousScreenRenderTarget);
+ graphics.GraphicsDevice.Clear(Color.Black);
+
+ Debug.WriteLine("Showing " + value.GetType().Name);
+ Debug.WriteLine("Previous screen is " + previousScreen?.GetType().Name);
+ Screen.Show();
+ }
+ }
}
}
diff --git a/RhythmBullet/Zer01HD/Game/Screens/MainScreen.cs b/RhythmBullet/Zer01HD/Game/Screens/MainScreen.cs
index 3259fd0..19e8417 100644
--- a/RhythmBullet/Zer01HD/Game/Screens/MainScreen.cs
+++ b/RhythmBullet/Zer01HD/Game/Screens/MainScreen.cs
@@ -4,8 +4,10 @@ using RhythmBullet.Zer01HD.Game.Screens.Transitions;
using RhythmBullet.Zer01HD.UI;
using RhythmBullet.Zer01HD.Utilities.ContentSystem;
using RhythmBullet.Zer01HD.Utilities.UI;
+using RhythmBullet.Zer01HD.Utilities.UI.ScreenSystem;
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -15,31 +17,24 @@ namespace RhythmBullet.Zer01HD.Game.Screens
class MainScreen : Screen
{
Texture2D background;
- FadeInTransition fadeInTransition;
- public MainScreen(GraphicsDevice graphicsDevice, Color transitionFromColor, ContentSystem assets) : base(true)
+ public MainScreen(GraphicsDevice graphicsDevice, ContentSystem assets) : base(true)
{
- fadeInTransition = new FadeInTransition(graphicsDevice, transitionFromColor);
+ FadeAwayTransition fadeAwayTransition = new FadeAwayTransition();
+ Transitions.Add(fadeAwayTransition);
+ graphicsDevice.Clear(Color.White);
background = assets.Get("backgrounds/mainBG");
- }
+ }
public override void Show()
{
- fadeInTransition.Init(ScreenSize);
base.Show();
}
public override void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(background, ScreenSize, Color.White);
- fadeInTransition.Draw(spriteBatch);
base.Draw(spriteBatch);
}
-
- public override void EnteringTransition(double delta, bool assetsLoaded, ref Color backgroundColor, RenderTarget2D previousScreenExitFrame)
- {
- fadeInTransition.Fade((float)delta);
- base.EnteringTransition(delta, assetsLoaded, ref backgroundColor, previousScreenExitFrame);
- }
}
}
diff --git a/RhythmBullet/Zer01HD/Game/Screens/Transitions/FadeInTransition.cs b/RhythmBullet/Zer01HD/Game/Screens/Transitions/FadeAwayTransition.cs
similarity index 54%
rename from RhythmBullet/Zer01HD/Game/Screens/Transitions/FadeInTransition.cs
rename to RhythmBullet/Zer01HD/Game/Screens/Transitions/FadeAwayTransition.cs
index e7c1776..676db8c 100644
--- a/RhythmBullet/Zer01HD/Game/Screens/Transitions/FadeInTransition.cs
+++ b/RhythmBullet/Zer01HD/Game/Screens/Transitions/FadeAwayTransition.cs
@@ -1,6 +1,7 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using RhythmBullet.Zer01HD.Utilities.UI;
+using RhythmBullet.Zer01HD.Utilities.UI.ScreenSystem;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -10,29 +11,22 @@ using System.Threading.Tasks;
namespace RhythmBullet.Zer01HD.Game.Screens.Transitions
{
- internal class FadeInTransition : IDisposable
+ internal class FadeAwayTransition : IDisposable, ITransition
{
- private const float RATE = 0.3f;
- public readonly Texture2D curtain;
+ private const float TIME_REQUIRED = 2f;
+ public Texture2D curtain;
public Rectangle curtainSize;
private Color color;
private float progR, progG, progB, progA;
- private float rR, rG, rB, rA;
- internal FadeInTransition(GraphicsDevice graphicsDevice, Color startColor)
- {
- curtain = new Texture2D(graphicsDevice, 1, 1);
- curtain.SetData(new[] { Color.White });
+ private float rR, rG, rB, rA;
- color = startColor;
- }
-
- internal void Init(Rectangle dimensions)
+ internal FadeAwayTransition()
{
- curtainSize = dimensions;
- rR = (0 - color.R) / RATE;
- rG = (0 - color.G) / RATE;
- rB = (0 - color.B) / RATE;
- rA = (0 - color.A) / RATE;
+ color = Color.White;
+ rR = (0 - 254) / TIME_REQUIRED;
+ rG = (0 - 254) / TIME_REQUIRED;
+ rB = (0 - 254) / TIME_REQUIRED;
+ rA = (0 - 254) / TIME_REQUIRED;
progA = color.A;
progR = color.R;
@@ -40,7 +34,12 @@ namespace RhythmBullet.Zer01HD.Game.Screens.Transitions
progB = color.B;
}
- internal bool Fade(float deltaf)
+ public void InitiateTransition(Rectangle dimensions)
+ {
+ curtainSize = dimensions;
+ }
+
+ private bool Fade(float deltaf)
{
if (progR > 0 || progG > 0 || progB > 0)
{
@@ -58,20 +57,32 @@ namespace RhythmBullet.Zer01HD.Game.Screens.Transitions
color.A = (byte)progA;
return false;
}
- return false;
+ return true;
}
- internal void Draw(SpriteBatch batch)
+ public void DrawTransition(SpriteBatch batch)
{
- if (curtain != null)
- {
- batch.Draw(curtain, curtainSize, color);
- }
+ batch.Draw(curtain, curtainSize, color);
}
public void Dispose()
{
curtain.Dispose();
}
+
+ public bool EnteringTransition(double delta, bool assetsLoaded)
+ {
+ return Fade((float)delta);
+ }
+
+ public bool ExitingTransition(double delta, bool assetsLoaded)
+ {
+ return Fade((float)delta);
+ }
+
+ public void UpdatePreviousScreenFrame(RenderTarget2D previousScreenFrame)
+ {
+ curtain = previousScreenFrame;
+ }
}
}
diff --git a/RhythmBullet/Zer01HD/Utilities/UI/Modular/Text.cs b/RhythmBullet/Zer01HD/Utilities/UI/Modular/Text.cs
index 2882865..527253d 100644
--- a/RhythmBullet/Zer01HD/Utilities/UI/Modular/Text.cs
+++ b/RhythmBullet/Zer01HD/Utilities/UI/Modular/Text.cs
@@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace RhythmBullet.Zer01HD.UI.Modular
{
- class Text : Module
+ public class Text : Module
{
private SpriteFont font;
private float scale;
diff --git a/RhythmBullet/Zer01HD/Utilities/UI/Screen.cs b/RhythmBullet/Zer01HD/Utilities/UI/Screen.cs
deleted file mode 100644
index 59a4058..0000000
--- a/RhythmBullet/Zer01HD/Utilities/UI/Screen.cs
+++ /dev/null
@@ -1,102 +0,0 @@
-using Microsoft.Xna.Framework;
-using Microsoft.Xna.Framework.Graphics;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace RhythmBullet.Zer01HD.Utilities.UI
-{
- public enum ScreenState { EnterTransition, ExitTransition, Normal }
-
- public class Screen
- {
- public bool UseRenderTargetForExitTransition;
- private GraphicsDevice GraphicsDevice;
- public Screen(bool useEnterTransition = false)
- {
- State = useEnterTransition ? ScreenState.EnterTransition : ScreenState.Normal;
- }
-
- public void Initiate(Rectangle screenSize, GraphicsDevice graphicsDevice)
- {
- Initiated = true;
- this.ScreenSize = screenSize;
- this.GraphicsDevice = graphicsDevice;
- RenderTarget = new RenderTarget2D(graphicsDevice, ScreenSize.Width, ScreenSize.Height);
- }
-
- public virtual void Update(GameTime gameTime)
- {
-
- }
-
- public virtual void Draw(SpriteBatch spriteBatch)
- {
-
- }
-
- public virtual void EnteringTransition(double delta, bool assetsLoaded, ref Color backgroundColor, RenderTarget2D previousScreenExitFrame)
- {
-
- }
-
- public virtual bool ExitingTransition(double delta, bool assetsLoaded, ref Color backgroundColor)
- {
- return true;
- }
-
- public virtual void Show()
- {
-
- }
-
- public virtual void Hide()
- {
-
- }
-
- public virtual void AssetLoadStateChange(bool state)
- {
-
- }
-
- public ScreenState State { get; private set; }
-
- public void DoneEnterTransition()
- {
- State = ScreenState.Normal;
- }
-
- public void StartExitTransition(bool UseRenderTargetForExitTransition = false)
- {
- this.UseRenderTargetForExitTransition = UseRenderTargetForExitTransition;
- State = ScreenState.ExitTransition;
- }
-
- public Screen NextScreen
- {
- get; protected set;
- }
-
- public Rectangle ScreenSize
- {
- get;
- protected set;
- //Remember to init in init func
- }
-
- public RenderTarget2D RenderTarget
- {
- get;
- private set;
- }
-
- public bool Initiated
- {
- get;
- private set;
- }
- }
-}
diff --git a/RhythmBullet/Zer01HD/Utilities/UI/ScreenSystem/ITransition.cs b/RhythmBullet/Zer01HD/Utilities/UI/ScreenSystem/ITransition.cs
new file mode 100644
index 0000000..2322b47
--- /dev/null
+++ b/RhythmBullet/Zer01HD/Utilities/UI/ScreenSystem/ITransition.cs
@@ -0,0 +1,48 @@
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace RhythmBullet.Zer01HD.Utilities.UI.ScreenSystem
+{
+ public interface ITransition
+ {
+ ///
+ /// Called once when the transition is needed.
+ /// The dimensions of the screen.
+ ///
+ void InitiateTransition(Rectangle dimensions);
+
+ ///
+ /// Called every frame if the state of the screen this transition is placed upon is in the enter transition phase.
+ ///
+ /// The time passed in seconds since the last frame.
+ /// Whether or not if all assets have been loaded by the .
+ /// The frame being rendered by the screen as it exits. This can be null.
+ /// If this returns true, then it is considered that this transition is complete.
+ bool EnteringTransition(double delta, bool assetsLoaded);
+
+ ///
+ /// Called every frame if the state of the screen this transition is placed upon is in the exit phase.
+ ///
+ /// The time passed in seconds since the last frame.
+ /// Whether or not if all assets have been loaded by the .
+ /// If this returns true, then it is considered that this transition is complete.
+ bool ExitingTransition(double delta, bool assetsLoaded);
+
+ ///
+ /// Called once every frame while transition is active. Meant to draw transition.
+ ///
+ ///
+ void DrawTransition(SpriteBatch spriteBatch);
+
+ ///
+ /// Updates if the previous screen uses a render target for exit transition.
+ ///
+ /// The frame of the previous screen.
+ void UpdatePreviousScreenFrame(RenderTarget2D previousScreenFrame);
+ }
+}
diff --git a/RhythmBullet/Zer01HD/Utilities/UI/LoadingScreen.cs b/RhythmBullet/Zer01HD/Utilities/UI/ScreenSystem/LoadingScreen.cs
similarity index 59%
rename from RhythmBullet/Zer01HD/Utilities/UI/LoadingScreen.cs
rename to RhythmBullet/Zer01HD/Utilities/UI/ScreenSystem/LoadingScreen.cs
index 12eb01e..bb7f1bc 100644
--- a/RhythmBullet/Zer01HD/Utilities/UI/LoadingScreen.cs
+++ b/RhythmBullet/Zer01HD/Utilities/UI/ScreenSystem/LoadingScreen.cs
@@ -1,16 +1,14 @@
-using Microsoft.Xna.Framework;
+
+using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
-using RhythmBullet.Zer01HD.Game.Screens;
-using RhythmBullet.Zer01HD.Utilities.UI;
using System;
-using System.Diagnostics;
-namespace RhythmBullet.Zer01HD.Game
+namespace RhythmBullet.Zer01HD.Utilities.UI.ScreenSystem
{
- class LoadingScreen : Screen
+ class LoadingScreen : Screen, ITransition
{
- private const float ENTER_RATE = 2f;
- private const float EXIT_RATE = 1f;
+ private const float ENTER_TIME = 2f;
+ private const float EXIT_TIME = 1f;
readonly Texture2D texture;
Color color;
Rectangle textureBounds;
@@ -23,26 +21,40 @@ namespace RhythmBullet.Zer01HD.Game
readonly bool rotate;
Vector2 origin;
- public LoadingScreen(Texture2D texture, float proportion, Rectangle dimensions, bool rotate = false) : base(true)
+ public LoadingScreen(Texture2D texture, float proportion, bool rotate = false) : base(true)
{
color = Color.White;
this.texture = texture;
this.proportion = proportion;
this.rotate = rotate;
- textureBounds.Width = (int)(dimensions.Height * proportion);
- textureBounds.Height = (int)(dimensions.Height * proportion);
- textureBounds.X = (dimensions.Width) / 2;
- textureBounds.Y = (dimensions.Height) / 2;
+ Transitions.Add(this);
+ }
+
+ void DoRotate(float deltaf)
+ {
+ rotation += (2f / 3f) * (float)Math.PI * deltaf;
+ if (rotation >= 2 * Math.PI)
+ {
+ rotation = 0;
+ }
+ }
+
+ public void DrawTransition(SpriteBatch spriteBatch)
+ {
+ spriteBatch.Draw(texture, textureBounds, null, Color.White, rotation, origin, SpriteEffects.None, 0f);
+ }
+
+ public void InitiateTransition(Rectangle dimensions)
+ {
+ textureBounds.Width = (int)(ScreenSize.Height * proportion);
+ textureBounds.Height = (int)(ScreenSize.Height * proportion);
+ textureBounds.X = (ScreenSize.Width) / 2;
+ textureBounds.Y = (ScreenSize.Height) / 2;
origin.X = texture.Width / 2;
origin.Y = texture.Height / 2;
}
- public override void Update(GameTime gameTime)
- {
- base.Update(gameTime);
- }
-
- public override void EnteringTransition(double delta, bool assetsLoaded, ref Color BGColor, RenderTarget2D previousScreenExitFrame)
+ public bool EnteringTransition(double delta, bool assetsLoaded)
{
float deltaf = (float)delta;
if (rotate)
@@ -55,9 +67,9 @@ namespace RhythmBullet.Zer01HD.Game
{
if (!recorded)
{
- rR = (Color.White.R - BGColor.R) / ENTER_RATE;
- rG = (Color.White.G - BGColor.G) / ENTER_RATE;
- rB = (Color.White.B - BGColor.B) / ENTER_RATE;
+ rR = (Color.White.R - BackgroundColor.R) / ENTER_TIME;
+ rG = (Color.White.G - BackgroundColor.G) / ENTER_TIME;
+ rB = (Color.White.B - BackgroundColor.B) / ENTER_TIME;
recorded = true;
}
progR += rR * deltaf;
@@ -66,19 +78,20 @@ namespace RhythmBullet.Zer01HD.Game
progG = Math.Min(progG, 254);
progB += rB * deltaf;
progB = Math.Min(progB, 254);
- BGColor.R = (byte)progR;
- BGColor.G = (byte)progG;
- BGColor.B = (byte)progB;
+ BackgroundColor.R = (byte)progR;
+ BackgroundColor.G = (byte)progG;
+ BackgroundColor.B = (byte)progB;
}
else
{
- DoneEnterTransition();
StartExitTransition(true);
+ return true;
}
}
+ return false;
}
- public override bool ExitingTransition(double delta, bool assetsLoaded, ref Color backgroundColor)
+ public bool ExitingTransition(double delta, bool assetsLoaded)
{
float deltaf = (float)delta;
if (rotate)
@@ -87,7 +100,7 @@ namespace RhythmBullet.Zer01HD.Game
}
if (progC > 0)
{
- float rate = deltaf * 255 / EXIT_RATE;
+ float rate = deltaf * 255 / EXIT_TIME;
progC -= rate;
progC = Math.Max(progC, 0);
color.R = (byte)progC;
@@ -102,20 +115,5 @@ namespace RhythmBullet.Zer01HD.Game
return false;
}
- void DoRotate(float deltaf)
- {
- rotation += (2f / 3f) * (float)Math.PI * deltaf;
- if (rotation >= 2 * Math.PI)
- {
- rotation = 0;
- }
- }
-
- public override void Draw(SpriteBatch spriteBatch)
- {
- spriteBatch.Draw(texture, textureBounds, null, color, rotation, origin, SpriteEffects.None, 0f);
- base.Draw(spriteBatch);
- }
-
}
}
diff --git a/RhythmBullet/Zer01HD/Utilities/UI/ScreenSystem/Screen.cs b/RhythmBullet/Zer01HD/Utilities/UI/ScreenSystem/Screen.cs
new file mode 100644
index 0000000..e4c2db7
--- /dev/null
+++ b/RhythmBullet/Zer01HD/Utilities/UI/ScreenSystem/Screen.cs
@@ -0,0 +1,142 @@
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace RhythmBullet.Zer01HD.Utilities.UI.ScreenSystem
+{
+ public enum ScreenState { EnterTransition, ExitTransition, Normal }
+
+ public class Screen
+ {
+ public List Transitions;
+ public bool UseRenderTargetForExitTransition;
+ public Color BackgroundColor;
+ public Screen(bool useEnterTransition = false)
+ {
+ State = useEnterTransition ? ScreenState.EnterTransition : ScreenState.Normal;
+ Transitions = new List();
+ }
+
+ public void Initiate(Rectangle screenSize)
+ {
+ Initiated = true;
+ this.ScreenSize = screenSize;
+ foreach (ITransition transition in Transitions)
+ {
+ transition.InitiateTransition(screenSize);
+ }
+ }
+
+ public virtual void Update(GameTime gameTime)
+ {
+
+ }
+
+ public virtual void Draw(SpriteBatch spriteBatch)
+ {
+ foreach (ITransition transition in Transitions)
+ {
+ transition.DrawTransition(spriteBatch);
+ }
+ }
+
+ ///
+ /// Updates the transition.
+ ///
+ /// Time passed since last frame in seconds.
+ /// If waiting on assets.
+ /// The previous screen's frame. May be null.
+ /// Only returns true if exit transition is complete. Returns false otherwise.
+ public bool UpdateTransition(double delta, bool assetsLoaded)
+ {
+ switch (State)
+ {
+ case ScreenState.EnterTransition:
+ EnteringTransition(delta, assetsLoaded);
+ break;
+ case ScreenState.ExitTransition:
+ return ExitingTransition(delta, assetsLoaded);
+ }
+
+ return false;
+ }
+
+ private void EnteringTransition(double delta, bool assetsLoaded)
+ {
+ bool complete = true;
+ for (int transitionID = 0; transitionID < Transitions.Count; transitionID++)
+ {
+ ITransition transition = Transitions[transitionID];
+ if (!transition.EnteringTransition(delta, assetsLoaded))
+ {
+ complete = false;
+ }
+ }
+ if (complete && State != ScreenState.ExitTransition)
+ {
+ State = ScreenState.Normal;
+ }
+ }
+
+ private bool ExitingTransition(double delta, bool assetsLoaded)
+ {
+ bool complete = true;
+ foreach (ITransition transition in Transitions)
+ {
+ if (!transition.ExitingTransition(delta, assetsLoaded))
+ {
+ complete = false;
+ }
+
+ }
+ return complete;
+ }
+
+ public virtual void Show()
+ {
+
+ }
+
+ public virtual void Hide()
+ {
+
+ }
+
+ public virtual void AssetLoadStateChange(bool state)
+ {
+
+ }
+
+ public ScreenState State { get; private set; }
+
+ public void StartExitTransition(bool UseRenderTargetForExitTransition = false)
+ {
+ this.UseRenderTargetForExitTransition = UseRenderTargetForExitTransition;
+ State = ScreenState.ExitTransition;
+ }
+
+ public virtual void UpdatePreviousScreenFrame(RenderTarget2D previousScreenFrame)
+ {
+ foreach (ITransition transition in Transitions)
+ {
+ transition.UpdatePreviousScreenFrame(previousScreenFrame);
+ }
+ }
+
+ public Screen NextScreen
+ { get; protected set; }
+
+ public Rectangle ScreenSize
+ { get; protected set; }
+
+ public bool Initiated
+ {
+ get;
+ private set;
+ }
+ }
+}