documentation.
This commit is contained in:
@@ -6,6 +6,9 @@ using System.Linq;
|
||||
|
||||
namespace RecrownedAthenaeum.UI.Book
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains the pages.
|
||||
/// </summary>
|
||||
public class Book
|
||||
{
|
||||
Camera2D camera;
|
||||
@@ -25,6 +28,10 @@ namespace RecrownedAthenaeum.UI.Book
|
||||
this.dimensions = dimensions;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws the pages.
|
||||
/// </summary>
|
||||
/// <param name="batch">Batch used to draw.</param>
|
||||
public void Draw(SpriteBatch batch)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
RemovePage(page.Name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the page.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of page to remove.</param>
|
||||
public void RemovePage(string 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)
|
||||
{
|
||||
targetPage = page;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Goes to page instantly.
|
||||
/// </summary>
|
||||
/// <param name="page">Page to go to.</param>
|
||||
public void GoToPage(Page page)
|
||||
{
|
||||
Rectangle targetBounds = page.bounds;
|
||||
|
@@ -5,57 +5,64 @@ using System;
|
||||
|
||||
namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a texture with more information.
|
||||
/// </summary>
|
||||
public class Image : UIModule, ISpecialDrawable
|
||||
{
|
||||
/// <summary>
|
||||
/// The rotation of the image.
|
||||
/// </summary>
|
||||
public float rotation = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// The texture to be rendered.
|
||||
/// </summary>
|
||||
public Texture2D Texture { get; set; }
|
||||
public float ScaleX
|
||||
{
|
||||
get
|
||||
{
|
||||
return (float)bounds.Width / Texture.Width;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scale of of the X axis.
|
||||
/// </summary>
|
||||
public float ScaleX { get { return (float)bounds.Width / Texture.Width; } set { bounds.Width = (int)(Texture.Width * value); } }
|
||||
|
||||
set
|
||||
{
|
||||
bounds.Width = (int)(Texture.Width * value);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Scale of the Y axis.
|
||||
/// </summary>
|
||||
public float ScaleY { get { return (float)bounds.Height / Texture.Height; } set { bounds.Height = (int)(Texture.Height * value); } }
|
||||
|
||||
public float ScaleY
|
||||
{
|
||||
get
|
||||
{
|
||||
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>
|
||||
/// Overall scale.
|
||||
/// </summary>
|
||||
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)
|
||||
{
|
||||
Texture = texture ?? throw new ArgumentException("Image requires a texture.");
|
||||
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)
|
||||
{
|
||||
batch.Draw(Texture, bounds, null, color, rotation, origin, SpriteEffects.None, 0f);
|
||||
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))
|
||||
{
|
||||
this.color = color;
|
||||
|
@@ -6,17 +6,40 @@ using RecrownedAthenaeum.UI.Skin.Definitions;
|
||||
|
||||
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
|
||||
{
|
||||
private ButtonSkinDefinition skinDefinition;
|
||||
private ISpecialDrawable downTexture, upTexture, highlightedTexture, disabledTexture;
|
||||
/// <summary>
|
||||
/// Click event listeners.
|
||||
/// </summary>
|
||||
public event Clicked Listeners;
|
||||
private bool pressed;
|
||||
/// <summary>
|
||||
/// Whether or not this button should be currently disabled.
|
||||
/// </summary>
|
||||
public bool disabled = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not this button is currently being hovered on.
|
||||
/// </summary>
|
||||
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)
|
||||
{
|
||||
this.downTexture = down;
|
||||
@@ -25,6 +48,11 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
||||
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)
|
||||
{
|
||||
this.skinDefinition = skin.ObtainDefinition<ButtonSkinDefinition>(definitionName, GetType());
|
||||
@@ -34,6 +62,10 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
||||
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)
|
||||
{
|
||||
if (disabled)
|
||||
@@ -54,6 +86,11 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
||||
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)
|
||||
{
|
||||
if (InputUtilities.MouseWithinBoundries(bounds))
|
||||
@@ -81,12 +118,17 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
||||
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)
|
||||
{
|
||||
return base.KeyboardStateChanged(state);
|
||||
}
|
||||
|
||||
protected void OnClick()
|
||||
internal void OnClick()
|
||||
{
|
||||
Listeners?.Invoke();
|
||||
}
|
||||
|
@@ -6,12 +6,34 @@ using System;
|
||||
|
||||
namespace RecrownedAthenaeum.UI.Modular
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Module for UI layout.
|
||||
/// </summary>
|
||||
public class UIModule : IInputListener
|
||||
{
|
||||
/// <summary>
|
||||
/// Bounds of this module.
|
||||
/// </summary>
|
||||
public Rectangle bounds;
|
||||
/// <summary>
|
||||
/// Origin of this module.
|
||||
/// </summary>
|
||||
public Vector2 origin;
|
||||
|
||||
/// <summary>
|
||||
/// The parent of this module. May be null.
|
||||
/// </summary>
|
||||
public UIModuleGroup Parent;
|
||||
|
||||
/// <summary>
|
||||
/// Name of this module. For organizational/referencial purposes mostly.
|
||||
/// </summary>
|
||||
public string Name;
|
||||
|
||||
/// <summary>
|
||||
/// The color tint of this module.
|
||||
/// </summary>
|
||||
public Color color = Color.White;
|
||||
|
||||
/// <summary>
|
||||
|
@@ -7,6 +7,10 @@ using RecrownedAthenaeum.Camera;
|
||||
|
||||
namespace RecrownedAthenaeum.UI.Modular
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Contains a group of modules and has its own relative coordinate system.
|
||||
/// </summary>
|
||||
public class UIModuleGroup : 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
foreach (UIModule module in modules)
|
||||
@@ -92,6 +104,11 @@ namespace RecrownedAthenaeum.UI.Modular
|
||||
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)
|
||||
{
|
||||
foreach (UIModule module in modules)
|
||||
@@ -101,6 +118,11 @@ namespace RecrownedAthenaeum.UI.Modular
|
||||
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)
|
||||
{
|
||||
foreach (UIModule module in modules)
|
||||
|
@@ -3,11 +3,24 @@ using System;
|
||||
|
||||
namespace RecrownedAthenaeum.UI.Skin.Definitions
|
||||
{
|
||||
/// <summary>
|
||||
/// Definition for a button.
|
||||
/// </summary>
|
||||
public class ButtonSkinDefinition : ISkinDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// Names for the regions in the texture atlas respectively.
|
||||
/// </summary>
|
||||
public string upRegion, downRegion, disabledRegion, selectedRegion;
|
||||
|
||||
///<inheritDoc/>
|
||||
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)
|
||||
{
|
||||
this.downRegion = downRegion;
|
||||
|
@@ -2,8 +2,14 @@
|
||||
|
||||
namespace RecrownedAthenaeum.UI.Skin.Definitions
|
||||
{
|
||||
/// <summary>
|
||||
/// A definition for the skin system.
|
||||
/// </summary>
|
||||
public interface ISkinDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// The module type this definition is definining.
|
||||
/// </summary>
|
||||
Type UIModuleType { get; }
|
||||
}
|
||||
}
|
||||
|
@@ -7,13 +7,29 @@ using System.Collections.Generic;
|
||||
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// Texture atlas containing the skins textures.
|
||||
/// </summary>
|
||||
public readonly TextureAtlas textureAtlas;
|
||||
/// <summary>
|
||||
/// Colors stored in this skin.
|
||||
/// </summary>
|
||||
public readonly Dictionary<string, Color> colors;
|
||||
/// <summary>
|
||||
/// Fonts stored in this skin.
|
||||
/// </summary>
|
||||
public readonly Dictionary<string, SpriteFont> fonts;
|
||||
Dictionary<Type, Dictionary<string, ISkinDefinition>> definitions;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="textureAtlas"></param>
|
||||
public Skin(TextureAtlas textureAtlas)
|
||||
{
|
||||
this.textureAtlas = textureAtlas;
|
||||
|
Reference in New Issue
Block a user