Began trying to fix primitive batch. Added a default camera to the configuration.
This commit is contained in:
@@ -31,9 +31,9 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
public float ScaleY { get { return (float)bounds.Height / Texture.Height; } set { bounds.Height = (int)(Texture.Height * value); } }
|
||||
|
||||
/// <summary>
|
||||
/// Overall scale.
|
||||
/// Sets scale of X and Y.
|
||||
/// </summary>
|
||||
public float Scale { set { bounds.Height = (int)(Texture.Height * value); bounds.Width = (int)(Texture.Width * value); } }
|
||||
public float Scale { set { ScaleY = value; ScaleX = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an image given a texture.
|
||||
|
@@ -2,6 +2,7 @@
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using RecrownedAthenaeum.UI.SkinSystem;
|
||||
using RecrownedAthenaeum.UI.SkinSystem.Definitions;
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
@@ -41,7 +42,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
/// <summary>
|
||||
/// The string to be displayed.
|
||||
/// </summary>
|
||||
public string Content { get { return originalText; } set { if (value == null) value = ellipsis; modifiedTextSize = font.MeasureString(value); originalText = value; displayedText = value; } }
|
||||
public string Content { get { return originalText; } set { originalText = value; if (value == null) value = ellipsis; modifiedTextSize = font.MeasureString(value); displayedText = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a UI text object.
|
||||
@@ -50,8 +51,8 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
/// <param name="content">The string for the text.</param>
|
||||
public Text(SpriteFont font, string content = null)
|
||||
{
|
||||
this.font = font ?? throw new ArgumentNullException("Font cannot be null.");
|
||||
Content = content;
|
||||
this.font = font;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -129,7 +130,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
/// </summary>
|
||||
public void ResetToOriginalText()
|
||||
{
|
||||
ModifiedText = originalText;
|
||||
Content = originalText;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -2,6 +2,7 @@
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using RecrownedAthenaeum.Input;
|
||||
using RecrownedAthenaeum.Render;
|
||||
using System;
|
||||
|
||||
namespace RecrownedAthenaeum.UI.Modular
|
||||
@@ -12,6 +13,16 @@ namespace RecrownedAthenaeum.UI.Modular
|
||||
/// </summary>
|
||||
public class UIModule : IInputListener
|
||||
{
|
||||
private RectangleRenderer renderer;
|
||||
private PrimitiveBatch primitiveBatch;
|
||||
|
||||
private bool debug = false;
|
||||
|
||||
/// <summary>
|
||||
/// Draws rectangle using the bounds of this module.
|
||||
/// </summary>
|
||||
public bool Debugging { set { if (value) { if (renderer == null) renderer = new RectangleRenderer(primitiveBatch = new PrimitiveBatch()); } else { primitiveBatch.Dispose(); primitiveBatch = null; renderer = null; } } get { return debug; } }
|
||||
|
||||
/// <summary>
|
||||
/// Bounds of this module.
|
||||
/// </summary>
|
||||
@@ -51,7 +62,7 @@ namespace RecrownedAthenaeum.UI.Modular
|
||||
/// <param name="batch">Batch used to draw.</param>
|
||||
public virtual void Draw(SpriteBatch batch)
|
||||
{
|
||||
|
||||
if (Debugging) { renderer.Begin(false); renderer.DrawRectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height, Color.Red); renderer.End(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -15,23 +15,25 @@ namespace RecrownedAthenaeum.UI.Modular
|
||||
{
|
||||
List<UIModule> modules = new List<UIModule>();
|
||||
Rectangle scissorBounds;
|
||||
RasterizerState scissorRasterizer = new RasterizerState();
|
||||
RasterizerState scissorRasterizer;
|
||||
|
||||
/// <summary>
|
||||
/// Camera used by the module for cropping.
|
||||
/// </summary>
|
||||
public Camera2D Camera { get; set; }
|
||||
public Camera2D camera;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a module group.
|
||||
/// </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.</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)
|
||||
{
|
||||
if (crop && camera == null) throw new ArgumentException("Cannot crop without camera.");
|
||||
Camera = camera;
|
||||
if (crop && camera == null) camera = Configuration.Camera2D;
|
||||
this.camera = camera;
|
||||
if (crop)
|
||||
{
|
||||
scissorRasterizer = new RasterizerState();
|
||||
scissorRasterizer.ScissorTestEnable = true;
|
||||
scissorBounds = new Rectangle();
|
||||
}
|
||||
@@ -46,7 +48,7 @@ namespace RecrownedAthenaeum.UI.Modular
|
||||
if (scissorBounds != null)
|
||||
{
|
||||
batch.End();
|
||||
batch.Begin(SpriteSortMode.Deferred, null, null, null, scissorRasterizer, null, Camera?.Matrix);
|
||||
batch.Begin(SpriteSortMode.Deferred, null, null, null, scissorRasterizer, null, camera?.Matrix);
|
||||
scissorBounds.Width = bounds.Width;
|
||||
scissorBounds.Height = bounds.Height;
|
||||
scissorBounds.X = bounds.X;
|
||||
@@ -70,7 +72,7 @@ namespace RecrownedAthenaeum.UI.Modular
|
||||
{
|
||||
batch.GraphicsDevice.ScissorRectangle = scissorBounds;
|
||||
batch.End();
|
||||
batch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, Camera?.Matrix);
|
||||
batch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, camera?.Matrix);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -116,7 +116,7 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
||||
/// <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)
|
||||
{
|
||||
if (graphicsDevice == null) graphicsDevice = Configuration.graphicsDeviceManager.GraphicsDevice;
|
||||
if (graphicsDevice == null) graphicsDevice = Configuration.GraphicsDeviceManager.GraphicsDevice;
|
||||
action = Action.LOAD;
|
||||
this.graphicsDevice = graphicsDevice;
|
||||
this.selectedSkinPath = path;
|
||||
|
Reference in New Issue
Block a user