diff --git a/GlobalClasses/Nodes/Buttons/PoloniumTextureButton.cs b/GlobalClasses/Nodes/Buttons/PoloniumTextureButton.cs new file mode 100644 index 0000000..ebb24ec --- /dev/null +++ b/GlobalClasses/Nodes/Buttons/PoloniumTextureButton.cs @@ -0,0 +1,40 @@ +using Godot; +using Polonium.Attributes; +using Polonium.DataStructures; +using System.Collections.Generic; + + +namespace GlobalClasses; +[GlobalClass] +[Tool] +[ProxyNode] +public partial class PoloniumTextureButton : TextureButton +{ + [ProxyProperty] + public virtual TextureSet TextureSet => null; + + [Export] + public GlobalRegistry.TextureSetName TextureSetName { get; set; } + + public sealed override void _Ready() + { + TextureSet t = TextureSet; + if (t is null) + t = GlobalRegistry.TextureSetMap.GetValueOrDefault(TextureSetName, null); + if (t is not null) + { + TextureNormal = t.Normal; + TextureHover = t.Hover; + TexturePressed = t.Pressed; + TextureDisabled = t.Disabled; + TextureFocused = t.Focused; + } + + __Ready(); + base._Ready(); + } + [ProxyMethod] + public virtual void __Ready() + { + } +} \ No newline at end of file diff --git a/GlobalClasses/Scenes/CameraScene.cs b/GlobalClasses/Nodes/Scenes/CameraScene.cs similarity index 85% rename from GlobalClasses/Scenes/CameraScene.cs rename to GlobalClasses/Nodes/Scenes/CameraScene.cs index 02a5d59..7b31902 100644 --- a/GlobalClasses/Scenes/CameraScene.cs +++ b/GlobalClasses/Nodes/Scenes/CameraScene.cs @@ -20,9 +20,16 @@ public partial class CameraScene : Scene get => Camera.Zoom.X; set => Camera.Zoom = value * Vector2.One; } - public override void _Ready() + + [ProxyMethod] + public virtual void __Ready() + { + } + + public sealed override void _Ready() { Camera = GetNode("Camera"); + __Ready(); base._Ready(); } protected void ZoomIn() => Zoom = Mathf.Max(Zoom * (1 + ZoomRate), MaxZoom); diff --git a/GlobalClasses/Scenes/DissolveScene.cs b/GlobalClasses/Nodes/Scenes/DissolveScene.cs similarity index 79% rename from GlobalClasses/Scenes/DissolveScene.cs rename to GlobalClasses/Nodes/Scenes/DissolveScene.cs index 2094e2c..1059652 100644 --- a/GlobalClasses/Scenes/DissolveScene.cs +++ b/GlobalClasses/Nodes/Scenes/DissolveScene.cs @@ -12,7 +12,7 @@ public partial class DissolveScene : Scene private bool Finished { get; set; } = false; private bool Terminated { get; set; } = false; - public override void _Process(double delta) + public sealed override void _Process(double delta) { if(Finished && !Terminated) { @@ -21,15 +21,15 @@ public partial class DissolveScene : Scene return; } - Process(delta); + __Process(delta); base._Process(delta); } [ProxyMethod] - public virtual void Enter() + public virtual void __Enter() { } [ProxyMethod] - public virtual void Process(double delta) + public virtual void __Process(double delta) { } @@ -37,7 +37,7 @@ public partial class DissolveScene : Scene { Finished = false; Terminated = false; - Enter(); + __Enter(); base._EnterTree(); } } diff --git a/GlobalClasses/Scenes/RootScene.cs b/GlobalClasses/Nodes/Scenes/RootScene.cs similarity index 62% rename from GlobalClasses/Scenes/RootScene.cs rename to GlobalClasses/Nodes/Scenes/RootScene.cs index ab81dfb..7eb507f 100644 --- a/GlobalClasses/Scenes/RootScene.cs +++ b/GlobalClasses/Nodes/Scenes/RootScene.cs @@ -19,28 +19,43 @@ public partial class RootScene : Scene CurrentScene = scene; } - public override void _Ready() - { - GlobalRegistry.RootScene = this; - base._Ready(); - } - [ProxyMethod] - public virtual void Enter() + public virtual void __Enter() { } - public override void _EnterTree() + [ProxyMethod] + public virtual void __Ready() { - Enter(); + } + + [ProxyMethod] + public virtual void __Process(double delta) + { + } + + public sealed override void _EnterTree() + { + GlobalRegistry.Prepare(); + GlobalRegistry.Start(); + __Enter(); base._EnterTree(); } - public override void _Process(double delta) + public sealed override void _Process(double delta) { if(!GlobalRegistry.Paused) foreach (ITimeConsumer tc in GlobalRegistry.TimeConsumers) tc.Process(delta); + __Process(delta); base._Process(delta); } + + public sealed override void _Ready() + { + GlobalRegistry.RootScene = this; + __Ready(); + base._Ready(); + } + } diff --git a/GlobalClasses/Scenes/Scene.cs b/GlobalClasses/Nodes/Scenes/Scene.cs similarity index 100% rename from GlobalClasses/Scenes/Scene.cs rename to GlobalClasses/Nodes/Scenes/Scene.cs diff --git a/Package/build/Polonium.targets b/Package/build/Polonium.targets index bcd3c70..a4d1ab6 100644 --- a/Package/build/Polonium.targets +++ b/Package/build/Polonium.targets @@ -13,7 +13,11 @@ + + + + + + + + + + + + + + + + diff --git a/Polonium.csproj b/Polonium.csproj index e7c6aa5..c2fed99 100644 --- a/Polonium.csproj +++ b/Polonium.csproj @@ -16,13 +16,14 @@ - + + + + + + + diff --git a/build b/build new file mode 100644 index 0000000..070fbd2 --- /dev/null +++ b/build @@ -0,0 +1,17 @@ +#! /bin/bash +rm -rf ~/.nuget/packages/polonium* +cd ../Polonium.Tasks +dotnet clean Polonium.Tasks.csproj +dotnet restore Polonium.Tasks.csproj +dotnet build Polonium.Tasks.csproj + +cd ../Polonium.Generators +dotnet clean Polonium.Generators.csproj +dotnet restore Polonium.Generators.csproj +dotnet build Polonium.Generators.csproj + +cd ../Polonium +rm -rf ~/.nuget/packages/polonium* +dotnet clean Polonium.csproj +dotnet restore Polonium.csproj +dotnet build Polonium.csproj diff --git a/src/Attributes/ProxyProperty.cs b/src/Attributes/ProxyProperty.cs new file mode 100644 index 0000000..a5cc0e3 --- /dev/null +++ b/src/Attributes/ProxyProperty.cs @@ -0,0 +1,6 @@ +namespace Polonium.Attributes; +[AttributeUsage(AttributeTargets.Property)] +public class ProxyProperty : Attribute +{ + +} \ No newline at end of file diff --git a/src/DataStructures/TextureSet.cs b/src/DataStructures/TextureSet.cs new file mode 100644 index 0000000..5617c17 --- /dev/null +++ b/src/DataStructures/TextureSet.cs @@ -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($"{path}.png"); + else if(DirAccess.DirExistsAbsolute($"{path}.at_dir")) + res = Utils.LoadAnimatedTextureFromDirectory($"{path}.at_dir"); + return res; + } + + +} \ No newline at end of file diff --git a/src/Utils.cs b/src/Utils.cs index 63dd29d..ae1d1a8 100644 --- a/src/Utils.cs +++ b/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 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(fname)); + } + } + + return AnimatedTextureCache[path]; + } + catch (Exception e) + { + return null; + } + } + + } \ No newline at end of file