Added sprite batch settings to maintain sprite batch begin settings and keep consistency and control over settings. Ninepatch uses this.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using RecrownedAthenaeum.Camera;
|
||||
using RecrownedAthenaeum.Render;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
@@ -12,12 +13,6 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
/// <param name="screen">The screen to show after the loading screen.</param>
|
||||
public delegate void ShowFirstScreen(Screen screen);
|
||||
|
||||
/// <summary>
|
||||
/// Custom spritebatch begin call.
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch"></param>
|
||||
public delegate void BeginBatch(SpriteBatch spriteBatch);
|
||||
|
||||
/// <summary>
|
||||
/// A manager for screens. Helps with transitions and updating screens as well as resizes.
|
||||
/// </summary>
|
||||
@@ -31,9 +26,9 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
public event ShowFirstScreen ShowFirstScreenEvent;
|
||||
|
||||
/// <summary>
|
||||
/// The function to call that begins the batch.
|
||||
/// The settings this manager will use to begin a sprite batch.
|
||||
/// </summary>
|
||||
public BeginBatch beginBatchFunc;
|
||||
public SpriteBatchSettings batchSettings;
|
||||
|
||||
private GraphicsDeviceManager graphics;
|
||||
private Screen previousScreen;
|
||||
@@ -77,16 +72,24 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
/// </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="graphicsDeviceManager">The graphics device manager to be used. Will use default set in <see cref="Configuration"/> if left null.</param>
|
||||
/// <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)
|
||||
/// <param name="spriteBatchSettings">The settings to begin spritebatch with. Will use the built-in one in screen manager if not provided.</param>
|
||||
public ScreenManager(Camera2D camera = null, GraphicsDeviceManager graphicsDeviceManager = null, SpriteBatchSettings? spriteBatchSettings = null)
|
||||
{
|
||||
if (beginBatchFunction == null) beginBatchFunction = BasicBeginBatch;
|
||||
|
||||
if (camera == null) camera = Configuration.Camera2D;
|
||||
if (!spriteBatchSettings.HasValue)
|
||||
{
|
||||
SpriteBatchSettings basicSettings = new SpriteBatchSettings();
|
||||
basicSettings.effect = camera.BasicEffect;
|
||||
basicSettings.blendState = BlendState.Additive;
|
||||
basicSettings.samplerState = null;
|
||||
spriteBatchSettings = basicSettings;
|
||||
}
|
||||
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.");
|
||||
this.camera = camera ?? throw new ArgumentNullException("2d camera argument cannot be null if setup's 2d camera is also null.");
|
||||
beginBatchFunc = beginBatchFunction;
|
||||
batchSettings = spriteBatchSettings.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -144,13 +147,13 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
{
|
||||
graphics.GraphicsDevice.SetRenderTarget(previousScreenRenderTarget);
|
||||
graphics.GraphicsDevice.Clear(previousScreen.BackgroundColor);
|
||||
beginBatchFunc(spriteBatch);
|
||||
batchSettings.BeginSpriteBatch(spriteBatch);
|
||||
previousScreen.Draw(spriteBatch);
|
||||
spriteBatch.End();
|
||||
graphics.GraphicsDevice.SetRenderTarget(null);
|
||||
Screen.UpdatePreviousScreenFrame(previousScreenRenderTarget);
|
||||
}
|
||||
beginBatchFunc(spriteBatch);
|
||||
batchSettings.BeginSpriteBatch(spriteBatch);
|
||||
Screen.Draw(spriteBatch);
|
||||
spriteBatch.End();
|
||||
}
|
||||
@@ -169,7 +172,7 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
previousScreenRenderTarget.Dispose();
|
||||
previousScreenRenderTarget = null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Notifies all screen that assets have completed being loaded after a resize.
|
||||
/// </summary>
|
||||
@@ -214,10 +217,5 @@ namespace RecrownedAthenaeum.ScreenSystem
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
private void BasicBeginBatch(SpriteBatch spriteBatch)
|
||||
{
|
||||
spriteBatch.Begin(effect: camera.BasicEffect, blendState: BlendState.NonPremultiplied);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user