recrownedathenaeum/RecrownedAthenaeum/UI/Modular/UIModule.cs

87 lines
2.8 KiB
C#
Raw Normal View History

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using RecrownedAthenaeum.Input;
using System;
namespace RecrownedAthenaeum.UI.Modular
{
public class UIModule : IInputListener
{
public Rectangle bounds;
public Vector2 origin;
public UIModuleGroup Parent;
public string Name;
public Color color = Color.White;
2019-01-14 05:23:03 +00:00
/// <summary>
/// Called every frame to update this module. Calculations and movement should go here.
/// </summary>
/// <param name="gameTime">Game time information.</param>
public virtual void Update(GameTime gameTime)
{
2019-01-14 05:23:03 +00:00
}
2019-01-14 05:23:03 +00:00
/// <summary>
/// Called every frame to draw this module. Anything that needs to be drawn should go here.
/// </summary>
/// <param name="batch">Batch used to draw.</param>
public virtual void Draw(SpriteBatch batch)
{
}
2019-01-14 05:23:03 +00:00
/// <summary>
/// Converts the given rectangle to the coordinates of the parent.
/// </summary>
/// <param name="rectangle">Rectangle to convert.</param>
/// <returns></returns>
public Rectangle ConvertToParentCoordinates(Rectangle rectangle)
{
if (Parent != null)
{
2019-01-14 05:23:03 +00:00
Rectangle parentHitbox = Parent.ConvertToParentCoordinates(rectangle);
int tX = rectangle.X + parentHitbox.X;
int tY = rectangle.Y + parentHitbox.Y;
return new Rectangle(tX, tY, rectangle.Width, rectangle.Height);
} else
{
2019-01-14 05:23:03 +00:00
return rectangle;
}
}
2019-01-14 05:23:03 +00:00
/// <summary>
/// Removes this module from the parent.
/// </summary>
public void RemoveFromParent()
{
if (Parent == null)
{
throw new InvalidOperationException("Parent is null.");
}
Parent.RemoveModule(this);
}
/// <summary>
/// Called whenever the keyboard state is changed.
/// </summary>
/// <param name="state">The current keyboard state.</param>
/// <returns>Returning whether or not to continue to call the next listener.</returns>
public virtual bool KeyboardStateChanged(KeyboardState state)
{
return true;
}
/// <summary>
/// Called whenever the state of the mouse changes. This includes movement.
/// </summary>
/// <param name="state">The current state of the mouse.</param>
/// <returns>Returning whether or not to continue to call the next listener.</returns>
public virtual bool MouseStateChanged(MouseState state)
{
return true;
}
}
}