draft: texture button
This commit is contained in:
6
src/Attributes/ProxyProperty.cs
Normal file
6
src/Attributes/ProxyProperty.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Polonium.Attributes;
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class ProxyProperty : Attribute
|
||||
{
|
||||
|
||||
}
|
||||
33
src/DataStructures/TextureSet.cs
Normal file
33
src/DataStructures/TextureSet.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Godot;
|
||||
using FileAccess = Godot.FileAccess;
|
||||
|
||||
namespace Polonium.DataStructures;
|
||||
|
||||
public class TextureSet
|
||||
{
|
||||
public TextureSet(string path)
|
||||
{
|
||||
Normal = LoadTexture($"{path}/Normal");
|
||||
Pressed = LoadTexture($"{path}/Pressed");
|
||||
Disabled = LoadTexture($"{path}/Disabled");
|
||||
Hover = LoadTexture($"{path}/Hover");
|
||||
Focused = LoadTexture($"{path}/Focused");
|
||||
}
|
||||
public Texture2D Normal { get; init; }
|
||||
public Texture2D Pressed { get; init; }
|
||||
public Texture2D Hover { get; init; }
|
||||
public Texture2D Disabled { get; init; }
|
||||
public Texture2D Focused { get; init; }
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
28
src/Utils.cs
28
src/Utils.cs
@@ -1,4 +1,5 @@
|
||||
using System.Reflection;
|
||||
using Godot;
|
||||
|
||||
namespace Polonium;
|
||||
|
||||
@@ -15,4 +16,31 @@ public static class Utils
|
||||
return e.Types.Where(t => t != null);
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<StringName, AnimatedTexture> AnimatedTextureCache = new ();
|
||||
public static AnimatedTexture LoadAnimatedTextureFromDirectory(StringName path)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!AnimatedTextureCache.ContainsKey(path))
|
||||
{
|
||||
AnimatedTextureCache[path] = new AnimatedTexture();
|
||||
int f = 0;
|
||||
foreach (string fname in DirAccess.GetFilesAt(path))
|
||||
{
|
||||
if (!fname.EndsWith(".png"))
|
||||
continue;
|
||||
AnimatedTextureCache[path].SetFrameTexture(f, ResourceLoader.Load<Texture2D>(fname));
|
||||
}
|
||||
}
|
||||
|
||||
return AnimatedTextureCache[path];
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user