refactoring; removed configuration setup; added consistent sprite batch; got rid of sprite batch settings; implemented newer setup;
This commit is contained in:
parent
e3535f5662
commit
b045033b25
@ -1,32 +0,0 @@
|
|||||||
using Microsoft.Xna.Framework;
|
|
||||||
using RecrownedAthenaeum.Camera;
|
|
||||||
using RecrownedAthenaeum.Render;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace RecrownedAthenaeum
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// All variables here should be for RecrownedAthenaeum to use when needed and thus eliminates unessecary passing.
|
|
||||||
/// </summary>
|
|
||||||
public static class Configuration
|
|
||||||
{
|
|
||||||
private static GraphicsDeviceManager graphicsDeviceManager;
|
|
||||||
/// <summary>
|
|
||||||
/// The graphics device that will be used by default.
|
|
||||||
/// </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; } }
|
|
||||||
|
|
||||||
|
|
||||||
private static Camera2D camera2D;
|
|
||||||
/// <summary>
|
|
||||||
/// 2D camera to be used by default.
|
|
||||||
/// </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; } }
|
|
||||||
|
|
||||||
private static SpriteBatchSettings? spriteBatchSettings;
|
|
||||||
/// <summary>
|
|
||||||
/// The begin sprite batch to use for custom begins and consistency.
|
|
||||||
/// </summary>
|
|
||||||
public static SpriteBatchSettings? SpriteBatchSettings { set { spriteBatchSettings = value.Value; } get { if (!spriteBatchSettings.HasValue) throw new InvalidOperationException("No default begin batch has been set yet has been requested."); return spriteBatchSettings; } }
|
|
||||||
}
|
|
||||||
}
|
|
@ -51,14 +51,13 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Render\BasicCamera.cs" />
|
||||||
|
<Compile Include="Render\ConsistentSpriteBatch.cs" />
|
||||||
<Compile Include="Render\ScissorBox.cs" />
|
<Compile Include="Render\ScissorBox.cs" />
|
||||||
<Compile Include="Render\SpriteBatchSettings.cs" />
|
|
||||||
<Compile Include="Render\Camera3D.cs" />
|
|
||||||
<Compile Include="Render\Camera2D.cs" />
|
<Compile Include="Render\Camera2D.cs" />
|
||||||
<Compile Include="ContentSystem\ContentData.cs" />
|
<Compile Include="ContentSystem\ContentData.cs" />
|
||||||
<Compile Include="ContentSystem\ContentManagerController.cs" />
|
<Compile Include="ContentSystem\ContentManagerController.cs" />
|
||||||
<Compile Include="ContentSystem\IContentPathResolver.cs" />
|
<Compile Include="ContentSystem\IContentPathResolver.cs" />
|
||||||
<Compile Include="Configuration.cs" />
|
|
||||||
<Compile Include="ContentSystem\NormalContentResolver.cs" />
|
<Compile Include="ContentSystem\NormalContentResolver.cs" />
|
||||||
<Compile Include="SpecialTypes\ISpecialDrawable.cs" />
|
<Compile Include="SpecialTypes\ISpecialDrawable.cs" />
|
||||||
<Compile Include="SpecialTypes\NinePatch.cs" />
|
<Compile Include="SpecialTypes\NinePatch.cs" />
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace RecrownedAthenaeum.Camera
|
namespace RecrownedAthenaeum.Camera
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A generic 3D camera.
|
/// A generic camera. Functions in 3D.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Camera3D
|
public class BasicCamera
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The scale for the world.
|
/// The scale for the world.
|
||||||
@ -24,7 +25,7 @@ namespace RecrownedAthenaeum.Camera
|
|||||||
public Vector3 lookAt;
|
public Vector3 lookAt;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The direction up is for the 3D camera.
|
/// The direction up is for the camera.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Vector3 upDirection;
|
public Vector3 upDirection;
|
||||||
|
|
||||||
@ -44,32 +45,22 @@ namespace RecrownedAthenaeum.Camera
|
|||||||
public Matrix projectionMatrix;
|
public Matrix projectionMatrix;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The graphics device used
|
/// A basic effect that will be updated with the correct matrice information everytime <see cref="Apply"/> is called. Can be null and thus will not be used.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected GraphicsDevice graphicsDevice;
|
public BasicEffect basicEffect;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The basic effect that contains the transformations.
|
|
||||||
/// </summary>
|
|
||||||
public BasicEffect BasicEffect { get; protected set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs 3D camera with an orthographic projection matrix with dimensions of graphics devices viewport. All changes to matrices should have apply called after changes.
|
/// Constructs 3D camera with an orthographic projection matrix with dimensions of graphics devices viewport. All changes to matrices should have apply called after changes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="graphicsDevice">The graphics device to use. Will use graphics device from <see cref="Configuration"/>'s graphics device manager if this is null which it is by default.</param>
|
/// <param name="basicEffect">A basic effect that will be updated with the correct matrice information everytime <see cref="Apply"/> is called. Can be null and thus will not be used.</param>
|
||||||
public Camera3D(GraphicsDevice graphicsDevice = null)
|
public BasicCamera(BasicEffect basicEffect = null)
|
||||||
{
|
{
|
||||||
graphicsDevice = graphicsDevice ?? (Configuration.GraphicsDeviceManager.GraphicsDevice);
|
|
||||||
this.graphicsDevice = graphicsDevice;
|
|
||||||
worldMatrix = Matrix.Identity;
|
worldMatrix = Matrix.Identity;
|
||||||
lookAt = Vector3.Forward;
|
lookAt = Vector3.Forward;
|
||||||
upDirection = Vector3.Up;
|
upDirection = Vector3.Up;
|
||||||
|
|
||||||
projectionMatrix = Matrix.Identity;
|
projectionMatrix = Matrix.Identity;
|
||||||
|
this.basicEffect = basicEffect;
|
||||||
BasicEffect = new BasicEffect(graphicsDevice);
|
|
||||||
BasicEffect.TextureEnabled = true;
|
|
||||||
BasicEffect.VertexColorEnabled = true;
|
|
||||||
Apply();
|
Apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,9 +72,12 @@ namespace RecrownedAthenaeum.Camera
|
|||||||
ViewMatrix = Matrix.CreateLookAt(position, lookAt, upDirection);
|
ViewMatrix = Matrix.CreateLookAt(position, lookAt, upDirection);
|
||||||
worldMatrix *= Matrix.CreateScale(worldScale);
|
worldMatrix *= Matrix.CreateScale(worldScale);
|
||||||
|
|
||||||
BasicEffect.World = worldMatrix;
|
if (basicEffect != null)
|
||||||
BasicEffect.View = ViewMatrix;
|
{
|
||||||
BasicEffect.Projection = projectionMatrix;
|
basicEffect.World = worldMatrix;
|
||||||
|
basicEffect.Projection = projectionMatrix;
|
||||||
|
basicEffect.View = ViewMatrix;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
@ -5,10 +5,20 @@ using System;
|
|||||||
namespace RecrownedAthenaeum.Camera
|
namespace RecrownedAthenaeum.Camera
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A virtual 2D camera that wraps the normal <see cref="Camera3D"/>. Default projection is orthographic.
|
/// A virtual 2D camera that wraps the normal <see cref="BasicCamera"/>. Default projection is orthographic.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Camera2D : Camera3D
|
public class Camera2D : BasicCamera
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The width of the view of the camera.
|
||||||
|
/// </summary>
|
||||||
|
public int viewWidth;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The height of the view of the camera.
|
||||||
|
/// </summary>
|
||||||
|
public int viewHeight;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The 2D position.
|
/// The 2D position.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -17,18 +27,21 @@ namespace RecrownedAthenaeum.Camera
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Places camera in the center given the corner position.
|
/// Places camera in the center given the corner position.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Vector2 CenterPosition { set { position.X = value.X + graphicsDevice.Viewport.Width / 2f; position.Y = value.Y + graphicsDevice.Viewport.Height / 2f; } }
|
public Vector2 ConrnerPosition { set { position.X = value.X + viewWidth / 2f; position.Y = value.Y + viewHeight / 2f; } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A 2D camera from the generic <see cref="Camera3D"/>.
|
/// A 2D camera from the generic <see cref="BasicCamera"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="graphicsDevice">The graphics device to use if not using the one in <see cref="Configuration"/>.</param>
|
/// <param name="height">Width of camera view.</param>
|
||||||
public Camera2D(GraphicsDevice graphicsDevice = null) : base(graphicsDevice)
|
/// <param name="width">Height of camera view.</param>
|
||||||
|
/// <param name="basicEffect">A basic effect that will be updated with the correct matrice information everytime <see cref="Apply"/> is called. Can be null and thus will not be used.</param>
|
||||||
|
public Camera2D(int width, int height, BasicEffect basicEffect = null) : base(basicEffect)
|
||||||
{
|
{
|
||||||
projectionMatrix = Matrix.CreateOrthographic(this.graphicsDevice.Viewport.Width, this.graphicsDevice.Viewport.Height, 0, 1);
|
this.viewWidth = width;
|
||||||
CenterPosition = new Vector2(0, 0);
|
this.viewHeight = height;
|
||||||
upDirection = Vector3.Down;
|
upDirection = Vector3.Down;
|
||||||
Apply();
|
Apply();
|
||||||
|
ConrnerPosition = new Vector2(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -37,6 +50,7 @@ namespace RecrownedAthenaeum.Camera
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override void Apply()
|
public override void Apply()
|
||||||
{
|
{
|
||||||
|
projectionMatrix = Matrix.CreateOrthographic(viewWidth, viewHeight, 0, 1);
|
||||||
position.Z = 0;
|
position.Z = 0;
|
||||||
lookAt = new Vector3(Position, 1f);
|
lookAt = new Vector3(Position, 1f);
|
||||||
base.Apply();
|
base.Apply();
|
||||||
|
89
RecrownedAthenaeum/Render/ConsistentSpriteBatch.cs
Normal file
89
RecrownedAthenaeum/Render/ConsistentSpriteBatch.cs
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
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 RecrownedAthenaeum.Render
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A <see cref="SpriteBatch"/> that keeps it's settings through begin and end unless manually changed either by the <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> or through changing the fields. Note that changing the fields while the batch has begun will not take effect until the next time the batch is started.
|
||||||
|
/// </summary>
|
||||||
|
public class ConsistentSpriteBatch : SpriteBatch
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// How to blend the colors. Uses <see cref="SpriteBatch"/>'s default if not set before or during <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> call.
|
||||||
|
/// Changes will only take effect on <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> call.
|
||||||
|
/// </summary>
|
||||||
|
public BlendState BlendState;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The state of sampler to use for the spritebatch. Uses <see cref="SpriteBatch"/>'s default if not set before or during <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> call.
|
||||||
|
/// Changes will only take effect on <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> call.
|
||||||
|
/// </summary>
|
||||||
|
public SamplerState SamplerState;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The state of the depth-stencil buffer. Uses <see cref="SpriteBatch"/>'s defaultdefault if not set before or during <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> call.
|
||||||
|
/// Changes will only take effect on <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> call.
|
||||||
|
/// </summary>
|
||||||
|
public DepthStencilState DepthStencilState;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The state of rasterizer to use. Uses <see cref="SpriteBatch"/>'s default if not set before or during <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> call.
|
||||||
|
/// Changes will only take effect on <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> call.
|
||||||
|
/// </summary>
|
||||||
|
public RasterizerState RasterizerState;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An effect to apply to the batch. Uses <see cref="SpriteBatch"/>'s default if not set before or during <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> call.
|
||||||
|
/// Changes will only take effect on <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> call.
|
||||||
|
/// </summary>
|
||||||
|
public Effect Effect;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A matrix to be applied to transform the sprites geometry. An identity matrix is used if not provided before or during <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> call.
|
||||||
|
/// Changes will only take effect on <see cref="Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> call.
|
||||||
|
/// </summary>
|
||||||
|
public Matrix? TransformMatrix;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a consistent sprite batch with default values.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="graphicsDevice">The graphics device to use to create a <see cref="SpriteBatch"/>.</param>
|
||||||
|
public ConsistentSpriteBatch(GraphicsDevice graphicsDevice) : base(graphicsDevice)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Begins the consistent sprite batch.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sortMode">Defines the spritebatch's method of sorting the items in each batch. Uses <see cref="SpriteBatch"/>'s default.</param>
|
||||||
|
/// <param name="blendState">How to blend the colors. Uses <see cref="SpriteBatch"/>'s default if not set and field is also not set.</param>
|
||||||
|
/// <param name="samplerState">The state of sampler to use for the spritebatch. Uses <see cref="SpriteBatch"/>'s default if not set and field is also not set.</param>
|
||||||
|
/// <param name="depthStencilState">What type of rasterization to use. Uses <see cref="SpriteBatch"/>'s default if not set and field is also not set.</param>
|
||||||
|
/// <param name="rasterizerState">What type of rasterization to use. Uses <see cref="SpriteBatch"/>'s default if not set and field is also not set.</param>
|
||||||
|
/// <param name="effect">An effect to apply to the batch. Uses <see cref="SpriteBatch"/>'s default if not set and field is also not set.</param>
|
||||||
|
/// <param name="transformMatrix">A matrix to be applied to transform the sprites geometry. An identity is used if not provided.</param>
|
||||||
|
public new void Begin(SpriteSortMode sortMode = SpriteSortMode.Deferred, BlendState blendState = null, SamplerState samplerState = null, DepthStencilState depthStencilState = null, RasterizerState rasterizerState = null, Effect effect = null, Matrix? transformMatrix = null)
|
||||||
|
{
|
||||||
|
if (blendState != null) this.BlendState = blendState;
|
||||||
|
if (samplerState != null) this.SamplerState = samplerState;
|
||||||
|
if (depthStencilState != null) this.DepthStencilState = depthStencilState;
|
||||||
|
if (rasterizerState != null) this.RasterizerState = rasterizerState;
|
||||||
|
if (effect != null) this.Effect = effect;
|
||||||
|
if (transformMatrix != null) this.TransformMatrix = transformMatrix;
|
||||||
|
|
||||||
|
base.Begin(
|
||||||
|
sortMode: sortMode,
|
||||||
|
blendState: blendState,
|
||||||
|
samplerState: samplerState,
|
||||||
|
depthStencilState: depthStencilState,
|
||||||
|
rasterizerState: rasterizerState,
|
||||||
|
effect: effect,
|
||||||
|
transformMatrix: transformMatrix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -12,7 +12,7 @@ namespace RecrownedAthenaeum.Render
|
|||||||
{
|
{
|
||||||
VertexPositionColor[] vertices;
|
VertexPositionColor[] vertices;
|
||||||
int bufferPosition;
|
int bufferPosition;
|
||||||
BasicEffect basicEffect;
|
Effect effect;
|
||||||
PrimitiveType primitiveType;
|
PrimitiveType primitiveType;
|
||||||
private int verticesPerPrimitive;
|
private int verticesPerPrimitive;
|
||||||
|
|
||||||
@ -24,28 +24,26 @@ namespace RecrownedAthenaeum.Render
|
|||||||
GraphicsDevice graphicsDevice;
|
GraphicsDevice graphicsDevice;
|
||||||
bool began;
|
bool began;
|
||||||
bool disposed;
|
bool disposed;
|
||||||
Camera3D camera;
|
|
||||||
|
|
||||||
|
BasicEffect basicEffect;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a batch used to draw primitives.
|
/// Creates a batch used to draw primitives.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="camera">The current camera being used. Will use default set in <see cref="Configuration"/> if left null.</param>
|
/// <param name="graphicsDevice">The graphics device used to draw the primitives.</param>
|
||||||
/// <param name="graphicsDevice">The graphics device used to draw the primitives. Will be using <see cref="Configuration"/>'s graphics device from graphics device manager if null. Default is null.</param>
|
|
||||||
/// <param name="verticesPerBatch">The amount of vertices every batch can hold before flushing. Default is 450. Should be changed to be the most optimal number if possible to prevent unnecessary resizing. Especially if using strip primitive types.</param>
|
/// <param name="verticesPerBatch">The amount of vertices every batch can hold before flushing. Default is 450. Should be changed to be the most optimal number if possible to prevent unnecessary resizing. Especially if using strip primitive types.</param>
|
||||||
public PrimitiveBatch(Camera2D camera = null, GraphicsDevice graphicsDevice = null, int verticesPerBatch = 500)
|
public PrimitiveBatch(GraphicsDevice graphicsDevice, int verticesPerBatch = 500)
|
||||||
{
|
{
|
||||||
this.graphicsDevice = graphicsDevice ?? (Configuration.GraphicsDeviceManager.GraphicsDevice);
|
|
||||||
this.camera = camera ?? (Configuration.Camera2D);
|
|
||||||
basicEffect = new BasicEffect(this.graphicsDevice);
|
|
||||||
basicEffect.VertexColorEnabled = true;
|
|
||||||
vertices = new VertexPositionColor[verticesPerBatch + 1];
|
vertices = new VertexPositionColor[verticesPerBatch + 1];
|
||||||
|
this.graphicsDevice = graphicsDevice;
|
||||||
|
basicEffect = new BasicEffect(graphicsDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Starts the batch. Batch cannot be started twice.
|
/// Starts the batch. Batch cannot be started twice.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="primitiveType">The type of primitive this batch would be drawing.</param>
|
/// <param name="primitiveType">The type of primitive this batch would be drawing.</param>
|
||||||
public void Begin(PrimitiveType primitiveType)
|
/// <param name="effect">Effect to use to render the primitives. Default will use a <see cref="BasicEffect"/>.</param>
|
||||||
|
public void Begin(PrimitiveType primitiveType, Effect effect = null)
|
||||||
{
|
{
|
||||||
if (began) throw new InvalidOperationException("Begin is being called twice before being ended.");
|
if (began) throw new InvalidOperationException("Begin is being called twice before being ended.");
|
||||||
if (disposed) throw new ObjectDisposedException(this.GetType().Name);
|
if (disposed) throw new ObjectDisposedException(this.GetType().Name);
|
||||||
@ -57,9 +55,7 @@ namespace RecrownedAthenaeum.Render
|
|||||||
case PrimitiveType.LineStrip: verticesPerPrimitive = 1; break;
|
case PrimitiveType.LineStrip: verticesPerPrimitive = 1; break;
|
||||||
case PrimitiveType.TriangleStrip: verticesPerPrimitive = 3; break;
|
case PrimitiveType.TriangleStrip: verticesPerPrimitive = 3; break;
|
||||||
}
|
}
|
||||||
basicEffect.World = camera.worldMatrix;
|
this.effect = effect ?? basicEffect;
|
||||||
basicEffect.View = camera.ViewMatrix;
|
|
||||||
basicEffect.Projection = camera.projectionMatrix;
|
|
||||||
began = true;
|
began = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +112,7 @@ namespace RecrownedAthenaeum.Render
|
|||||||
if (disposed) throw new ObjectDisposedException(this.GetType().Name);
|
if (disposed) throw new ObjectDisposedException(this.GetType().Name);
|
||||||
if (bufferPosition == 0) return;
|
if (bufferPosition == 0) return;
|
||||||
if (primitiveCount == 0) primitiveCount = bufferPosition / verticesPerPrimitive;
|
if (primitiveCount == 0) primitiveCount = bufferPosition / verticesPerPrimitive;
|
||||||
foreach (EffectPass effectPass in basicEffect.CurrentTechnique.Passes)
|
foreach (EffectPass effectPass in effect.CurrentTechnique.Passes)
|
||||||
{
|
{
|
||||||
effectPass.Apply();
|
effectPass.Apply();
|
||||||
graphicsDevice.DrawUserPrimitives(primitiveType, vertices, 0, primitiveCount);
|
graphicsDevice.DrawUserPrimitives(primitiveType, vertices, 0, primitiveCount);
|
||||||
|
@ -20,11 +20,10 @@ namespace RecrownedAthenaeum.Render
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a rectangle renderer with the given <see cref="PrimitiveBatch"/>.
|
/// Creates a rectangle renderer with the given <see cref="PrimitiveBatch"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="camera">Camera to use for <see cref="PrimitiveBatch"/>. Default will use <see cref="Configuration"/>.</param>
|
/// <param name="graphicsDevice">Graphics device to use.</param>
|
||||||
/// <param name="graphicsDevice">Graphics device to use. Default will use <see cref="Configuration"/>.</param>
|
public RectangleRenderer(GraphicsDevice graphicsDevice)
|
||||||
public RectangleRenderer(Camera2D camera = null, GraphicsDevice graphicsDevice = null)
|
|
||||||
{
|
{
|
||||||
primitiveBatch = new PrimitiveBatch(camera, graphicsDevice);
|
primitiveBatch = new PrimitiveBatch(graphicsDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -9,23 +9,33 @@ namespace RecrownedAthenaeum.Render
|
|||||||
public class ScissorBox
|
public class ScissorBox
|
||||||
{
|
{
|
||||||
|
|
||||||
SpriteBatch spriteBatch;
|
ConsistentSpriteBatch spriteBatch;
|
||||||
Rectangle currentScissorRect;
|
Rectangle originalScissor;
|
||||||
|
RasterizerState originalRasterizerState;
|
||||||
|
|
||||||
|
RasterizerState scissorRasterizerState;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Used to crop off anything that doesn't fit into the defined space.
|
||||||
|
/// </summary>
|
||||||
|
public ScissorBox()
|
||||||
|
{
|
||||||
|
scissorRasterizerState = new RasterizerState();
|
||||||
|
scissorRasterizerState.ScissorTestEnable = true;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Starts spritebatch with scissoring enabled.
|
/// Starts spritebatch with scissoring enabled.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="rectangle"></param>
|
/// <param name="rectangle"></param>
|
||||||
/// <param name="spriteBatch"></param>
|
/// <param name="spriteBatch"></param>
|
||||||
/// <param name="spriteBatchSettings">The settings for using the <see cref="SpriteBatch"/> to perform the scissor.</param>
|
public void Begin(Rectangle rectangle, ConsistentSpriteBatch spriteBatch)
|
||||||
public void Begin(Rectangle rectangle, SpriteBatch spriteBatch, SpriteBatchSettings? spriteBatchSettings = null)
|
|
||||||
{
|
{
|
||||||
if (spriteBatchSettings == null) spriteBatchSettings = Configuration.SpriteBatchSettings;
|
|
||||||
|
|
||||||
this.spriteBatch = spriteBatch;
|
this.spriteBatch = spriteBatch;
|
||||||
spriteBatchSettings.Value.rasterizerState.ScissorTestEnable = true;
|
originalRasterizerState = spriteBatch.RasterizerState;
|
||||||
spriteBatchSettings.Value.BeginSpriteBatch(spriteBatch);
|
spriteBatch.Begin(rasterizerState: scissorRasterizerState);
|
||||||
currentScissorRect = spriteBatch.GraphicsDevice.ScissorRectangle;
|
|
||||||
|
originalScissor = spriteBatch.GraphicsDevice.ScissorRectangle;
|
||||||
spriteBatch.GraphicsDevice.ScissorRectangle = rectangle;
|
spriteBatch.GraphicsDevice.ScissorRectangle = rectangle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +44,8 @@ namespace RecrownedAthenaeum.Render
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void End()
|
public void End()
|
||||||
{
|
{
|
||||||
spriteBatch.GraphicsDevice.ScissorRectangle = currentScissorRect;
|
spriteBatch.GraphicsDevice.ScissorRectangle = originalScissor;
|
||||||
|
spriteBatch.RasterizerState = originalRasterizerState;
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,76 +0,0 @@
|
|||||||
using Microsoft.Xna.Framework;
|
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
|
||||||
|
|
||||||
namespace RecrownedAthenaeum.Render
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The settings the sprite batch should use.
|
|
||||||
/// </summary>
|
|
||||||
public struct SpriteBatchSettings
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Defines sprites sort mode.
|
|
||||||
/// </summary>
|
|
||||||
public SpriteSortMode spriteSortMode;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The blend state to use.
|
|
||||||
/// </summary>
|
|
||||||
public BlendState blendState;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sampler state to use.
|
|
||||||
/// </summary>
|
|
||||||
public SamplerState samplerState;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The depth stencil state to use.
|
|
||||||
/// </summary>
|
|
||||||
public DepthStencilState depthStencilState;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The rasterizer state to use.
|
|
||||||
/// </summary>
|
|
||||||
public RasterizerState rasterizerState;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The effect to use.
|
|
||||||
/// </summary>
|
|
||||||
public Effect effect;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The transformation matrix to use.
|
|
||||||
/// </summary>
|
|
||||||
public Matrix? transformMatrix;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// See <see cref="SpriteBatch.Begin(SpriteSortMode, BlendState, SamplerState, DepthStencilState, RasterizerState, Effect, Matrix?)"/> for uses and defaults.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="spriteSortMode"></param>
|
|
||||||
/// <param name="blendState"></param>
|
|
||||||
/// <param name="samplerState"></param>
|
|
||||||
/// <param name="depthStencilState"></param>
|
|
||||||
/// <param name="rasterizerState"></param>
|
|
||||||
/// <param name="effect"></param>
|
|
||||||
/// <param name="transformMatrix"></param>
|
|
||||||
public SpriteBatchSettings(SpriteSortMode spriteSortMode = SpriteSortMode.Deferred, BlendState blendState = null, SamplerState samplerState = null, DepthStencilState depthStencilState = null, RasterizerState rasterizerState = null, Effect effect = null, Matrix? transformMatrix = null)
|
|
||||||
{
|
|
||||||
this.spriteSortMode = spriteSortMode;
|
|
||||||
this.blendState = blendState;
|
|
||||||
this.samplerState = samplerState;
|
|
||||||
this.depthStencilState = depthStencilState;
|
|
||||||
this.rasterizerState = rasterizerState;
|
|
||||||
this.effect = effect;
|
|
||||||
this.transformMatrix = transformMatrix;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Begins the given sprite batch with the current set of settings.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="spriteBatch">Begins the spritebatch with the given settings.</param>
|
|
||||||
public void BeginSpriteBatch(SpriteBatch spriteBatch)
|
|
||||||
{
|
|
||||||
spriteBatch.Begin(spriteSortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, transformMatrix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,6 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using RecrownedAthenaeum.Render;
|
||||||
|
|
||||||
namespace RecrownedAthenaeum.ScreenSystem
|
namespace RecrownedAthenaeum.ScreenSystem
|
||||||
{
|
{
|
||||||
@ -34,7 +35,7 @@ namespace RecrownedAthenaeum.ScreenSystem
|
|||||||
/// Called once every frame while transition is active. Meant to draw transition.
|
/// Called once every frame while transition is active. Meant to draw transition.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="spriteBatch"></param>
|
/// <param name="spriteBatch"></param>
|
||||||
void DrawTransition(SpriteBatch spriteBatch);
|
void DrawTransition(ConsistentSpriteBatch spriteBatch);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates if the previous screen uses a render target for exit transition.
|
/// Updates if the previous screen uses a render target for exit transition.
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using RecrownedAthenaeum.Render;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace RecrownedAthenaeum.ScreenSystem
|
namespace RecrownedAthenaeum.ScreenSystem
|
||||||
@ -62,10 +63,10 @@ namespace RecrownedAthenaeum.ScreenSystem
|
|||||||
public void InitiateTransition(Rectangle dimensions)
|
public void InitiateTransition(Rectangle dimensions)
|
||||||
{
|
{
|
||||||
color = Color.White;
|
color = Color.White;
|
||||||
textureBounds.Width = (int)(ScreenSize.Height * proportion);
|
textureBounds.Width = (int)(height * proportion);
|
||||||
textureBounds.Height = (int)(ScreenSize.Height * proportion);
|
textureBounds.Height = (int)(height * proportion);
|
||||||
textureBounds.X = (ScreenSize.Width) / 2;
|
textureBounds.X = (width) / 2;
|
||||||
textureBounds.Y = (ScreenSize.Height) / 2;
|
textureBounds.Y = (height) / 2;
|
||||||
origin.X = texture.Width / 2;
|
origin.X = texture.Width / 2;
|
||||||
origin.Y = texture.Height / 2;
|
origin.Y = texture.Height / 2;
|
||||||
}
|
}
|
||||||
@ -83,7 +84,7 @@ namespace RecrownedAthenaeum.ScreenSystem
|
|||||||
/// Draws the transition.
|
/// Draws the transition.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="spriteBatch">Batch to use.</param>
|
/// <param name="spriteBatch">Batch to use.</param>
|
||||||
public void DrawTransition(SpriteBatch spriteBatch)
|
public void DrawTransition(ConsistentSpriteBatch spriteBatch)
|
||||||
{
|
{
|
||||||
spriteBatch.Draw(texture, textureBounds, null, color, rotation, origin, SpriteEffects.None, 0f);
|
spriteBatch.Draw(texture, textureBounds, null, color, rotation, origin, SpriteEffects.None, 0f);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using RecrownedAthenaeum.Camera;
|
using RecrownedAthenaeum.Camera;
|
||||||
|
using RecrownedAthenaeum.Render;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace RecrownedAthenaeum.ScreenSystem
|
namespace RecrownedAthenaeum.ScreenSystem
|
||||||
@ -34,7 +35,7 @@ namespace RecrownedAthenaeum.ScreenSystem
|
|||||||
public readonly List<ITransition> Transitions;
|
public readonly List<ITransition> Transitions;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether or not to continue rendering this screen onto a buffer for the benifit of the next screen to use as a transition.
|
/// Whether or not to continue rendering this screen onto a buffer for the benefit of the next screen to use as a transition.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool UseRenderTargetForExitTransition { get; private set; }
|
public bool UseRenderTargetForExitTransition { get; private set; }
|
||||||
|
|
||||||
@ -49,19 +50,9 @@ namespace RecrownedAthenaeum.ScreenSystem
|
|||||||
public Screen NextScreen { get; set; }
|
public Screen NextScreen { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The current window size.
|
/// The current window dimensions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Rectangle ScreenSize { get; private set; }
|
public int width, height;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether or not screen have been initiated.
|
|
||||||
/// </summary>
|
|
||||||
public bool Initiated { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The 2D camera to be used for the screen.
|
|
||||||
/// </summary>
|
|
||||||
public Camera2D Camera { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Current state of the screen.
|
/// Current state of the screen.
|
||||||
@ -79,13 +70,14 @@ namespace RecrownedAthenaeum.ScreenSystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called only once after initialization to give required parameters.
|
/// Called when screen size is set.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void Initiate(Rectangle screenSize, Camera2D camera)
|
/// <param name="width">The width of the screen.</param>
|
||||||
|
/// <param name="height">The height of the screen.</param>
|
||||||
|
public virtual void ApplySize(int width, int height)
|
||||||
{
|
{
|
||||||
this.Camera = camera;
|
this.width = width;
|
||||||
this.ScreenSize = screenSize;
|
this.height = height;
|
||||||
Initiated = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -101,7 +93,7 @@ namespace RecrownedAthenaeum.ScreenSystem
|
|||||||
/// Called to draw this screen.
|
/// Called to draw this screen.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="spriteBatch">SpriteBatch to use.</param>
|
/// <param name="spriteBatch">SpriteBatch to use.</param>
|
||||||
public virtual void Draw(SpriteBatch spriteBatch)
|
public virtual void Draw(ConsistentSpriteBatch spriteBatch)
|
||||||
{
|
{
|
||||||
foreach (ITransition transition in Transitions)
|
foreach (ITransition transition in Transitions)
|
||||||
{
|
{
|
||||||
@ -167,7 +159,7 @@ namespace RecrownedAthenaeum.ScreenSystem
|
|||||||
{
|
{
|
||||||
foreach (ITransition transition in Transitions)
|
foreach (ITransition transition in Transitions)
|
||||||
{
|
{
|
||||||
transition.InitiateTransition(ScreenSize);
|
transition.InitiateTransition(new Rectangle(0, 0, width, height));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ namespace RecrownedAthenaeum.ScreenSystem
|
|||||||
/// Called when the first screen is being shown.
|
/// Called when the first screen is being shown.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <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 NeedNextScreen(Screen screen);
|
||||||
|
|
||||||
/// <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.
|
||||||
@ -23,18 +23,15 @@ namespace RecrownedAthenaeum.ScreenSystem
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 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 NeedNextScreen NeedNextScreen;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The settings this manager will use to begin a sprite batch.
|
/// The settings this manager will use to begin a sprite batch.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public SpriteBatchSettings batchSettings;
|
|
||||||
|
|
||||||
private GraphicsDeviceManager graphics;
|
private GraphicsDeviceManager graphics;
|
||||||
private Screen previousScreen;
|
private Screen previousScreen;
|
||||||
private RenderTarget2D previousScreenRenderTarget;
|
private RenderTarget2D previousScreenRenderTarget;
|
||||||
private Screen currentScreen;
|
private Screen currentScreen;
|
||||||
private Camera2D camera;
|
|
||||||
private bool firstScreenChangeComplete;
|
private bool firstScreenChangeComplete;
|
||||||
private bool resizing;
|
private bool resizing;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -50,9 +47,9 @@ namespace RecrownedAthenaeum.ScreenSystem
|
|||||||
{
|
{
|
||||||
previousScreen = currentScreen;
|
previousScreen = currentScreen;
|
||||||
currentScreen = value;
|
currentScreen = value;
|
||||||
if (!Screen.Initiated)
|
if (Screen.width != graphics.PreferredBackBufferWidth || Screen.height != graphics.PreferredBackBufferHeight)
|
||||||
{
|
{
|
||||||
Screen.Initiate(new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight), camera);
|
Screen.ApplySize(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
|
||||||
}
|
}
|
||||||
if (previousScreen != null && previousScreenRenderTarget == null && previousScreen.UseRenderTargetForExitTransition)
|
if (previousScreen != null && previousScreenRenderTarget == null && previousScreen.UseRenderTargetForExitTransition)
|
||||||
{
|
{
|
||||||
@ -68,27 +65,12 @@ namespace RecrownedAthenaeum.ScreenSystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a screen manager that helps manage multiple screens and their transitions.
|
/// Creates a screen manager that helps update, draw, and manage multiple screens and their transitions. Uses its own <see cref="SpriteBatch"/>.
|
||||||
/// </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="graphicsDeviceManager">The graphics device manager to be used.</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(GraphicsDeviceManager graphicsDeviceManager)
|
||||||
/// <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)
|
|
||||||
{
|
{
|
||||||
|
graphics = graphicsDeviceManager ?? throw new ArgumentNullException("Graphics device manager argument cannot be null.");
|
||||||
if (camera == null) camera = Configuration.Camera2D;
|
|
||||||
if (!spriteBatchSettings.HasValue)
|
|
||||||
{
|
|
||||||
SpriteBatchSettings basicSettings = new SpriteBatchSettings();
|
|
||||||
basicSettings.effect = camera.BasicEffect;
|
|
||||||
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.");
|
|
||||||
batchSettings = spriteBatchSettings.Value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -98,6 +80,7 @@ namespace RecrownedAthenaeum.ScreenSystem
|
|||||||
/// <param name="waiting">Whether or not there is something a transition should be waiting for. Usually used to wait for assets to complete loading.</param>
|
/// <param name="waiting">Whether or not there is something a transition should be waiting for. Usually used to wait for assets to complete loading.</param>
|
||||||
public void UpdateCurrentScreen(GameTime gameTime, bool waiting)
|
public void UpdateCurrentScreen(GameTime gameTime, bool waiting)
|
||||||
{
|
{
|
||||||
|
waiting = !waiting;
|
||||||
switch (Screen.State)
|
switch (Screen.State)
|
||||||
{
|
{
|
||||||
case ScreenState.EnterTransition:
|
case ScreenState.EnterTransition:
|
||||||
@ -113,7 +96,7 @@ namespace RecrownedAthenaeum.ScreenSystem
|
|||||||
if (!firstScreenChangeComplete)
|
if (!firstScreenChangeComplete)
|
||||||
{
|
{
|
||||||
firstScreenChangeComplete = true;
|
firstScreenChangeComplete = true;
|
||||||
OnFirstScreenChange(Screen);
|
OnNeedNextScreen(Screen);
|
||||||
}
|
}
|
||||||
if (Screen.NextScreen != null)
|
if (Screen.NextScreen != null)
|
||||||
{
|
{
|
||||||
@ -137,24 +120,34 @@ namespace RecrownedAthenaeum.ScreenSystem
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Renders screen into window.
|
/// Renders screen into window.
|
||||||
|
/// Starts and ends the given <paramref name="consistentSpriteBatch"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="spriteBatch">Uses this batch to render.</param>
|
/// <param name="consistentSpriteBatch">The consistent sprite batch to use. Needs to be consistent as changing render targets requires ending and beginning the sprite batch.</param>
|
||||||
public void DrawCurrentScreen(SpriteBatch spriteBatch)
|
public void DrawScreen(ConsistentSpriteBatch consistentSpriteBatch)
|
||||||
{
|
{
|
||||||
|
if (consistentSpriteBatch == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(consistentSpriteBatch));
|
||||||
|
}
|
||||||
|
if (Screen == null) return;
|
||||||
|
|
||||||
graphics.GraphicsDevice.Clear(Screen.BackgroundColor);
|
graphics.GraphicsDevice.Clear(Screen.BackgroundColor);
|
||||||
if (Screen.State == ScreenState.EnterTransition && previousScreen != null && previousScreen.UseRenderTargetForExitTransition)
|
if (Screen.State == ScreenState.EnterTransition && previousScreen != null && previousScreen.UseRenderTargetForExitTransition)
|
||||||
{
|
{
|
||||||
graphics.GraphicsDevice.SetRenderTarget(previousScreenRenderTarget);
|
graphics.GraphicsDevice.SetRenderTarget(previousScreenRenderTarget);
|
||||||
graphics.GraphicsDevice.Clear(previousScreen.BackgroundColor);
|
graphics.GraphicsDevice.Clear(previousScreen.BackgroundColor);
|
||||||
batchSettings.BeginSpriteBatch(spriteBatch);
|
|
||||||
previousScreen.Draw(spriteBatch);
|
consistentSpriteBatch.Begin();
|
||||||
spriteBatch.End();
|
previousScreen.Draw(consistentSpriteBatch);
|
||||||
|
consistentSpriteBatch.End();
|
||||||
|
|
||||||
graphics.GraphicsDevice.SetRenderTarget(null);
|
graphics.GraphicsDevice.SetRenderTarget(null);
|
||||||
Screen.UpdatePreviousScreenFrame(previousScreenRenderTarget);
|
Screen.UpdatePreviousScreenFrame(previousScreenRenderTarget);
|
||||||
}
|
}
|
||||||
batchSettings.BeginSpriteBatch(spriteBatch);
|
|
||||||
Screen.Draw(spriteBatch);
|
consistentSpriteBatch.Begin();
|
||||||
spriteBatch.End();
|
Screen.Draw(consistentSpriteBatch);
|
||||||
|
consistentSpriteBatch.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -181,9 +174,9 @@ namespace RecrownedAthenaeum.ScreenSystem
|
|||||||
Screen.AssetLoadStateChange(true);
|
Screen.AssetLoadStateChange(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnFirstScreenChange(Screen screen)
|
private void OnNeedNextScreen(Screen screen)
|
||||||
{
|
{
|
||||||
ShowFirstScreenEvent?.Invoke(screen);
|
NeedNextScreen?.Invoke(screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -201,12 +194,12 @@ namespace RecrownedAthenaeum.ScreenSystem
|
|||||||
/// <param name="disposing">True of user invoked dispose called.</param>
|
/// <param name="disposing">True of user invoked dispose called.</param>
|
||||||
public virtual void Dispose(bool disposing)
|
public virtual void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposed) return;
|
if (disposed) throw new ObjectDisposedException(GetType().Name);
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
previousScreenRenderTarget?.Dispose();
|
previousScreenRenderTarget?.Dispose();
|
||||||
}
|
}
|
||||||
disposing = true;
|
disposed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using RecrownedAthenaeum.Render;
|
||||||
|
|
||||||
namespace RecrownedAthenaeum.SpecialTypes
|
namespace RecrownedAthenaeum.SpecialTypes
|
||||||
{
|
{
|
||||||
@ -16,6 +17,6 @@ namespace RecrownedAthenaeum.SpecialTypes
|
|||||||
/// <param name="color">The color tint to draw with.</param>
|
/// <param name="color">The color tint to draw with.</param>
|
||||||
/// <param name="rotation">The rotation to be used.</param>
|
/// <param name="rotation">The rotation to be used.</param>
|
||||||
/// <param name="origin">The origin for the rotation.</param>
|
/// <param name="origin">The origin for the rotation.</param>
|
||||||
void Draw(SpriteBatch spriteBatch, Rectangle destination, Color color, float rotation = 0f, Vector2 origin = default(Vector2));
|
void Draw(ConsistentSpriteBatch spriteBatch, Rectangle destination, Color color, float rotation = 0f, Vector2 origin = default(Vector2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,20 +86,21 @@ namespace RecrownedAthenaeum.SpecialTypes
|
|||||||
/// Draws the ninepatch.
|
/// Draws the ninepatch.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="spriteBatch">Batch to use.</param>
|
/// <param name="spriteBatch">Batch to use.</param>
|
||||||
/// <param name="destination">Where to the patch.</param>
|
|
||||||
/// <param name="color">The color of the patch.</param>
|
/// <param name="color">The color of the patch.</param>
|
||||||
/// <param name="spriteBatchSettings">The sprite batch settings to use to begin the batch in after drawing the ninepatch.</param>
|
/// <param name="destination">Where to the patch.</param>
|
||||||
public void Draw(SpriteBatch spriteBatch, Color color, Rectangle destination, SpriteBatchSettings? spriteBatchSettings = null)
|
public void Draw(ConsistentSpriteBatch spriteBatch, Color color, Rectangle destination)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if (spriteBatchSettings == null) spriteBatchSettings = Configuration.SpriteBatchSettings;
|
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
} catch (InvalidOperationException)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Begin must be called to draw a nine patch!");
|
||||||
|
}
|
||||||
|
|
||||||
SpriteBatchSettings ss = spriteBatchSettings.Value;
|
SamplerState originalSamplerState = spriteBatch.SamplerState;
|
||||||
SamplerState nSS = ss.samplerState;
|
GraphicsDevice graphics = spriteBatch.GraphicsDevice;
|
||||||
|
spriteBatch.Begin(samplerState: SamplerState.PointClamp);
|
||||||
ss.samplerState = SamplerState.PointClamp;
|
|
||||||
|
|
||||||
ss.BeginSpriteBatch(spriteBatch);
|
|
||||||
|
|
||||||
Rectangle[] destinations = GenenerateDestinationRectangles(destination.Width, destination.Height);
|
Rectangle[] destinations = GenenerateDestinationRectangles(destination.Width, destination.Height);
|
||||||
for (int i = 0; i < destinations.Length; i++)
|
for (int i = 0; i < destinations.Length; i++)
|
||||||
@ -110,20 +111,17 @@ namespace RecrownedAthenaeum.SpecialTypes
|
|||||||
}
|
}
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
|
||||||
ss.samplerState = nSS;
|
spriteBatch.Begin(samplerState: originalSamplerState);
|
||||||
ss.BeginSpriteBatch(spriteBatch);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Draw with more options.
|
|
||||||
/// Uses the default <see cref="Configuration"/> for the spritebatch settings.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="spriteBatch">Spritebatch to use.</param>
|
/// <param name="spriteBatch">Spritebatch to use.</param>
|
||||||
/// <param name="destination">The destination to draw the patch.</param>
|
/// <param name="destination">The destination to draw the patch.</param>
|
||||||
/// <param name="color">The tint for each patch.</param>
|
/// <param name="color">The tint for each patch.</param>
|
||||||
/// <param name="rotation">Not considered for 9patches.</param>
|
/// <param name="rotation">Not considered for 9patches.</param>
|
||||||
/// <param name="origin">Not considered for 9patches.</param>
|
/// <param name="origin">Not considered for 9patches.</param>
|
||||||
public void Draw(SpriteBatch spriteBatch, Rectangle destination, Color color, float rotation = 0, Vector2 origin = default(Vector2))
|
public void Draw(ConsistentSpriteBatch spriteBatch, Rectangle destination, Color color, float rotation = 0, Vector2 origin = default(Vector2))
|
||||||
{
|
{
|
||||||
if (rotation != 0) throw new NotImplementedException("Ninepatches can't be rotated.");
|
if (rotation != 0) throw new NotImplementedException("Ninepatches can't be rotated.");
|
||||||
if (origin != default(Vector2)) throw new NotImplementedException("Ninepatches can't have origin changed (hint: use the destination rectangle to shift and position).");
|
if (origin != default(Vector2)) throw new NotImplementedException("Ninepatches can't have origin changed (hint: use the destination rectangle to shift and position).");
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using RecrownedAthenaeum.Render;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -56,7 +57,7 @@ namespace RecrownedAthenaeum.SpecialTypes
|
|||||||
/// <param name="color">Color to use.</param>
|
/// <param name="color">Color to use.</param>
|
||||||
/// <param name="rotation">Rotation of texture drawn.</param>
|
/// <param name="rotation">Rotation of texture drawn.</param>
|
||||||
/// <param name="origin">Origin used by rotation.</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);
|
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.
|
/// Creates or obtains a previously created texture of a region.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">Name of region.</param>
|
/// <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>
|
/// <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);
|
return dictionaryOfRegions[name].AsTexture2D(graphicsDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ namespace RecrownedAthenaeum.SpecialTypes
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A region of a <see cref="TextureAtlas"/>.
|
/// A region of a <see cref="TextureAtlas"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Region : IComparable<Region>, ISpecialDrawable, IDisposable
|
public class Region : ISpecialDrawable, IDisposable
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The name of the region. Mostly used to be refered to within the context of a <see cref="TextureAtlas"/>.
|
/// 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.atlasTexture = atlasTexture ?? throw new ArgumentNullException("Name parameters can be null.");
|
||||||
this.name = name ?? throw new ArgumentNullException("Name parameters can be null.");
|
this.name = name ?? throw new ArgumentNullException("Name parameters can be null.");
|
||||||
this.sourceRectangle = sourceRegion;
|
sourceRectangle = sourceRegion;
|
||||||
this.ninepatch = ninePatch;
|
ninepatch = ninePatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -168,7 +168,7 @@ namespace RecrownedAthenaeum.SpecialTypes
|
|||||||
/// <param name="color">The color to use.</param>
|
/// <param name="color">The color to use.</param>
|
||||||
/// <param name="rotation">Rotation of the final drawing. Ignored if is a 9patch.</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>
|
/// <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);
|
if (Disposed) throw new ObjectDisposedException(GetType().Name);
|
||||||
|
|
||||||
@ -185,16 +185,15 @@ namespace RecrownedAthenaeum.SpecialTypes
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create or obtains a previously created texture of this region.
|
/// Create or obtains a previously created texture of this region.
|
||||||
/// </summary>
|
/// </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>
|
/// <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 (Disposed) throw new ObjectDisposedException(GetType().Name);
|
||||||
|
|
||||||
if (regionTexture == null)
|
if (regionTexture == null)
|
||||||
{
|
{
|
||||||
Color[] data = new Color[sourceRectangle.Width * sourceRectangle.Height];
|
Color[] data = new Color[sourceRectangle.Width * sourceRectangle.Height];
|
||||||
if (graphicsDevice == null) graphicsDevice = Configuration.GraphicsDeviceManager.GraphicsDevice;
|
|
||||||
regionTexture = new Texture2D(graphicsDevice, sourceRectangle.Width, sourceRectangle.Height);
|
regionTexture = new Texture2D(graphicsDevice, sourceRectangle.Width, sourceRectangle.Height);
|
||||||
atlasTexture.GetData(0, sourceRectangle, data, 0, sourceRectangle.Width * sourceRectangle.Height);
|
atlasTexture.GetData(0, sourceRectangle, data, 0, sourceRectangle.Width * sourceRectangle.Height);
|
||||||
regionTexture.SetData(data);
|
regionTexture.SetData(data);
|
||||||
@ -202,16 +201,6 @@ namespace RecrownedAthenaeum.SpecialTypes
|
|||||||
return regionTexture;
|
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>
|
/// <summary>
|
||||||
/// Call this to dispose.
|
/// Call this to dispose.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -4,7 +4,9 @@ using Microsoft.Xna.Framework.Input;
|
|||||||
using RecrownedAthenaeum.Camera;
|
using RecrownedAthenaeum.Camera;
|
||||||
using RecrownedAthenaeum.ContentSystem;
|
using RecrownedAthenaeum.ContentSystem;
|
||||||
using RecrownedAthenaeum.Input;
|
using RecrownedAthenaeum.Input;
|
||||||
|
using RecrownedAthenaeum.Render;
|
||||||
using RecrownedAthenaeum.UI.SkinSystem;
|
using RecrownedAthenaeum.UI.SkinSystem;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
@ -17,46 +19,80 @@ namespace RecrownedAthenaeum.UI.BookSystem
|
|||||||
{
|
{
|
||||||
readonly ContentManagerController assets;
|
readonly ContentManagerController assets;
|
||||||
readonly ISkin skin;
|
readonly ISkin skin;
|
||||||
Camera2D camera;
|
|
||||||
Page targetPage;
|
Page targetPage;
|
||||||
Rectangle dimensions;
|
int width, height;
|
||||||
Dictionary<string, Page> pages = new Dictionary<string, Page>();
|
Dictionary<string, Page> pages = new Dictionary<string, Page>();
|
||||||
List<Page> orderedPages = new List<Page>();
|
List<Page> orderedPages = new List<Page>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The camera to use to change between pages.
|
||||||
|
/// </summary>
|
||||||
|
public Camera2D camera;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The scissorbox used to crop things.
|
||||||
|
/// </summary>
|
||||||
|
public ScissorBox scissorBox;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a book.
|
/// Creates a book.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="assets"><see cref="ContentManagerController"/> that holds the assets that are to be used in the pages for this book during initialization.</param>
|
/// <param name="assets"><see cref="ContentManagerController"/> that holds the assets that are to be used in the pages for this book during initialization.</param>
|
||||||
/// <param name="skin">The skin that will be passed to pages during their initialization.</param>
|
/// <param name="skin">The skin that will be passed to pages during their initialization.</param>
|
||||||
public Book(ContentManagerController assets, ISkin skin)
|
/// <param name="camera">Camera to move to change pages.</param>
|
||||||
|
/// <param name="scissorBox">The scissor box to use to crop the pages to the given dimensions. Default is null, and will not crop anything.</param>
|
||||||
|
public Book(ContentManagerController assets, ISkin skin, Camera2D camera, ScissorBox scissorBox = null)
|
||||||
{
|
{
|
||||||
this.assets = assets;
|
this.assets = assets;
|
||||||
this.skin = skin;
|
this.skin = skin;
|
||||||
|
|
||||||
|
this.camera = camera ?? throw new ArgumentNullException("Camera can't be null since book needs a camera to move to change between the slides (pages).");
|
||||||
|
this.scissorBox = scissorBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Should be called whenever a valid camera and dimensions for the book exist.
|
/// Should be called whenever a valid camera and dimensions for the book exist.
|
||||||
/// Initializes book with given parameters.
|
/// Initializes book with given parameters.
|
||||||
/// Generally used with a <see cref="ScreenSystem.Screen"/> and called in the <see cref="ScreenSystem.Screen.Initiate(Rectangle, Camera2D)"/> function.
|
/// Generally used with a <see cref="ScreenSystem.Screen"/> and called in the <see cref="ScreenSystem.Screen.ApplySize(int, int)"/> function.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="camera">Camera game is currently using.</param>
|
/// <param name="camera">Camera to move to change pages.</param>
|
||||||
/// <param name="dimensions">Dimensions of the book and the dimensions the pages will use.</param>
|
/// <param name="dimensions">Dimensions of the book and the dimensions the pages will use.</param>
|
||||||
public void Initiate(Camera2D camera, Rectangle dimensions)
|
/// <param name="scissorBox">The scissor box to use to crop the pages to the given dimensions. Default is null, and will not crop anything.</param>
|
||||||
|
public void Initiate(Camera2D camera, Rectangle dimensions, ScissorBox scissorBox = null)
|
||||||
{
|
{
|
||||||
this.camera = camera;
|
this.camera = camera;
|
||||||
this.dimensions = dimensions;
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Applies the size if the book's pages.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="width">The width of one page.</param>
|
||||||
|
/// <param name="height">The height of one page.</param>
|
||||||
|
public void ApplySize(int width, int height)
|
||||||
|
{
|
||||||
|
if (this.width == width && this.height == height) return;
|
||||||
|
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
for (int pageIndex = 0; pageIndex < pages.Count; pageIndex++)
|
||||||
|
{
|
||||||
|
Page page = orderedPages[pageIndex];
|
||||||
|
if (page.Boundaries.Width != width || page.Boundaries.Height != height)
|
||||||
|
{
|
||||||
|
page.requiresSizeUpdate = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Draws the pages.
|
/// Draws the pages.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="batch">Batch used to draw.</param>
|
/// <param name="batch">Batch used to draw.</param>
|
||||||
public void Draw(SpriteBatch batch)
|
public void Draw(ConsistentSpriteBatch batch)
|
||||||
{
|
{
|
||||||
for (int pageIndex = 0; pageIndex < pages.Count; pageIndex++)
|
for (int pageIndex = 0; pageIndex < pages.Count; pageIndex++)
|
||||||
{
|
{
|
||||||
Page page = orderedPages[pageIndex];
|
orderedPages[pageIndex].Draw(batch);
|
||||||
page.Draw(batch);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +118,7 @@ namespace RecrownedAthenaeum.UI.BookSystem
|
|||||||
for (int pageIndex = 0; pageIndex < pages.Count; pageIndex++)
|
for (int pageIndex = 0; pageIndex < pages.Count; pageIndex++)
|
||||||
{
|
{
|
||||||
Page page = pages.ElementAt(pageIndex).Value;
|
Page page = pages.ElementAt(pageIndex).Value;
|
||||||
if (page.requiresSizeUpdate) page.ApplySize(dimensions.Width, dimensions.Height);
|
if (page.requiresSizeUpdate) page.ApplySize(width, height);
|
||||||
page.Update(gameTime);
|
page.Update(gameTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,6 +133,7 @@ namespace RecrownedAthenaeum.UI.BookSystem
|
|||||||
{
|
{
|
||||||
orderedPages.Add(page);
|
orderedPages.Add(page);
|
||||||
this.pages.Add(page.name, page);
|
this.pages.Add(page.name, page);
|
||||||
|
page.Initialize(assets, skin, scissorBox);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using RecrownedAthenaeum.ContentSystem;
|
using RecrownedAthenaeum.ContentSystem;
|
||||||
|
using RecrownedAthenaeum.Render;
|
||||||
using RecrownedAthenaeum.UI.Modular;
|
using RecrownedAthenaeum.UI.Modular;
|
||||||
using RecrownedAthenaeum.UI.SkinSystem;
|
using RecrownedAthenaeum.UI.SkinSystem;
|
||||||
|
|
||||||
@ -20,7 +21,7 @@ namespace RecrownedAthenaeum.UI.BookSystem
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pageX">The X position in the book.</param>
|
/// <param name="pageX">The X position in the book.</param>
|
||||||
/// <param name="pageY">The Y position in the book.</param>
|
/// <param name="pageY">The Y position in the book.</param>
|
||||||
public Page(int pageX, int pageY) : base(false)
|
public Page(int pageX, int pageY) : base()
|
||||||
{
|
{
|
||||||
this.pageX = pageX;
|
this.pageX = pageX;
|
||||||
this.pageY = pageY;
|
this.pageY = pageY;
|
||||||
@ -47,9 +48,10 @@ namespace RecrownedAthenaeum.UI.BookSystem
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="assets">The assets to be used during initialization passed by the book this page belongs to.</param>
|
/// <param name="assets">The assets to be used during initialization passed by the book this page belongs to.</param>
|
||||||
/// <param name="skin">The skin the book containing this page is given that can be used by this page.</param>
|
/// <param name="skin">The skin the book containing this page is given that can be used by this page.</param>
|
||||||
protected internal virtual void Initialize(ContentManagerController assets, ISkin skin)
|
/// <param name="scissorBox">The scissor box to use for cropping.</param>
|
||||||
|
protected internal virtual void Initialize(ContentManagerController assets, ISkin skin, ScissorBox scissorBox)
|
||||||
{
|
{
|
||||||
|
this.scissorBox = scissorBox;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using RecrownedAthenaeum.Render;
|
||||||
using RecrownedAthenaeum.SpecialTypes;
|
using RecrownedAthenaeum.SpecialTypes;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
@ -49,7 +50,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
|||||||
/// Draws the image with default values.
|
/// Draws the image with default values.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="batch">The batch to use.</param>
|
/// <param name="batch">The batch to use.</param>
|
||||||
public override void Draw(SpriteBatch batch)
|
public override void Draw(ConsistentSpriteBatch batch)
|
||||||
{
|
{
|
||||||
batch.Draw(texture, situation, null, color, rotation, origin, SpriteEffects.None, 0f);
|
batch.Draw(texture, situation, null, color, rotation, origin, SpriteEffects.None, 0f);
|
||||||
base.Draw(batch);
|
base.Draw(batch);
|
||||||
@ -63,7 +64,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
|||||||
/// <param name="color">The color tint to use.</param>
|
/// <param name="color">The color tint to use.</param>
|
||||||
/// <param name="rotation">Rotation of image.</param>
|
/// <param name="rotation">Rotation of image.</param>
|
||||||
/// <param name="origin">Origin for the rotation.</param>
|
/// <param name="origin">Origin for the rotation.</param>
|
||||||
public void Draw(SpriteBatch spriteBatch, Rectangle destination, Color color, float rotation = 0, Vector2 origin = default(Vector2))
|
public void Draw(ConsistentSpriteBatch spriteBatch, Rectangle destination, Color color, float rotation = 0, Vector2 origin = default(Vector2))
|
||||||
{
|
{
|
||||||
this.color = color;
|
this.color = color;
|
||||||
this.rotation = rotation;
|
this.rotation = rotation;
|
||||||
|
@ -4,6 +4,7 @@ using RecrownedAthenaeum.SpecialTypes;
|
|||||||
using RecrownedAthenaeum.Input;
|
using RecrownedAthenaeum.Input;
|
||||||
using RecrownedAthenaeum.UI.SkinSystem.Definitions;
|
using RecrownedAthenaeum.UI.SkinSystem.Definitions;
|
||||||
using RecrownedAthenaeum.UI.SkinSystem;
|
using RecrownedAthenaeum.UI.SkinSystem;
|
||||||
|
using RecrownedAthenaeum.Render;
|
||||||
|
|
||||||
namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
||||||
{
|
{
|
||||||
@ -80,7 +81,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
|||||||
/// Draws the button.
|
/// Draws the button.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="batch">Batch used to draw the button.</param>
|
/// <param name="batch">Batch used to draw the button.</param>
|
||||||
public override void Draw(SpriteBatch batch)
|
public override void Draw(ConsistentSpriteBatch batch)
|
||||||
{
|
{
|
||||||
if (disabled)
|
if (disabled)
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using RecrownedAthenaeum.Render;
|
||||||
using RecrownedAthenaeum.SpecialTypes;
|
using RecrownedAthenaeum.SpecialTypes;
|
||||||
using RecrownedAthenaeum.UI.SkinSystem;
|
using RecrownedAthenaeum.UI.SkinSystem;
|
||||||
using RecrownedAthenaeum.UI.SkinSystem.Definitions;
|
using RecrownedAthenaeum.UI.SkinSystem.Definitions;
|
||||||
@ -84,7 +85,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
|||||||
/// Called whenever game wants to render this button.
|
/// Called whenever game wants to render this button.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="batch">Batch to use. Batch should already be started.</param>
|
/// <param name="batch">Batch to use. Batch should already be started.</param>
|
||||||
public override void Draw(SpriteBatch batch)
|
public override void Draw(ConsistentSpriteBatch batch)
|
||||||
{
|
{
|
||||||
base.Draw(batch);
|
base.Draw(batch);
|
||||||
text.Draw(batch);
|
text.Draw(batch);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using RecrownedAthenaeum.Render;
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@ -80,7 +81,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
|||||||
/// Draws the text.
|
/// Draws the text.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="batch">Batch to use.</param>
|
/// <param name="batch">Batch to use.</param>
|
||||||
public override void Draw(SpriteBatch batch)
|
public override void Draw(ConsistentSpriteBatch batch)
|
||||||
{
|
{
|
||||||
batch.DrawString(font, Content, position, color, 0f, default(Vector2), scale, SpriteEffects.None, 0f);
|
batch.DrawString(font, Content, position, color, 0f, default(Vector2), scale, SpriteEffects.None, 0f);
|
||||||
base.Draw(batch);
|
base.Draw(batch);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
using RecrownedAthenaeum.Input;
|
using RecrownedAthenaeum.Input;
|
||||||
|
using RecrownedAthenaeum.Render;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace RecrownedAthenaeum.UI.Modular
|
namespace RecrownedAthenaeum.UI.Modular
|
||||||
@ -61,7 +62,7 @@ namespace RecrownedAthenaeum.UI.Modular
|
|||||||
/// Called every frame to draw this module. Anything that needs to be drawn should go here.
|
/// Called every frame to draw this module. Anything that needs to be drawn should go here.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="batch">Batch used to draw.</param>
|
/// <param name="batch">Batch used to draw.</param>
|
||||||
public virtual void Draw(SpriteBatch batch)
|
public virtual void Draw(ConsistentSpriteBatch batch)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,36 +14,22 @@ namespace RecrownedAthenaeum.UI.Modular
|
|||||||
public class UIModuleGroup : UIModule
|
public class UIModuleGroup : UIModule
|
||||||
{
|
{
|
||||||
List<UIModule> modules = new List<UIModule>();
|
List<UIModule> modules = new List<UIModule>();
|
||||||
ScissorBox scissorBox;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Configuration for starting sprite batch after scissoring. Only used if cropping.
|
/// Set this to crop anything that flows out of the boundaries of this group. Will not crop if this is null.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public SpriteBatchSettings spriteBatchSettings;
|
public ScissorBox scissorBox;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a module group.
|
/// Draws this group of modules. If scissoring, will use the matrix and effect designated in the <see cref="ScissorBox"/> to begin the batch normally again.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="crop">Whether or not to crop out of bounds. Default is false.</param>
|
/// <param name="spriteBatch">Batch used to draw the group.</param>
|
||||||
public UIModuleGroup(bool crop = false)
|
public override void Draw(ConsistentSpriteBatch spriteBatch)
|
||||||
{
|
|
||||||
this.spriteBatchSettings = Configuration.SpriteBatchSettings.Value;
|
|
||||||
if (crop)
|
|
||||||
{
|
|
||||||
scissorBox = new ScissorBox();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Draws this group of modules.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="batch">Batch used to draw the group.</param>
|
|
||||||
public override void Draw(SpriteBatch batch)
|
|
||||||
{
|
{
|
||||||
if (scissorBox != null)
|
if (scissorBox != null)
|
||||||
{
|
{
|
||||||
batch.End();
|
spriteBatch.End();
|
||||||
scissorBox.Begin(Boundaries, batch, spriteBatchSettings);
|
scissorBox.Begin(Boundaries, spriteBatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (UIModule module in modules)
|
foreach (UIModule module in modules)
|
||||||
@ -52,7 +38,7 @@ namespace RecrownedAthenaeum.UI.Modular
|
|||||||
int offsetY = module.situation.Y;
|
int offsetY = module.situation.Y;
|
||||||
module.situation.X = situation.X + offsetX;
|
module.situation.X = situation.X + offsetX;
|
||||||
module.situation.Y = situation.Y + offsetY;
|
module.situation.Y = situation.Y + offsetY;
|
||||||
module.Draw(batch);
|
module.Draw(spriteBatch);
|
||||||
module.situation.X = offsetX;
|
module.situation.X = offsetX;
|
||||||
module.situation.Y = offsetY;
|
module.situation.Y = offsetY;
|
||||||
}
|
}
|
||||||
@ -61,6 +47,8 @@ namespace RecrownedAthenaeum.UI.Modular
|
|||||||
{
|
{
|
||||||
scissorBox.End();
|
scissorBox.End();
|
||||||
|
|
||||||
|
GraphicsDevice graphics = spriteBatch.GraphicsDevice;
|
||||||
|
spriteBatch.Begin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using RecrownedAthenaeum.Render;
|
||||||
using RecrownedAthenaeum.SpecialTypes;
|
using RecrownedAthenaeum.SpecialTypes;
|
||||||
using RecrownedAthenaeum.UI.SkinSystem.Definitions;
|
using RecrownedAthenaeum.UI.SkinSystem.Definitions;
|
||||||
|
|
||||||
@ -24,7 +25,7 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
|||||||
/// <param name="destination">The destination to draw to.</param>
|
/// <param name="destination">The destination to draw to.</param>
|
||||||
/// <param name="rotation">The rotation to use in radians.</param>
|
/// <param name="rotation">The rotation to use in radians.</param>
|
||||||
/// <param name="origin">The origin for the rotation.</param>
|
/// <param name="origin">The origin for the rotation.</param>
|
||||||
void Draw(string regionName, string color, SpriteBatch batch, Rectangle destination, float rotation = 0, Vector2 origin = default(Vector2));
|
void Draw(string regionName, string color, ConsistentSpriteBatch batch, Rectangle destination, float rotation = 0, Vector2 origin = default(Vector2));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a <see cref="Color"/> with given name of defined color;
|
/// Returns a <see cref="Color"/> with given name of defined color;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using RecrownedAthenaeum.Render;
|
||||||
using RecrownedAthenaeum.SpecialTypes;
|
using RecrownedAthenaeum.SpecialTypes;
|
||||||
using RecrownedAthenaeum.UI.SkinSystem.Definitions;
|
using RecrownedAthenaeum.UI.SkinSystem.Definitions;
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw(string regionName, string color, SpriteBatch batch, Rectangle destination, float rotation = 0, Vector2 origin = default(Vector2))
|
public void Draw(string regionName, string color, ConsistentSpriteBatch batch, Rectangle destination, float rotation = 0, Vector2 origin = default(Vector2))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using RecrownedAthenaeum.Render;
|
||||||
using RecrownedAthenaeum.SpecialTypes;
|
using RecrownedAthenaeum.SpecialTypes;
|
||||||
using RecrownedAthenaeum.UI.SkinSystem.Definitions;
|
using RecrownedAthenaeum.UI.SkinSystem.Definitions;
|
||||||
using System;
|
using System;
|
||||||
@ -80,7 +81,7 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
|||||||
/// <param name="destination">The destination to draw to.</param>
|
/// <param name="destination">The destination to draw to.</param>
|
||||||
/// <param name="rotation">The rotation to use in radians.</param>
|
/// <param name="rotation">The rotation to use in radians.</param>
|
||||||
/// <param name="origin">The origin for the rotation.</param>
|
/// <param name="origin">The origin for the rotation.</param>
|
||||||
public void Draw(string regionName, string color, SpriteBatch batch, Rectangle destination, float rotation = 0, Vector2 origin = default(Vector2))
|
public void Draw(string regionName, string color, ConsistentSpriteBatch batch, Rectangle destination, float rotation = 0, Vector2 origin = default(Vector2))
|
||||||
{
|
{
|
||||||
if (disposed) throw new ObjectDisposedException(GetType().Name);
|
if (disposed) throw new ObjectDisposedException(GetType().Name);
|
||||||
textureAtlas.Draw(regionName, batch, destination, colors[color], rotation, origin);
|
textureAtlas.Draw(regionName, batch, destination, colors[color], rotation, origin);
|
||||||
|
@ -71,7 +71,7 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
|||||||
public ISkin Skin { get { return mergedSkin; } }
|
public ISkin Skin { get { return mergedSkin; } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The user loaded skin. Set by the skin loaded by calling <see cref="LoadSkin(SkinData, string, GraphicsDevice)"/>.
|
/// The user loaded skin resulted from asynchronous <see cref="LoadSkin(string, GraphicsDevice)"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ISkin loadedSkin { get { return mergedSkin.mainSkin; } private set { mergedSkin.mainSkin = value; } }
|
public ISkin loadedSkin { get { return mergedSkin.mainSkin; } private set { mergedSkin.mainSkin = value; } }
|
||||||
|
|
||||||
@ -111,16 +111,14 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// loads a skin asynchronously to the <see cref="loadedSkin"/>.
|
/// loads a skin asynchronously to the <see cref="loadedSkin"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="graphicsDevice">Graphics device to use for texture creation. Uses graphics device from <see cref="Configuration"/>by default.</param>
|
|
||||||
/// <param name="skinData">The data to generate from.</param>
|
|
||||||
/// <param name="path">The path pointing to the file with the extension "<see cref="EXTENSION"/>".</param>
|
/// <param name="path">The path pointing to the file with the extension "<see cref="EXTENSION"/>".</param>
|
||||||
public void LoadSkin(SkinData skinData, string path, GraphicsDevice graphicsDevice = null)
|
/// <param name="graphicsDevice">Graphics device to use for texture creation.</param>
|
||||||
|
public void LoadSkin(string path, GraphicsDevice graphicsDevice)
|
||||||
{
|
{
|
||||||
if (graphicsDevice == null) graphicsDevice = Configuration.GraphicsDeviceManager.GraphicsDevice;
|
|
||||||
action = Action.LOAD;
|
action = Action.LOAD;
|
||||||
this.graphicsDevice = graphicsDevice;
|
this.graphicsDevice = graphicsDevice ?? throw new ArgumentNullException("Requires graphics device to create textures.");
|
||||||
this.selectedSkinPath = path;
|
selectedSkinPath = path ?? throw new ArgumentNullException("Requires path to find textures.");
|
||||||
this.skinDataToUse = skinData;
|
skinDataToUse = ReadSkinData(path);
|
||||||
|
|
||||||
AttemptAsync();
|
AttemptAsync();
|
||||||
}
|
}
|
||||||
@ -163,14 +161,18 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
|||||||
}
|
}
|
||||||
TextureAtlasDataReader tatlasDataReader = new TextureAtlasDataReader();
|
TextureAtlasDataReader tatlasDataReader = new TextureAtlasDataReader();
|
||||||
TextureAtlasData atlasData;
|
TextureAtlasData atlasData;
|
||||||
using (FileStream fileStream = new FileStream(filePath[skinData.nameOfTextureAtlas], FileMode.Open))
|
atlasData = JsonConvert.DeserializeObject<TextureAtlasData>(File.ReadAllText(filePath[skinData.nameOfTextureAtlas]));
|
||||||
{
|
|
||||||
atlasData = tatlasDataReader.ReadTextureAtlasData(new BinaryReader(fileStream));
|
|
||||||
}
|
|
||||||
Texture2D atlasTexture;
|
Texture2D atlasTexture;
|
||||||
using (FileStream stream = new FileStream(filePath[atlasData.textureName], FileMode.Open))
|
using (FileStream stream = new FileStream(filePath[atlasData.textureName], FileMode.Open))
|
||||||
{
|
{
|
||||||
atlasTexture = Texture2D.FromStream(graphicsDevice, stream);
|
atlasTexture = Texture2D.FromStream(graphicsDevice, stream);
|
||||||
|
Vector4[] data = new Vector4[atlasTexture.Width * atlasTexture.Height];
|
||||||
|
atlasTexture.GetData(data);
|
||||||
|
for (int i = 0; i < data.Length; i++)
|
||||||
|
{
|
||||||
|
Color.FromNonPremultiplied(data[i]);
|
||||||
|
}
|
||||||
|
atlasTexture.SetData(data);
|
||||||
}
|
}
|
||||||
TextureAtlas.Region[] regions = textureAtlasDataReader.GenerateAtlasRegionsFromData(atlasData, atlasTexture);
|
TextureAtlas.Region[] regions = textureAtlasDataReader.GenerateAtlasRegionsFromData(atlasData, atlasTexture);
|
||||||
TextureAtlas textureAtlas = new TextureAtlas(atlasTexture, regions);
|
TextureAtlas textureAtlas = new TextureAtlas(atlasTexture, regions);
|
||||||
@ -180,6 +182,13 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
|||||||
using (FileStream stream = new FileStream(filePath[skinData.cursorTextureName], FileMode.Open))
|
using (FileStream stream = new FileStream(filePath[skinData.cursorTextureName], FileMode.Open))
|
||||||
{
|
{
|
||||||
cursorTexture = Texture2D.FromStream(graphicsDevice, stream);
|
cursorTexture = Texture2D.FromStream(graphicsDevice, stream);
|
||||||
|
Vector4[] data = new Vector4[cursorTexture.Width * cursorTexture.Height];
|
||||||
|
atlasTexture.GetData(data);
|
||||||
|
for (int i = 0; i < data.Length; i++)
|
||||||
|
{
|
||||||
|
Color.FromNonPremultiplied(data[i]);
|
||||||
|
}
|
||||||
|
cursorTexture.SetData(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user