64 lines
2.2 KiB
C#
64 lines
2.2 KiB
C#
using Godot;
|
|
using FileAccess = Godot.FileAccess;
|
|
|
|
namespace Polonium.DataStructures;
|
|
|
|
/// <summary>
|
|
/// Represents a complete set of textures for UI button states.
|
|
/// Automatically loads textures for Normal, Pressed, Disabled, Hover, and Focused states from a directory.
|
|
/// </summary>
|
|
public class TextureSet
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="TextureSet"/> class by loading textures from the specified path.
|
|
/// </summary>
|
|
/// <param name="path">The base path where texture files are located.</param>
|
|
public TextureSet(string path)
|
|
{
|
|
Normal = LoadTexture($"{path}/Normal");
|
|
Pressed = LoadTexture($"{path}/Pressed");
|
|
Disabled = LoadTexture($"{path}/Disabled");
|
|
Hover = LoadTexture($"{path}/Hover");
|
|
Focused = LoadTexture($"{path}/Focused");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the texture for the normal button state.
|
|
/// </summary>
|
|
public Texture2D Normal { get; init; }
|
|
|
|
/// <summary>
|
|
/// Gets the texture for the pressed button state.
|
|
/// </summary>
|
|
public Texture2D Pressed { get; init; }
|
|
|
|
/// <summary>
|
|
/// Gets the texture for the hover button state.
|
|
/// </summary>
|
|
public Texture2D Hover { get; init; }
|
|
|
|
/// <summary>
|
|
/// Gets the texture for the disabled button state.
|
|
/// </summary>
|
|
public Texture2D Disabled { get; init; }
|
|
|
|
/// <summary>
|
|
/// Gets the texture for the focused button state.
|
|
/// </summary>
|
|
public Texture2D Focused { get; init; }
|
|
|
|
/// <summary>
|
|
/// Loads a texture from the specified path, supporting both static PNG files and animated texture directories.
|
|
/// </summary>
|
|
/// <param name="path">The path to the texture file or directory.</param>
|
|
/// <returns>The loaded texture, or an empty texture if not found.</returns>
|
|
private static Texture2D LoadTexture(string path)
|
|
{
|
|
Texture2D res = new();
|
|
if(FileAccess.FileExists($"{path}.png"))
|
|
res = ResourceLoader.Load<Texture2D>($"{path}.png");
|
|
else if(DirAccess.DirExistsAbsolute($"{path}.at_dir"))
|
|
res = Utils.LoadAnimatedTextureFromDirectory($"{path}.at_dir");
|
|
return res;
|
|
}
|
|
} |