Added better system for beginning sprite batches for easier consistency.

This commit is contained in:
2019-03-09 02:03:05 -06:00
parent ed11d31100
commit c59252dbbf
3 changed files with 39 additions and 9 deletions

View File

@@ -4,6 +4,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using RecrownedAthenaeum.Camera;
using RecrownedAthenaeum.ScreenSystem;
namespace RecrownedAthenaeum.UI.Modular
{
@@ -16,6 +17,7 @@ namespace RecrownedAthenaeum.UI.Modular
List<UIModule> modules = new List<UIModule>();
Rectangle scissorBounds;
RasterizerState scissorRasterizer;
BeginBatch beginBatch;
/// <summary>
/// Camera used by the module for cropping.
@@ -27,9 +29,12 @@ namespace RecrownedAthenaeum.UI.Modular
/// </summary>
/// <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>
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;
this.beginBatch = beginBatchFunction;
this.camera = camera;
if (crop)
{
@@ -48,7 +53,7 @@ namespace RecrownedAthenaeum.UI.Modular
if (scissorBounds != null)
{
batch.End();
batch.Begin(effect: camera?.BasicEffect);
beginBatch(batch);
scissorBounds.Width = situation.Width;
scissorBounds.Height = situation.Height;
scissorBounds.X = situation.X;
@@ -73,7 +78,7 @@ namespace RecrownedAthenaeum.UI.Modular
{
batch.GraphicsDevice.ScissorRectangle = scissorBounds;
batch.End();
batch.Begin(effect: camera?.BasicEffect);
beginBatch(batch);
}
}