ZoFo/MonogameLibrary/UI/Base/DrawableUIElement.cs
2024-08-20 16:24:20 +03:00

55 lines
1.7 KiB
C#

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonogameLibrary.UI.Enums;
using System;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using Microsoft.Xna.Framework.Content;
namespace MonogameLibrary.UI.Base
{
public class DrawableUIElement
{
protected Texture2D texture;
protected int layerIndex;
protected UIManager Manager;
public string textureName = "";
public Rectangle rectangle = new Rectangle(0, 0, 10, 10);
public Color mainColor = Color.White;
public bool sus = true;
public DrawableUIElement(UIManager manager, int layerIndex = 0, string textureName = "")
{
Manager = manager;
this.textureName = textureName;
manager.Register(this, layerIndex);
}
public virtual void LoadTexture(ContentManager content)
{
if (textureName == "")
{
sus = false;
texture = new Texture2D(Manager.GraphicsDevice, 1, 1);
texture.SetData<Color>(new Color[] { mainColor });
}
else
{
try
{
texture = content.Load<Texture2D>(textureName);
}
catch
{
texture = new Texture2D(Manager.GraphicsDevice, 1, 1);
texture.SetData<Color>(new Color[] { mainColor });
}
}
}
public virtual void Draw(SpriteBatch _spriteBatch)
{
_spriteBatch.Draw(texture, rectangle, mainColor);
}
}
}