refactoring; removed configuration setup; added consistent sprite batch; got rid of sprite batch settings; implemented newer setup;

This commit is contained in:
2019-03-23 19:04:43 -05:00
parent e3535f5662
commit b045033b25
28 changed files with 342 additions and 329 deletions

View File

@@ -1,5 +1,6 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using RecrownedAthenaeum.Render;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -56,7 +57,7 @@ namespace RecrownedAthenaeum.SpecialTypes
/// <param name="color">Color to use.</param>
/// <param name="rotation">Rotation of texture drawn.</param>
/// <param name="origin">Origin used by rotation.</param>
public void Draw(string name, SpriteBatch batch, Rectangle destination, Color color = default(Color), float rotation = 0, Vector2 origin = new Vector2())
public void Draw(string name, ConsistentSpriteBatch batch, Rectangle destination, Color color = default(Color), float rotation = 0, Vector2 origin = new Vector2())
{
dictionaryOfRegions[name].Draw(batch, destination, color, rotation, origin);
}
@@ -65,11 +66,10 @@ namespace RecrownedAthenaeum.SpecialTypes
/// Creates or obtains a previously created texture of a region.
/// </summary>
/// <param name="name">Name of region.</param>
/// <param name="graphicsDevice">graphics device to be used. Default is null and will resort to using graphics device from <see cref="Configuration"/>'s graphics device manager.</param>
/// <param name="graphicsDevice">graphics device to be used to generate the texture.</param>
/// <returns>The texture from the region.</returns>
public Texture2D ObtainRegionAsTexture(string name, GraphicsDevice graphicsDevice = null)
public Texture2D ObtainRegionAsTexture(string name, GraphicsDevice graphicsDevice)
{
if (graphicsDevice == null) graphicsDevice = Configuration.GraphicsDeviceManager.GraphicsDevice;
return dictionaryOfRegions[name].AsTexture2D(graphicsDevice);
}
@@ -125,7 +125,7 @@ namespace RecrownedAthenaeum.SpecialTypes
/// <summary>
/// A region of a <see cref="TextureAtlas"/>.
/// </summary>
public class Region : IComparable<Region>, ISpecialDrawable, IDisposable
public class Region : ISpecialDrawable, IDisposable
{
/// <summary>
/// The name of the region. Mostly used to be refered to within the context of a <see cref="TextureAtlas"/>.
@@ -156,8 +156,8 @@ namespace RecrownedAthenaeum.SpecialTypes
{
this.atlasTexture = atlasTexture ?? throw new ArgumentNullException("Name parameters can be null.");
this.name = name ?? throw new ArgumentNullException("Name parameters can be null.");
this.sourceRectangle = sourceRegion;
this.ninepatch = ninePatch;
sourceRectangle = sourceRegion;
ninepatch = ninePatch;
}
/// <summary>
@@ -168,7 +168,7 @@ namespace RecrownedAthenaeum.SpecialTypes
/// <param name="color">The color to use.</param>
/// <param name="rotation">Rotation of the final drawing. Ignored if is a 9patch.</param>
/// <param name="origin">The origin of the drawing. Ignored if is a 9patch.</param>
public void Draw(SpriteBatch batch, Rectangle destination, Color color, float rotation = 0, Vector2 origin = default(Vector2))
public void Draw(ConsistentSpriteBatch batch, Rectangle destination, Color color, float rotation = 0, Vector2 origin = default(Vector2))
{
if (Disposed) throw new ObjectDisposedException(GetType().Name);
@@ -185,16 +185,15 @@ namespace RecrownedAthenaeum.SpecialTypes
/// <summary>
/// Create or obtains a previously created texture of this region.
/// </summary>
/// <param name="graphicsDevice">The graphics device to use to create the texture. Will use graphics device from <see cref="Configuration"/>'s graphics device manager if left to null.</param>
/// <param name="graphicsDevice">The graphics device to use to create the texture.</param>
/// <returns>The texture of the region.</returns>
public Texture2D AsTexture2D(GraphicsDevice graphicsDevice = null)
public Texture2D AsTexture2D(GraphicsDevice graphicsDevice)
{
if (Disposed) throw new ObjectDisposedException(GetType().Name);
if (regionTexture == null)
{
Color[] data = new Color[sourceRectangle.Width * sourceRectangle.Height];
if (graphicsDevice == null) graphicsDevice = Configuration.GraphicsDeviceManager.GraphicsDevice;
regionTexture = new Texture2D(graphicsDevice, sourceRectangle.Width, sourceRectangle.Height);
atlasTexture.GetData(0, sourceRectangle, data, 0, sourceRectangle.Width * sourceRectangle.Height);
regionTexture.SetData(data);
@@ -202,16 +201,6 @@ namespace RecrownedAthenaeum.SpecialTypes
return regionTexture;
}
/// <summary>
/// Compares this region to another in terms of name.
/// </summary>
/// <param name="other">The other region to compare to in terms of name.</param>
/// <returns>Less than one if precedes, greater than one if after, 0 if same.</returns>
public int CompareTo(Region other)
{
return name.CompareTo(other);
}
/// <summary>
/// Call this to dispose.
/// </summary>