Added better system for beginning sprite batches for easier consistency.
This commit is contained in:
parent
ed11d31100
commit
c59252dbbf
@ -1,5 +1,6 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using RecrownedAthenaeum.Camera;
|
using RecrownedAthenaeum.Camera;
|
||||||
|
using RecrownedAthenaeum.ScreenSystem;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace RecrownedAthenaeum
|
namespace RecrownedAthenaeum
|
||||||
@ -9,19 +10,23 @@ namespace RecrownedAthenaeum
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class Configuration
|
public static class Configuration
|
||||||
{
|
{
|
||||||
|
|
||||||
private static GraphicsDeviceManager graphicsDeviceManager;
|
private static GraphicsDeviceManager graphicsDeviceManager;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The graphics device that will be used by default.
|
/// The graphics device that will be used by default.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static GraphicsDeviceManager GraphicsDeviceManager { set { graphicsDeviceManager = value; } get { if (graphicsDeviceManager == null) throw new InvalidOperationException("Graphics device manager property requested as substitute but configuration does not have one."); return graphicsDeviceManager; } }
|
public static GraphicsDeviceManager GraphicsDeviceManager { set { graphicsDeviceManager = value; } get { if (graphicsDeviceManager == null) throw new InvalidOperationException("Graphics device manager property requested as substitute but configuration does not have one."); return graphicsDeviceManager; } }
|
||||||
|
|
||||||
private static Camera2D camera2D;
|
|
||||||
|
|
||||||
|
private static Camera2D camera2D;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 2D camera to be used by default.
|
/// 2D camera to be used by default.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static Camera2D Camera2D { set { camera2D = value; } get { if (camera2D == null) throw new InvalidOperationException("2D camera property requested as substitute but configuration does not have one."); return camera2D; } }
|
public static Camera2D Camera2D { set { camera2D = value; } get { if (camera2D == null) throw new InvalidOperationException("2D camera property requested as substitute but configuration does not have one."); return camera2D; } }
|
||||||
|
|
||||||
|
private static BeginBatch beginBatchFunction;
|
||||||
|
/// <summary>
|
||||||
|
/// The begin sprite batch to use for custom begins and consistency.
|
||||||
|
/// </summary>
|
||||||
|
public static BeginBatch BeginBatchFunction { set { beginBatchFunction = value; } get { if (beginBatchFunction == null) throw new InvalidOperationException("No default begin batch has been set yet has been requested."); return beginBatchFunction; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,12 @@ namespace RecrownedAthenaeum.ScreenSystem
|
|||||||
/// <param name="screen">The screen to show after the loading screen.</param>
|
/// <param name="screen">The screen to show after the loading screen.</param>
|
||||||
public delegate void ShowFirstScreen(Screen screen);
|
public delegate void ShowFirstScreen(Screen screen);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Custom spritebatch begin call.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="spriteBatch"></param>
|
||||||
|
public delegate void BeginBatch(SpriteBatch spriteBatch);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A manager for screens. Helps with transitions and updating screens as well as resizes.
|
/// A manager for screens. Helps with transitions and updating screens as well as resizes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -23,6 +29,12 @@ namespace RecrownedAthenaeum.ScreenSystem
|
|||||||
/// Called when the first loading screen is done, and needs to show the landing screen.
|
/// Called when the first loading screen is done, and needs to show the landing screen.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event ShowFirstScreen ShowFirstScreenEvent;
|
public event ShowFirstScreen ShowFirstScreenEvent;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The function to call that begins the batch.
|
||||||
|
/// </summary>
|
||||||
|
public BeginBatch beginBatchFunc;
|
||||||
|
|
||||||
private GraphicsDeviceManager graphics;
|
private GraphicsDeviceManager graphics;
|
||||||
private Screen previousScreen;
|
private Screen previousScreen;
|
||||||
private RenderTarget2D previousScreenRenderTarget;
|
private RenderTarget2D previousScreenRenderTarget;
|
||||||
@ -65,13 +77,16 @@ namespace RecrownedAthenaeum.ScreenSystem
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="camera">The camera to be used to perform the correct translations and transformations. Will use default set in <see cref="Configuration"/> if left null.</param>
|
/// <param name="camera">The camera to be used to perform the correct translations and transformations. Will use default set in <see cref="Configuration"/> if left null.</param>
|
||||||
/// <param name="graphicsDeviceManager">The graphics device manager to be used. Will use default set in <see cref="Configuration"/> if left null.</param>
|
/// <param name="graphicsDeviceManager">The graphics device manager to be used. Will use default set in <see cref="Configuration"/> if left null.</param>
|
||||||
public ScreenManager(Camera2D camera = null, GraphicsDeviceManager graphicsDeviceManager = null)
|
/// <param name="beginBatchFunction">The function to call to begin a batch to be used generally. Will use the built-in one in screen manager if not provided.</param>
|
||||||
|
public ScreenManager(Camera2D camera = null, GraphicsDeviceManager graphicsDeviceManager = null, BeginBatch beginBatchFunction = null)
|
||||||
{
|
{
|
||||||
|
if (beginBatchFunction == null) beginBatchFunction = BasicBeginBatch;
|
||||||
if (camera == null) camera = Configuration.Camera2D;
|
if (camera == null) camera = Configuration.Camera2D;
|
||||||
if (graphicsDeviceManager == null) graphicsDeviceManager = Configuration.GraphicsDeviceManager;
|
if (graphicsDeviceManager == null) graphicsDeviceManager = Configuration.GraphicsDeviceManager;
|
||||||
|
|
||||||
graphics = graphicsDeviceManager ?? throw new ArgumentNullException("Graphics device manager argument cannot be null if setup's graphics device manager is also null.");
|
graphics = graphicsDeviceManager ?? throw new ArgumentNullException("Graphics device manager argument cannot be null if setup's graphics device manager is also null.");
|
||||||
this.camera = camera ?? throw new ArgumentNullException("2d camera argument cannot be null if setup's 2d camera is also null.");
|
this.camera = camera ?? throw new ArgumentNullException("2d camera argument cannot be null if setup's 2d camera is also null.");
|
||||||
|
beginBatchFunc = beginBatchFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -129,13 +144,13 @@ namespace RecrownedAthenaeum.ScreenSystem
|
|||||||
{
|
{
|
||||||
graphics.GraphicsDevice.SetRenderTarget(previousScreenRenderTarget);
|
graphics.GraphicsDevice.SetRenderTarget(previousScreenRenderTarget);
|
||||||
graphics.GraphicsDevice.Clear(previousScreen.BackgroundColor);
|
graphics.GraphicsDevice.Clear(previousScreen.BackgroundColor);
|
||||||
spriteBatch.Begin(effect: camera.BasicEffect);
|
beginBatchFunc(spriteBatch);
|
||||||
previousScreen.Draw(spriteBatch);
|
previousScreen.Draw(spriteBatch);
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
graphics.GraphicsDevice.SetRenderTarget(null);
|
graphics.GraphicsDevice.SetRenderTarget(null);
|
||||||
Screen.UpdatePreviousScreenFrame(previousScreenRenderTarget);
|
Screen.UpdatePreviousScreenFrame(previousScreenRenderTarget);
|
||||||
}
|
}
|
||||||
spriteBatch.Begin(effect: camera.BasicEffect);
|
beginBatchFunc(spriteBatch);
|
||||||
Screen.Draw(spriteBatch);
|
Screen.Draw(spriteBatch);
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
}
|
}
|
||||||
@ -199,5 +214,10 @@ namespace RecrownedAthenaeum.ScreenSystem
|
|||||||
{
|
{
|
||||||
Dispose(false);
|
Dispose(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void BasicBeginBatch(SpriteBatch spriteBatch)
|
||||||
|
{
|
||||||
|
spriteBatch.Begin(effect: camera.BasicEffect, blendState: BlendState.NonPremultiplied);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ using Microsoft.Xna.Framework;
|
|||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
using RecrownedAthenaeum.Camera;
|
using RecrownedAthenaeum.Camera;
|
||||||
|
using RecrownedAthenaeum.ScreenSystem;
|
||||||
|
|
||||||
namespace RecrownedAthenaeum.UI.Modular
|
namespace RecrownedAthenaeum.UI.Modular
|
||||||
{
|
{
|
||||||
@ -16,6 +17,7 @@ namespace RecrownedAthenaeum.UI.Modular
|
|||||||
List<UIModule> modules = new List<UIModule>();
|
List<UIModule> modules = new List<UIModule>();
|
||||||
Rectangle scissorBounds;
|
Rectangle scissorBounds;
|
||||||
RasterizerState scissorRasterizer;
|
RasterizerState scissorRasterizer;
|
||||||
|
BeginBatch beginBatch;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Camera used by the module for cropping.
|
/// Camera used by the module for cropping.
|
||||||
@ -27,9 +29,12 @@ namespace RecrownedAthenaeum.UI.Modular
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="crop">Whether or not to crop out of bounds. Default is false.</param>
|
/// <param name="crop">Whether or not to crop out of bounds. Default is false.</param>
|
||||||
/// <param name="camera">What camera to use for cropping. Default is null and will use <see cref="Configuration"/>'s camera if crop is enabled.</param>
|
/// <param name="camera">What camera to use for cropping. Default is null and will use <see cref="Configuration"/>'s camera if crop is enabled.</param>
|
||||||
public UIModuleGroup(bool crop = false, Camera2D camera = null)
|
/// <param name="beginBatchFunction">The function to be called that begins the batch.</param>
|
||||||
|
public UIModuleGroup(bool crop = false, Camera2D camera = null, BeginBatch beginBatchFunction = null)
|
||||||
{
|
{
|
||||||
|
if (beginBatchFunction == null) beginBatchFunction = Configuration.BeginBatchFunction;
|
||||||
if (crop && camera == null) camera = Configuration.Camera2D;
|
if (crop && camera == null) camera = Configuration.Camera2D;
|
||||||
|
this.beginBatch = beginBatchFunction;
|
||||||
this.camera = camera;
|
this.camera = camera;
|
||||||
if (crop)
|
if (crop)
|
||||||
{
|
{
|
||||||
@ -48,7 +53,7 @@ namespace RecrownedAthenaeum.UI.Modular
|
|||||||
if (scissorBounds != null)
|
if (scissorBounds != null)
|
||||||
{
|
{
|
||||||
batch.End();
|
batch.End();
|
||||||
batch.Begin(effect: camera?.BasicEffect);
|
beginBatch(batch);
|
||||||
scissorBounds.Width = situation.Width;
|
scissorBounds.Width = situation.Width;
|
||||||
scissorBounds.Height = situation.Height;
|
scissorBounds.Height = situation.Height;
|
||||||
scissorBounds.X = situation.X;
|
scissorBounds.X = situation.X;
|
||||||
@ -73,7 +78,7 @@ namespace RecrownedAthenaeum.UI.Modular
|
|||||||
{
|
{
|
||||||
batch.GraphicsDevice.ScissorRectangle = scissorBounds;
|
batch.GraphicsDevice.ScissorRectangle = scissorBounds;
|
||||||
batch.End();
|
batch.End();
|
||||||
batch.Begin(effect: camera?.BasicEffect);
|
beginBatch(batch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user