Oprava spawnování monster, optimalizace v CommandProcessor a EventProcessor. Přesunutí některých tříd do vlastních namespaců, pročištění kódu, úpravy formátování, odstranění nepoužívaných souborů a zakomentovaného kódu
This commit is contained in:
parent
e5d746d597
commit
243f071a43
62 changed files with 873 additions and 1217 deletions
|
|
@ -1,31 +1,28 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Mime;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using MonoGameLibrary;
|
||||
using MonoGameLibrary.Graphics;
|
||||
using MonoGameLibrary.Input;
|
||||
|
||||
namespace ONDClient.GUI;
|
||||
|
||||
public class UIElement {
|
||||
public static int GlobalPixelMultiplier{ get; set; }
|
||||
|
||||
public bool Active { get; set; } = true;
|
||||
public bool Pressable { get; set; } = false;
|
||||
public bool Visible { get; set; } = true;
|
||||
public int DrawPriority { get; } = 0;
|
||||
|
||||
protected (Point, Point) _bounds;
|
||||
public (Point, Point) Bounds{
|
||||
get => _bounds;
|
||||
protected set { _bounds = value; UpdateBounds(); }
|
||||
}
|
||||
|
||||
protected (Point, Point) screenSpaceBounds;
|
||||
public List<TextureRegion> Textures = new();
|
||||
protected int currentTextureId = 0;
|
||||
|
||||
protected (Point, Point) _bounds;
|
||||
protected (Point, Point) ScreenSpaceBounds;
|
||||
protected int CurrentTextureId = 0;
|
||||
|
||||
private List<TextureRegion> textures = new();
|
||||
private float _scaleMultiplier = 1;
|
||||
public float ScaleMultiplier{
|
||||
get{
|
||||
|
|
@ -38,23 +35,23 @@ public class UIElement {
|
|||
}
|
||||
protected int pixelScaleMultiplier = 1;
|
||||
private void LoadPixelScaleMultiplier() {
|
||||
pixelScaleMultiplier = (int)(UIManager.GlobalPixelMultiplier * _scaleMultiplier); // TODO: move GlobalPixelMultiplier somewhere where it would make sense
|
||||
pixelScaleMultiplier = (int)(GlobalPixelMultiplier * _scaleMultiplier);
|
||||
UpdateBounds();
|
||||
}
|
||||
|
||||
protected virtual void UpdateBounds() {
|
||||
_bounds = (Bounds.Item1, (Bounds.Item2 - Bounds.Item1).MultiplyByScalar(ScaleMultiplier) + Bounds.Item1);
|
||||
screenSpaceBounds = (Bounds.Item1.MultiplyByScalar(pixelScaleMultiplier), Bounds.Item2.MultiplyByScalar(pixelScaleMultiplier));
|
||||
ScreenSpaceBounds = (Bounds.Item1.MultiplyByScalar(pixelScaleMultiplier), Bounds.Item2.MultiplyByScalar(pixelScaleMultiplier));
|
||||
}
|
||||
|
||||
public UIElement(TextureRegion texture, Point position, int drawPriority = 0) {
|
||||
Textures.Add(texture);
|
||||
textures.Add(texture);
|
||||
Bounds = (position, position + new Point(texture.Width, texture.Height));
|
||||
DrawPriority = drawPriority;
|
||||
LoadPixelScaleMultiplier();
|
||||
}
|
||||
public UIElement(TextureRegion[] textures, Point position, int drawPriority = 0) {
|
||||
this.Textures.AddRange(textures);
|
||||
this.textures.AddRange(textures);
|
||||
Bounds = (position, position + new Point(textures[0].Width, textures[0].Height));
|
||||
DrawPriority = drawPriority;
|
||||
LoadPixelScaleMultiplier();
|
||||
|
|
@ -67,44 +64,41 @@ public class UIElement {
|
|||
}
|
||||
|
||||
public virtual void SetTexture(int textureId) {
|
||||
if (textureId >= Textures.Count){
|
||||
if (textureId >= textures.Count){
|
||||
Console.WriteLine($"WARNING: TEXTURE {textureId} OUT OF BOUNDS");
|
||||
return;
|
||||
}
|
||||
|
||||
currentTextureId = textureId;
|
||||
CurrentTextureId = textureId;
|
||||
}
|
||||
public virtual void Update() { }
|
||||
|
||||
public bool IsWithinBounds(Point pos) {
|
||||
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);
|
||||
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; }
|
||||
|
||||
// public virtual void OnMousePress() { }
|
||||
|
||||
public virtual void OnMouseRelease() { }
|
||||
|
||||
public virtual void OnMouseHold() { }
|
||||
// public virtual void OnMouseRelease() { }
|
||||
// public virtual void OnMouseHold() { }
|
||||
|
||||
public virtual void Draw(SpriteBatch spriteBatch) {
|
||||
if (!Visible || !Active || Textures.Count == 0){
|
||||
if (!Visible || !Active || textures.Count == 0){
|
||||
return;
|
||||
}
|
||||
|
||||
Textures[currentTextureId].Draw(spriteBatch, screenSpaceBounds.Item1.ToVector2(), Color.White, 0, Vector2.Zero, pixelScaleMultiplier, SpriteEffects.None, 0);
|
||||
textures[CurrentTextureId].Draw(spriteBatch, ScreenSpaceBounds.Item1.ToVector2(), Color.White, 0, Vector2.Zero, pixelScaleMultiplier, SpriteEffects.None, 0);
|
||||
// texture.Draw(spriteBatch, bounds.Item1.ToVector2(), Color.White);
|
||||
}
|
||||
|
||||
public void SetPosition(Point position) {
|
||||
Bounds = (position, position + new Point(Textures[0].Width, Textures[0].Height));
|
||||
Bounds = (position, position + new Point(textures[0].Width, textures[0].Height));
|
||||
}
|
||||
|
||||
public UIElement Clone() {
|
||||
return new UIElement(Textures.ToArray(), Bounds.Item1);
|
||||
return new UIElement(textures.ToArray(), Bounds.Item1);
|
||||
}
|
||||
|
||||
public TextureRegion[] GetTextures() => Textures.ToArray();
|
||||
public TextureRegion[] GetTextures() => textures.ToArray();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue