documentation.
This commit is contained in:
parent
32c2f25196
commit
40c7772559
@ -29,6 +29,7 @@
|
|||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<DocumentationFile>bin\Release\RecrownedAthenaeum.Pipeline.xml</DocumentationFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="MonoGame.Framework, Version=3.7.0.1708, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="MonoGame.Framework, Version=3.7.0.1708, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
@ -4,13 +4,32 @@ using System;
|
|||||||
|
|
||||||
namespace RecrownedAthenaeum.Camera
|
namespace RecrownedAthenaeum.Camera
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A virtual 2D camera.
|
||||||
|
/// </summary>
|
||||||
public class Camera2D
|
public class Camera2D
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Current zoom level.
|
||||||
|
/// </summary>
|
||||||
public float Zoom;
|
public float Zoom;
|
||||||
public Vector2 Position;
|
|
||||||
public Matrix Matrix { get; private set; }
|
|
||||||
public GraphicsDevice graphicsDevice;
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Current position in the world.
|
||||||
|
/// </summary>
|
||||||
|
public Vector2 Position;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The matrix representing the zoom and position.
|
||||||
|
/// </summary>
|
||||||
|
public Matrix Matrix { get; private set; }
|
||||||
|
|
||||||
|
private GraphicsDevice graphicsDevice;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructs 2D camera.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="graphicsDevice">The graphics device to use.</param>
|
||||||
public Camera2D(GraphicsDevice graphicsDevice)
|
public Camera2D(GraphicsDevice graphicsDevice)
|
||||||
{
|
{
|
||||||
this.graphicsDevice = graphicsDevice;
|
this.graphicsDevice = graphicsDevice;
|
||||||
@ -19,6 +38,9 @@ namespace RecrownedAthenaeum.Camera
|
|||||||
Position.Y = this.graphicsDevice.Viewport.Height * 0.5f;
|
Position.Y = this.graphicsDevice.Viewport.Height * 0.5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Applies any changes made to the properties of this camera and updates to new dimensions of viewport specified by the graphics device.
|
||||||
|
/// </summary>
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
Rectangle bounds = graphicsDevice.Viewport.Bounds;
|
Rectangle bounds = graphicsDevice.Viewport.Bounds;
|
||||||
@ -28,6 +50,12 @@ namespace RecrownedAthenaeum.Camera
|
|||||||
Matrix.CreateTranslation(new Vector3(bounds.Width * 0.5f, bounds.Height * 0.5f, 0f));
|
Matrix.CreateTranslation(new Vector3(bounds.Width * 0.5f, bounds.Height * 0.5f, 0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Lerps to the given position.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="alpha">The multiplier for difference in distance.</param>
|
||||||
|
/// <param name="targetPosition">The target position to lerp to.</param>
|
||||||
|
/// <param name="delta">Time between this frame and the previous frame.</param>
|
||||||
public void LinearInterpolationToPosition(float alpha, Vector2 targetPosition, float delta)
|
public void LinearInterpolationToPosition(float alpha, Vector2 targetPosition, float delta)
|
||||||
{
|
{
|
||||||
if (alpha <= 0 && alpha > 1f) throw new ArgumentException("Alpha can't be greater than 1f, less than or equal to 0.");
|
if (alpha <= 0 && alpha > 1f) throw new ArgumentException("Alpha can't be greater than 1f, less than or equal to 0.");
|
||||||
|
@ -6,16 +6,36 @@ using System.Threading;
|
|||||||
|
|
||||||
namespace RecrownedAthenaeum.ContentSystem
|
namespace RecrownedAthenaeum.ContentSystem
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Wrapper for the content manager that helps with controlling it by adding automated multithreaded content loading.
|
||||||
|
/// </summary>
|
||||||
public class ContentManagerController
|
public class ContentManagerController
|
||||||
{
|
{
|
||||||
Thread thread;
|
Thread thread;
|
||||||
readonly ContentManager contentManager;
|
readonly ContentManager contentManager;
|
||||||
readonly Queue<LoadableContent> queue;
|
readonly Queue<LoadableContent> queue;
|
||||||
Dictionary<string, IDisposable> assets;
|
Dictionary<string, IDisposable> assets;
|
||||||
|
/// <summary>
|
||||||
|
/// Path modifiers to change the path in which the content manager looks to load a file. Used for better organizing things while not needing to type entire path.
|
||||||
|
/// </summary>
|
||||||
public readonly Dictionary<Type, IContentPathModifier> contentPathModifier;
|
public readonly Dictionary<Type, IContentPathModifier> contentPathModifier;
|
||||||
volatile float progress;
|
volatile float progress;
|
||||||
volatile bool running;
|
volatile bool running;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether or not the queue is empty and all content is loaded.
|
||||||
|
/// </summary>
|
||||||
|
public bool Done { get { return !running && queue.Count == 0; } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The progress of the loading. 1 is complete while 0 is incomplete.
|
||||||
|
/// </summary>
|
||||||
|
public float Progress { get { return progress; } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Wraps the <see cref="ContentManager"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="contentManager">The manager to wrap.</param>
|
||||||
public ContentManagerController(ContentManager contentManager)
|
public ContentManagerController(ContentManager contentManager)
|
||||||
{
|
{
|
||||||
this.contentManager = contentManager;
|
this.contentManager = contentManager;
|
||||||
@ -38,6 +58,12 @@ namespace RecrownedAthenaeum.ContentSystem
|
|||||||
Debug.WriteLine("Loaded asset: " + assetName);
|
Debug.WriteLine("Loaded asset: " + assetName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the requested asset.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type of the asset for an alternative way to cast.</typeparam>
|
||||||
|
/// <param name="assetName">The name of the asset.</param>
|
||||||
|
/// <returns>The asset casted to the type given with T.</returns>
|
||||||
public T Get<T>(string assetName)
|
public T Get<T>(string assetName)
|
||||||
{
|
{
|
||||||
lock (queue)
|
lock (queue)
|
||||||
@ -46,6 +72,12 @@ namespace RecrownedAthenaeum.ContentSystem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Queues an asset to be loaded.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type of the asset to be queued.</typeparam>
|
||||||
|
/// <param name="assetName">Name of asset to look for.</param>
|
||||||
|
/// <param name="usePathModifier">Whether or not to use the path modifiers.</param>
|
||||||
public void Queue<T>(string assetName, bool usePathModifier = true) where T : IDisposable
|
public void Queue<T>(string assetName, bool usePathModifier = true) where T : IDisposable
|
||||||
{
|
{
|
||||||
lock (queue)
|
lock (queue)
|
||||||
@ -133,20 +165,6 @@ namespace RecrownedAthenaeum.ContentSystem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Done
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return !running && queue.Count == 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public float Progress
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return progress;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
namespace RecrownedAthenaeum.ContentSystem
|
namespace RecrownedAthenaeum.ContentSystem
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Modifies the given path based on a name. Used to simplify long paths for the <see cref="ContentManagerController"/>
|
||||||
|
/// </summary>
|
||||||
public interface IContentPathModifier
|
public interface IContentPathModifier
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -2,10 +2,23 @@
|
|||||||
|
|
||||||
namespace RecrownedAthenaeum.Input
|
namespace RecrownedAthenaeum.Input
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Input listener for <see cref="InputUtilities"/>.
|
||||||
|
/// </summary>
|
||||||
public interface IInputListener
|
public interface IInputListener
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Called when the state of the keyboard has changed.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="state">The new state.</param>
|
||||||
|
/// <returns>True to continue calling other listeners.</returns>
|
||||||
bool KeyboardStateChanged(KeyboardState state);
|
bool KeyboardStateChanged(KeyboardState state);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when the state of the mouse has changed.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="state">The new state.</param>
|
||||||
|
/// <returns>True to continue calling other listeners.</returns>
|
||||||
bool MouseStateChanged(MouseState state);
|
bool MouseStateChanged(MouseState state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<DocumentationFile>bin\Release\RecrownedAthenaeum.xml</DocumentationFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="MonoGame.Framework, Version=3.7.1.189, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="MonoGame.Framework, Version=3.7.1.189, Culture=neutral, processorArchitecture=MSIL">
|
||||||
|
@ -5,23 +5,42 @@ using System;
|
|||||||
|
|
||||||
namespace RecrownedAthenaeum.Render
|
namespace RecrownedAthenaeum.Render
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Renders rectangles using the <see cref="PrimitiveBatch"/>.
|
||||||
|
/// </summary>
|
||||||
public class RectangleRenderer : IDisposable
|
public class RectangleRenderer : IDisposable
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The <see cref="PrimitiveBatch"/> used.
|
||||||
|
/// </summary>
|
||||||
public readonly PrimitiveBatch primitiveBatch;
|
public readonly PrimitiveBatch primitiveBatch;
|
||||||
private bool disposed;
|
private bool disposed;
|
||||||
private bool began;
|
private bool began;
|
||||||
private bool filling;
|
private bool filling;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a rectangle renderer with the given <see cref="PrimitiveBatch"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="primitiveBatch"></param>
|
||||||
public RectangleRenderer(PrimitiveBatch primitiveBatch)
|
public RectangleRenderer(PrimitiveBatch primitiveBatch)
|
||||||
{
|
{
|
||||||
this.primitiveBatch = primitiveBatch;
|
this.primitiveBatch = primitiveBatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a rectangle renderer.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="graphicsDevice">The graphics device used to create the <see cref="PrimitiveBatch"/></param>
|
||||||
|
/// <param name="camera">The camera containing the matrix to be used for the transformations.</param>
|
||||||
public RectangleRenderer(GraphicsDevice graphicsDevice, Camera2D camera) : this(new PrimitiveBatch(graphicsDevice, camera, 4))
|
public RectangleRenderer(GraphicsDevice graphicsDevice, Camera2D camera) : this(new PrimitiveBatch(graphicsDevice, camera, 4))
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Begins the render batch.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filled">Whether or not to fill the rectangle.</param>
|
||||||
public void Begin(bool filled)
|
public void Begin(bool filled)
|
||||||
{
|
{
|
||||||
filling = filled;
|
filling = filled;
|
||||||
@ -31,6 +50,9 @@ namespace RecrownedAthenaeum.Render
|
|||||||
began = true;
|
began = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ends the batch.
|
||||||
|
/// </summary>
|
||||||
public void End()
|
public void End()
|
||||||
{
|
{
|
||||||
if (disposed) throw new ObjectDisposedException(GetType().Name);
|
if (disposed) throw new ObjectDisposedException(GetType().Name);
|
||||||
@ -77,25 +99,39 @@ namespace RecrownedAthenaeum.Render
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attempts to dispose of this object.
|
||||||
|
/// </summary>
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
if (disposed) throw new ObjectDisposedException(typeof(PrimitiveBatch).Name);
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose(bool disposing)
|
/// <summary>
|
||||||
|
/// An overridable of disposable.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">Only true when called by user code dispose. Destructor calling this results in false.</param>
|
||||||
|
public virtual void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
|
disposed = true;
|
||||||
if (!disposed && disposing)
|
if (!disposed && disposing)
|
||||||
{
|
{
|
||||||
|
disposed = true;
|
||||||
if (primitiveBatch != null)
|
if (primitiveBatch != null)
|
||||||
{
|
{
|
||||||
primitiveBatch.Dispose();
|
primitiveBatch.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
|
||||||
if (disposed) throw new ObjectDisposedException(typeof(PrimitiveBatch).Name);
|
/// <summary>
|
||||||
}
|
/// Destructor.
|
||||||
|
/// </summary>
|
||||||
|
~RectangleRenderer ()
|
||||||
|
{
|
||||||
|
Dispose(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,9 @@ using System.Linq;
|
|||||||
|
|
||||||
namespace RecrownedAthenaeum.UI.Book
|
namespace RecrownedAthenaeum.UI.Book
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains the pages.
|
||||||
|
/// </summary>
|
||||||
public class Book
|
public class Book
|
||||||
{
|
{
|
||||||
Camera2D camera;
|
Camera2D camera;
|
||||||
@ -25,6 +28,10 @@ namespace RecrownedAthenaeum.UI.Book
|
|||||||
this.dimensions = dimensions;
|
this.dimensions = dimensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Draws the pages.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="batch">Batch used to draw.</param>
|
||||||
public void Draw(SpriteBatch batch)
|
public void Draw(SpriteBatch batch)
|
||||||
{
|
{
|
||||||
for (int pageIndex = 0; pageIndex < pages.Count; pageIndex++)
|
for (int pageIndex = 0; pageIndex < pages.Count; pageIndex++)
|
||||||
@ -34,6 +41,10 @@ namespace RecrownedAthenaeum.UI.Book
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the book.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="gameTime">Snapshot of information of the game time.</param>
|
||||||
public void Update(GameTime gameTime)
|
public void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
if (targetPage != null)
|
if (targetPage != null)
|
||||||
@ -57,6 +68,10 @@ namespace RecrownedAthenaeum.UI.Book
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds the page(s).
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pages">The page(s) to add.</param>
|
||||||
public void AddPages(params Page[] pages)
|
public void AddPages(params Page[] pages)
|
||||||
{
|
{
|
||||||
foreach (Page page in pages)
|
foreach (Page page in pages)
|
||||||
@ -65,21 +80,37 @@ namespace RecrownedAthenaeum.UI.Book
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes the page.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="page">Page to remove.</param>
|
||||||
public void RemovePage(Page page)
|
public void RemovePage(Page page)
|
||||||
{
|
{
|
||||||
RemovePage(page.Name);
|
RemovePage(page.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes the page.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Name of page to remove.</param>
|
||||||
public void RemovePage(string name)
|
public void RemovePage(string name)
|
||||||
{
|
{
|
||||||
pages.Remove(name);
|
pages.Remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Perform a step of linear interpolation to the given page.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="page">The page to lerp to.</param>
|
||||||
public void LerpToPage(Page page)
|
public void LerpToPage(Page page)
|
||||||
{
|
{
|
||||||
targetPage = page;
|
targetPage = page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Goes to page instantly.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="page">Page to go to.</param>
|
||||||
public void GoToPage(Page page)
|
public void GoToPage(Page page)
|
||||||
{
|
{
|
||||||
Rectangle targetBounds = page.bounds;
|
Rectangle targetBounds = page.bounds;
|
||||||
|
@ -5,57 +5,64 @@ using System;
|
|||||||
|
|
||||||
namespace RecrownedAthenaeum.UI.Modular.Modules
|
namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a texture with more information.
|
||||||
|
/// </summary>
|
||||||
public class Image : UIModule, ISpecialDrawable
|
public class Image : UIModule, ISpecialDrawable
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The rotation of the image.
|
||||||
|
/// </summary>
|
||||||
public float rotation = 0f;
|
public float rotation = 0f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The texture to be rendered.
|
||||||
|
/// </summary>
|
||||||
public Texture2D Texture { get; set; }
|
public Texture2D Texture { get; set; }
|
||||||
public float ScaleX
|
|
||||||
{
|
/// <summary>
|
||||||
get
|
/// Scale of of the X axis.
|
||||||
{
|
/// </summary>
|
||||||
return (float)bounds.Width / Texture.Width;
|
public float ScaleX { get { return (float)bounds.Width / Texture.Width; } set { bounds.Width = (int)(Texture.Width * value); } }
|
||||||
}
|
|
||||||
|
|
||||||
set
|
/// <summary>
|
||||||
{
|
/// Scale of the Y axis.
|
||||||
bounds.Width = (int)(Texture.Width * value);
|
/// </summary>
|
||||||
}
|
public float ScaleY { get { return (float)bounds.Height / Texture.Height; } set { bounds.Height = (int)(Texture.Height * value); } }
|
||||||
}
|
|
||||||
|
|
||||||
public float ScaleY
|
/// <summary>
|
||||||
{
|
/// Overall scale.
|
||||||
get
|
/// </summary>
|
||||||
{
|
public float Scale { set { bounds.Height = (int)(Texture.Height * value); bounds.Width = (int)(Texture.Width * value); } }
|
||||||
return (float)bounds.Height / Texture.Height;
|
|
||||||
}
|
|
||||||
|
|
||||||
set
|
|
||||||
{
|
|
||||||
bounds.Height = (int)(Texture.Height * value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public float Scale
|
|
||||||
{
|
|
||||||
set
|
|
||||||
{
|
|
||||||
bounds.Height = (int)(Texture.Height * value);
|
|
||||||
bounds.Width = (int)(Texture.Width * value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructs an image given a texture.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="texture">Texture to use.</param>
|
||||||
public Image(Texture2D texture)
|
public Image(Texture2D texture)
|
||||||
{
|
{
|
||||||
Texture = texture ?? throw new ArgumentException("Image requires a texture.");
|
Texture = texture ?? throw new ArgumentException("Image requires a texture.");
|
||||||
bounds = texture.Bounds;
|
bounds = texture.Bounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Draws the image with default values.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="batch">The batch to use.</param>
|
||||||
public override void Draw(SpriteBatch batch)
|
public override void Draw(SpriteBatch batch)
|
||||||
{
|
{
|
||||||
batch.Draw(Texture, bounds, null, color, rotation, origin, SpriteEffects.None, 0f);
|
batch.Draw(Texture, bounds, null, color, rotation, origin, SpriteEffects.None, 0f);
|
||||||
base.Draw(batch);
|
base.Draw(batch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Draws the image with more options.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="spriteBatch">Batch used.</param>
|
||||||
|
/// <param name="destination">Where to draw texture to.</param>
|
||||||
|
/// <param name="color">The color tint to use.</param>
|
||||||
|
/// <param name="rotation">Rotation of image.</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(SpriteBatch spriteBatch, Rectangle destination, Color color, float rotation = 0, Vector2 origin = default(Vector2))
|
||||||
{
|
{
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
@ -6,17 +6,40 @@ using RecrownedAthenaeum.UI.Skin.Definitions;
|
|||||||
|
|
||||||
namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
||||||
{
|
{
|
||||||
public delegate bool Clicked();
|
/// <summary>
|
||||||
|
/// Function to be called when button is clicked.
|
||||||
|
/// </summary>
|
||||||
|
public delegate void Clicked();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A very primitive button containing all the basic functions.
|
||||||
|
/// </summary>
|
||||||
public class Button : UIModule
|
public class Button : UIModule
|
||||||
{
|
{
|
||||||
private ButtonSkinDefinition skinDefinition;
|
private ButtonSkinDefinition skinDefinition;
|
||||||
private ISpecialDrawable downTexture, upTexture, highlightedTexture, disabledTexture;
|
private ISpecialDrawable downTexture, upTexture, highlightedTexture, disabledTexture;
|
||||||
|
/// <summary>
|
||||||
|
/// Click event listeners.
|
||||||
|
/// </summary>
|
||||||
public event Clicked Listeners;
|
public event Clicked Listeners;
|
||||||
private bool pressed;
|
private bool pressed;
|
||||||
|
/// <summary>
|
||||||
|
/// Whether or not this button should be currently disabled.
|
||||||
|
/// </summary>
|
||||||
public bool disabled = false;
|
public bool disabled = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether or not this button is currently being hovered on.
|
||||||
|
/// </summary>
|
||||||
public bool Highlighted { get; private set; }
|
public bool Highlighted { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructs this button using <see cref="ISpecialDrawable"/>s for the different states it could be in.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="down">Button being pressed.</param>
|
||||||
|
/// <param name="up">Button not being pressed.</param>
|
||||||
|
/// <param name="disabled">Disabled button.</param>
|
||||||
|
/// <param name="selected">Button being highlighted.</param>
|
||||||
public Button(ISpecialDrawable down, ISpecialDrawable up, ISpecialDrawable disabled = null, ISpecialDrawable selected = null)
|
public Button(ISpecialDrawable down, ISpecialDrawable up, ISpecialDrawable disabled = null, ISpecialDrawable selected = null)
|
||||||
{
|
{
|
||||||
this.downTexture = down;
|
this.downTexture = down;
|
||||||
@ -25,6 +48,11 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
|||||||
this.highlightedTexture = selected;
|
this.highlightedTexture = selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructs this button using the skin system.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="skin">The skin containing the information of the textures and design to follow.</param>
|
||||||
|
/// <param name="definitionName">The name of the definition in the skin. Can be null to select the default.</param>
|
||||||
public Button(Skin.Skin skin, string definitionName = null)
|
public Button(Skin.Skin skin, string definitionName = null)
|
||||||
{
|
{
|
||||||
this.skinDefinition = skin.ObtainDefinition<ButtonSkinDefinition>(definitionName, GetType());
|
this.skinDefinition = skin.ObtainDefinition<ButtonSkinDefinition>(definitionName, GetType());
|
||||||
@ -34,6 +62,10 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
|||||||
highlightedTexture = skin.textureAtlas[skinDefinition.selectedRegion];
|
highlightedTexture = skin.textureAtlas[skinDefinition.selectedRegion];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Draws the button.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="batch">Batch used to draw the button.</param>
|
||||||
public override void Draw(SpriteBatch batch)
|
public override void Draw(SpriteBatch batch)
|
||||||
{
|
{
|
||||||
if (disabled)
|
if (disabled)
|
||||||
@ -54,6 +86,11 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
|||||||
base.Draw(batch);
|
base.Draw(batch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when the mouse changes state.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="state">The new state.</param>
|
||||||
|
/// <returns>Whether or not to continue calling the next mouse change listener.</returns>
|
||||||
public sealed override bool MouseStateChanged(MouseState state)
|
public sealed override bool MouseStateChanged(MouseState state)
|
||||||
{
|
{
|
||||||
if (InputUtilities.MouseWithinBoundries(bounds))
|
if (InputUtilities.MouseWithinBoundries(bounds))
|
||||||
@ -81,12 +118,17 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
|||||||
return base.MouseStateChanged(state);
|
return base.MouseStateChanged(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when the state of the keyboard changes.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="state">The new state.</param>
|
||||||
|
/// <returns>Whether or not the next keyboard change listener should be called.</returns>
|
||||||
public sealed override bool KeyboardStateChanged(KeyboardState state)
|
public sealed override bool KeyboardStateChanged(KeyboardState state)
|
||||||
{
|
{
|
||||||
return base.KeyboardStateChanged(state);
|
return base.KeyboardStateChanged(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void OnClick()
|
internal void OnClick()
|
||||||
{
|
{
|
||||||
Listeners?.Invoke();
|
Listeners?.Invoke();
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,34 @@ using System;
|
|||||||
|
|
||||||
namespace RecrownedAthenaeum.UI.Modular
|
namespace RecrownedAthenaeum.UI.Modular
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Module for UI layout.
|
||||||
|
/// </summary>
|
||||||
public class UIModule : IInputListener
|
public class UIModule : IInputListener
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Bounds of this module.
|
||||||
|
/// </summary>
|
||||||
public Rectangle bounds;
|
public Rectangle bounds;
|
||||||
|
/// <summary>
|
||||||
|
/// Origin of this module.
|
||||||
|
/// </summary>
|
||||||
public Vector2 origin;
|
public Vector2 origin;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The parent of this module. May be null.
|
||||||
|
/// </summary>
|
||||||
public UIModuleGroup Parent;
|
public UIModuleGroup Parent;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Name of this module. For organizational/referencial purposes mostly.
|
||||||
|
/// </summary>
|
||||||
public string Name;
|
public string Name;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The color tint of this module.
|
||||||
|
/// </summary>
|
||||||
public Color color = Color.White;
|
public Color color = Color.White;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -7,6 +7,10 @@ using RecrownedAthenaeum.Camera;
|
|||||||
|
|
||||||
namespace RecrownedAthenaeum.UI.Modular
|
namespace RecrownedAthenaeum.UI.Modular
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Contains a group of modules and has its own relative coordinate system.
|
||||||
|
/// </summary>
|
||||||
public class UIModuleGroup : UIModule
|
public class UIModuleGroup : UIModule
|
||||||
{
|
{
|
||||||
List<UIModule> modules = new List<UIModule>();
|
List<UIModule> modules = new List<UIModule>();
|
||||||
@ -24,6 +28,10 @@ namespace RecrownedAthenaeum.UI.Modular
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Draws this group of modules.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="batch">Batch used to draw the group.</param>
|
||||||
public override void Draw(SpriteBatch batch)
|
public override void Draw(SpriteBatch batch)
|
||||||
{
|
{
|
||||||
if (scissorBounds != null)
|
if (scissorBounds != null)
|
||||||
@ -57,6 +65,10 @@ namespace RecrownedAthenaeum.UI.Modular
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the group of modules.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="gameTime">Game time used.</param>
|
||||||
public override void Update(GameTime gameTime)
|
public override void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
foreach (UIModule module in modules)
|
foreach (UIModule module in modules)
|
||||||
@ -92,6 +104,11 @@ namespace RecrownedAthenaeum.UI.Modular
|
|||||||
modules.Remove(module);
|
modules.Remove(module);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the keyboard state of the modules in this group.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="state">The new state.</param>
|
||||||
|
/// <returns>Whether or not to continue updating the other listeners.</returns>
|
||||||
public override bool KeyboardStateChanged(KeyboardState state)
|
public override bool KeyboardStateChanged(KeyboardState state)
|
||||||
{
|
{
|
||||||
foreach (UIModule module in modules)
|
foreach (UIModule module in modules)
|
||||||
@ -101,6 +118,11 @@ namespace RecrownedAthenaeum.UI.Modular
|
|||||||
return base.KeyboardStateChanged(state);
|
return base.KeyboardStateChanged(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the moues state of the modules in this group.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="state">The new state.</param>
|
||||||
|
/// <returns>Whether or not to continue updating other listeners.</returns>
|
||||||
public override bool MouseStateChanged(MouseState state)
|
public override bool MouseStateChanged(MouseState state)
|
||||||
{
|
{
|
||||||
foreach (UIModule module in modules)
|
foreach (UIModule module in modules)
|
||||||
|
@ -3,11 +3,24 @@ using System;
|
|||||||
|
|
||||||
namespace RecrownedAthenaeum.UI.Skin.Definitions
|
namespace RecrownedAthenaeum.UI.Skin.Definitions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Definition for a button.
|
||||||
|
/// </summary>
|
||||||
public class ButtonSkinDefinition : ISkinDefinition
|
public class ButtonSkinDefinition : ISkinDefinition
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Names for the regions in the texture atlas respectively.
|
||||||
|
/// </summary>
|
||||||
public string upRegion, downRegion, disabledRegion, selectedRegion;
|
public string upRegion, downRegion, disabledRegion, selectedRegion;
|
||||||
|
|
||||||
|
///<inheritDoc/>
|
||||||
public Type UIModuleType { get { return typeof(Button); } }
|
public Type UIModuleType { get { return typeof(Button); } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructs the definition with minimum requirements.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="downRegion">Name of region specifying the texture shown for when the button is pressed down.</param>
|
||||||
|
/// <param name="upRegion">Name of region specifying the texture shown for when the button is not pressed.</param>
|
||||||
public ButtonSkinDefinition(string downRegion, string upRegion)
|
public ButtonSkinDefinition(string downRegion, string upRegion)
|
||||||
{
|
{
|
||||||
this.downRegion = downRegion;
|
this.downRegion = downRegion;
|
||||||
|
@ -2,8 +2,14 @@
|
|||||||
|
|
||||||
namespace RecrownedAthenaeum.UI.Skin.Definitions
|
namespace RecrownedAthenaeum.UI.Skin.Definitions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A definition for the skin system.
|
||||||
|
/// </summary>
|
||||||
public interface ISkinDefinition
|
public interface ISkinDefinition
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The module type this definition is definining.
|
||||||
|
/// </summary>
|
||||||
Type UIModuleType { get; }
|
Type UIModuleType { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,29 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace RecrownedAthenaeum.UI.Skin
|
namespace RecrownedAthenaeum.UI.Skin
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A skin is used to group a theme which can then be applied to the UI via the use of modules.
|
||||||
|
/// </summary>
|
||||||
public class Skin
|
public class Skin
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Texture atlas containing the skins textures.
|
||||||
|
/// </summary>
|
||||||
public readonly TextureAtlas textureAtlas;
|
public readonly TextureAtlas textureAtlas;
|
||||||
|
/// <summary>
|
||||||
|
/// Colors stored in this skin.
|
||||||
|
/// </summary>
|
||||||
public readonly Dictionary<string, Color> colors;
|
public readonly Dictionary<string, Color> colors;
|
||||||
|
/// <summary>
|
||||||
|
/// Fonts stored in this skin.
|
||||||
|
/// </summary>
|
||||||
public readonly Dictionary<string, SpriteFont> fonts;
|
public readonly Dictionary<string, SpriteFont> fonts;
|
||||||
Dictionary<Type, Dictionary<string, ISkinDefinition>> definitions;
|
Dictionary<Type, Dictionary<string, ISkinDefinition>> definitions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="textureAtlas"></param>
|
||||||
public Skin(TextureAtlas textureAtlas)
|
public Skin(TextureAtlas textureAtlas)
|
||||||
{
|
{
|
||||||
this.textureAtlas = textureAtlas;
|
this.textureAtlas = textureAtlas;
|
||||||
|
Loading…
Reference in New Issue
Block a user