Opravena chyba se špatně převedenými hitboxy UI elementů. Opravena chyba s měněním screenu, kdy stará zůstala aktivní. Přidány elementy pro překlikávání kamer.

This commit is contained in:
Perry 2026-01-29 19:37:40 +01:00
parent 2cd215cc33
commit 8a3267cc4b
8 changed files with 56 additions and 19 deletions

View file

@ -12,8 +12,10 @@ public class UIElement {
public bool Active { get; set; } = false;
public bool Pressable { get; set; } = false;
public bool Visible { get; set; } = true;
private (Point, Point) bounds; // TODO: Change this to support non-rectangular hitboxes
private (Point, Point) screenSpaceBounds;
private List<TextureRegion> textures = new();
private int currentTextureId = 0;
@ -27,9 +29,10 @@ public class UIElement {
LoadPixelScaleMultiplier();
}
}
private float pixelScaleMultiplier = 1;
private int pixelScaleMultiplier = 1;
private void LoadPixelScaleMultiplier() {
pixelScaleMultiplier = UIManager.GlobalPixelMultiplier * _scaleMultiplier;
pixelScaleMultiplier = (int)(UIManager.GlobalPixelMultiplier * _scaleMultiplier); // TODO: move GlobalPixelMultiplier somewhere where it would make sense
screenSpaceBounds = (bounds.Item1.MultiplyByScalar(pixelScaleMultiplier), bounds.Item2.MultiplyByScalar(pixelScaleMultiplier));
}
public UIElement(TextureRegion texture, Point position) {
@ -42,6 +45,12 @@ public class UIElement {
bounds = (position, position + new Point(textures[0].Width, textures[0].Height));
LoadPixelScaleMultiplier();
}
public UIElement(Point corner1, Point corner2) {
bounds = (corner1, corner2);
Visible = false;
LoadPixelScaleMultiplier();
}
public void SetTexture(int textureId) {
@ -57,8 +66,8 @@ public class UIElement {
}
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);
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);
}
public Action OnMousePress{ get; set; }
@ -70,7 +79,10 @@ public class UIElement {
public virtual void OnMouseHold() { }
public void Draw(SpriteBatch spriteBatch) {
textures[currentTextureId].Draw(spriteBatch, bounds.Item1.ToVector2(), Color.White, 0, Vector2.Zero, pixelScaleMultiplier, SpriteEffects.None, 0);
if (!Visible){
return;
}
textures[currentTextureId].Draw(spriteBatch, screenSpaceBounds.Item1.ToVector2(), Color.White, 0, Vector2.Zero, pixelScaleMultiplier, SpriteEffects.None, 0);
// texture.Draw(spriteBatch, bounds.Item1.ToVector2(), Color.White);
}
}