2026-01-15 19:56:50 +01:00
|
|
|
using System;
|
2026-01-26 09:39:17 +01:00
|
|
|
using System.Collections.Generic;
|
2026-01-15 19:56:50 +01:00
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
2026-01-26 09:39:17 +01:00
|
|
|
using MonoGameLibrary;
|
2026-01-15 19:56:50 +01:00
|
|
|
using MonoGameLibrary.Graphics;
|
|
|
|
|
using MonoGameLibrary.Input;
|
|
|
|
|
|
|
|
|
|
namespace FNAF_Clone.GUI;
|
|
|
|
|
|
|
|
|
|
public class UIElement {
|
2026-01-26 09:39:17 +01:00
|
|
|
|
2026-01-15 19:56:50 +01:00
|
|
|
public bool Active { get; set; } = false;
|
|
|
|
|
public bool Pressable { get; set; } = false;
|
2026-01-29 19:37:40 +01:00
|
|
|
public bool Visible { get; set; } = true;
|
2026-01-15 19:56:50 +01:00
|
|
|
|
|
|
|
|
private (Point, Point) bounds; // TODO: Change this to support non-rectangular hitboxes
|
2026-01-29 19:37:40 +01:00
|
|
|
private (Point, Point) screenSpaceBounds;
|
2026-01-26 09:39:17 +01:00
|
|
|
private List<TextureRegion> textures = new();
|
|
|
|
|
private int currentTextureId = 0;
|
2026-01-15 19:56:50 +01:00
|
|
|
|
2026-01-26 09:39:17 +01:00
|
|
|
private float _scaleMultiplier = 1;
|
|
|
|
|
public float ScaleMultiplier{
|
|
|
|
|
get{
|
|
|
|
|
return _scaleMultiplier;
|
|
|
|
|
}
|
|
|
|
|
set{
|
|
|
|
|
_scaleMultiplier = value;
|
|
|
|
|
LoadPixelScaleMultiplier();
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-29 19:37:40 +01:00
|
|
|
private int pixelScaleMultiplier = 1;
|
2026-01-26 09:39:17 +01:00
|
|
|
private void LoadPixelScaleMultiplier() {
|
2026-01-29 19:37:40 +01:00
|
|
|
pixelScaleMultiplier = (int)(UIManager.GlobalPixelMultiplier * _scaleMultiplier); // TODO: move GlobalPixelMultiplier somewhere where it would make sense
|
|
|
|
|
screenSpaceBounds = (bounds.Item1.MultiplyByScalar(pixelScaleMultiplier), bounds.Item2.MultiplyByScalar(pixelScaleMultiplier));
|
2026-01-26 09:39:17 +01:00
|
|
|
}
|
|
|
|
|
|
2026-01-15 19:56:50 +01:00
|
|
|
public UIElement(TextureRegion texture, Point position) {
|
2026-01-26 09:39:17 +01:00
|
|
|
textures.Add(texture);
|
2026-01-15 19:56:50 +01:00
|
|
|
bounds = (position, position + new Point(texture.Width, texture.Height));
|
2026-01-26 09:39:17 +01:00
|
|
|
LoadPixelScaleMultiplier();
|
|
|
|
|
}
|
|
|
|
|
public UIElement(TextureRegion[] textures, Point position) {
|
|
|
|
|
this.textures.AddRange(textures);
|
|
|
|
|
bounds = (position, position + new Point(textures[0].Width, textures[0].Height));
|
|
|
|
|
LoadPixelScaleMultiplier();
|
|
|
|
|
}
|
2026-01-29 19:37:40 +01:00
|
|
|
|
|
|
|
|
public UIElement(Point corner1, Point corner2) {
|
|
|
|
|
bounds = (corner1, corner2);
|
|
|
|
|
Visible = false;
|
|
|
|
|
LoadPixelScaleMultiplier();
|
|
|
|
|
}
|
2026-01-26 09:39:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
public void SetTexture(int textureId) {
|
|
|
|
|
if (textureId >= textures.Count){
|
|
|
|
|
Console.WriteLine($"WARNING: TEXTURE {textureId} OUT OF BOUNDS");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentTextureId = textureId;
|
2026-01-15 19:56:50 +01:00
|
|
|
}
|
|
|
|
|
public void Update() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsWithinBounds(Point pos) {
|
2026-01-29 19:37:40 +01:00
|
|
|
return pos.X >= Math.Min(screenSpaceBounds.Item1.X, screenSpaceBounds.Item2.X) && pos.X <= Math.Max(screenSpaceBounds.Item1.X, screenSpaceBounds.Item2.X) &&
|
|
|
|
|
pos.Y >= Math.Min(screenSpaceBounds.Item1.Y, screenSpaceBounds.Item2.Y) && pos.Y <= Math.Max(screenSpaceBounds.Item1.Y, screenSpaceBounds.Item2.Y);
|
2026-01-15 19:56:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Action OnMousePress{ get; set; }
|
|
|
|
|
|
|
|
|
|
// public virtual void OnMousePress() { }
|
|
|
|
|
|
|
|
|
|
public virtual void OnMouseRelease() { }
|
|
|
|
|
|
|
|
|
|
public virtual void OnMouseHold() { }
|
|
|
|
|
|
|
|
|
|
public void Draw(SpriteBatch spriteBatch) {
|
2026-01-29 19:37:40 +01:00
|
|
|
if (!Visible){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
textures[currentTextureId].Draw(spriteBatch, screenSpaceBounds.Item1.ToVector2(), Color.White, 0, Vector2.Zero, pixelScaleMultiplier, SpriteEffects.None, 0);
|
2026-01-26 09:39:17 +01:00
|
|
|
// texture.Draw(spriteBatch, bounds.Item1.ToVector2(), Color.White);
|
2026-01-15 19:56:50 +01:00
|
|
|
}
|
|
|
|
|
}
|