Přidány základy uživatelského rozhraní a testovací textury. Aktualizovaná Monogame library pro podporu myši
This commit is contained in:
parent
4561e254d4
commit
b968b12090
9 changed files with 184 additions and 11 deletions
40
FNAF_Clone/GUI/UIElement.cs
Normal file
40
FNAF_Clone/GUI/UIElement.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using MonoGameLibrary.Graphics;
|
||||
using MonoGameLibrary.Input;
|
||||
|
||||
namespace FNAF_Clone.GUI;
|
||||
|
||||
public class UIElement {
|
||||
public bool Active { get; set; } = false;
|
||||
public bool Pressable { get; set; } = false;
|
||||
|
||||
private (Point, Point) bounds; // TODO: Change this to support non-rectangular hitboxes
|
||||
private TextureRegion texture;
|
||||
|
||||
public UIElement(TextureRegion texture, Point position) {
|
||||
this.texture = texture;
|
||||
bounds = (position, position + new Point(texture.Width, texture.Height));
|
||||
}
|
||||
public void Update() {
|
||||
|
||||
}
|
||||
|
||||
public bool IsWithinBounds(Point pos) {
|
||||
return pos.X >= Math.Min(bounds.Item1.X, bounds.Item2.X) && pos.X <= Math.Max(bounds.Item1.X, bounds.Item2.X) &&
|
||||
pos.Y >= Math.Min(bounds.Item1.Y, bounds.Item2.Y) && pos.Y <= Math.Max(bounds.Item1.Y, bounds.Item2.Y);
|
||||
}
|
||||
|
||||
public Action OnMousePress{ get; set; }
|
||||
|
||||
// public virtual void OnMousePress() { }
|
||||
|
||||
public virtual void OnMouseRelease() { }
|
||||
|
||||
public virtual void OnMouseHold() { }
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch) {
|
||||
texture.Draw(spriteBatch, bounds.Item1.ToVector2(), Color.White);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue