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; /// /// Called every frame to update this module. Calculations and movement should go here. /// /// Game time information. public virtual void Update(GameTime gameTime) { } /// /// Called every frame to draw this module. Anything that needs to be drawn should go here. /// /// Batch used to draw. public virtual void Draw(SpriteBatch batch) { } /// /// Converts the given rectangle to the coordinates of the parent. /// /// Rectangle to convert. /// public Rectangle ConvertToParentCoordinates(Rectangle rectangle) { if (Parent != null) { 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 { return rectangle; } } /// /// Removes this module from the parent. /// public void RemoveFromParent() { if (Parent == null) { throw new InvalidOperationException("Parent is null."); } Parent.RemoveModule(this); } /// /// Called whenever the keyboard state is changed. /// /// The current keyboard state. /// Returning whether or not to continue to call the next listener. public virtual bool KeyboardStateChanged(KeyboardState state) { return true; } /// /// Called whenever the state of the mouse changes. This includes movement. /// /// The current state of the mouse. /// Returning whether or not to continue to call the next listener. public virtual bool MouseStateChanged(MouseState state) { return true; } } }