draft: texture button
This commit is contained in:
40
GlobalClasses/Nodes/Buttons/PoloniumTextureButton.cs
Normal file
40
GlobalClasses/Nodes/Buttons/PoloniumTextureButton.cs
Normal file
@@ -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()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -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<Camera2D>("Camera");
|
||||
__Ready();
|
||||
base._Ready();
|
||||
}
|
||||
protected void ZoomIn() => Zoom = Mathf.Max(Zoom * (1 + ZoomRate), MaxZoom);
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,7 +13,11 @@
|
||||
<MakeDir Directories="$(ProjectDir)Concepts" Condition="!Exists('$(ProjectDir)Concepts')"/>
|
||||
<MakeDir Directories="$(ProjectDir)Registries" Condition="!Exists('$(ProjectDir)Registries')"/>
|
||||
<MakeDir Directories="$(ProjectDir)Data" Condition="!Exists('$(ProjectDir)Data')"/>
|
||||
<MakeDir Directories="$(ProjectDir)Resources" Condition="!Exists('$(ProjectDir)Resources')"/>
|
||||
<MakeDir Directories="$(ProjectDir)Resources/ButtonTextureSet" Condition="!Exists('$(ProjectDir)Resources/ButtonTextureSet')"/>
|
||||
<MakeDir Directories="$(ProjectDir)script_templates" Condition="!Exists('$(ProjectDir)script_templates')"/>
|
||||
<MakeDir Directories="$(ProjectDir).polonium" Condition="!Exists('$(ProjectDir).polonium')"/>
|
||||
<MakeDir Directories="$(ProjectDir).polonium/Patches" Condition="!Exists('$(ProjectDir).polonium/Patches')" />
|
||||
<Exec
|
||||
Command='rmdir "$(ProjectDir)GlobalClasses"'
|
||||
Condition="'$(OS)'=='Windows_NT' and Exists('$(ProjectDir)GlobalClasses')"
|
||||
@@ -63,13 +67,28 @@
|
||||
Encoding="UTF-8"
|
||||
/>
|
||||
</Target>
|
||||
<Target Name="CleanPoloniumFiles" BeforeTargets="GenerateTextureSetManifest">
|
||||
<ItemGroup>
|
||||
<PoloniumFiles Include="$(ProjectDir).polonium/**/*.*"/>
|
||||
</ItemGroup>
|
||||
<Delete Files="@(PoloniumFiles)"/>
|
||||
</Target>
|
||||
<Target Name="GenerateTextureSetManifest" DependsOnTargets="CleanPoloniumFiles" BeforeTargets="BeforeBuild">
|
||||
<ScanTextureSetFolderTask
|
||||
RootPath="$(ProjectDir)Resources/ButtonTextureSet/"
|
||||
OutputPath="$(ProjectDir).polonium/"
|
||||
/>
|
||||
</Target>
|
||||
<ItemGroup>
|
||||
<Folder Include="Concepts"/>
|
||||
<Folder Include="Assets"/>
|
||||
<Folder Include="Registries"/>
|
||||
<Folder Include="Data"/>
|
||||
<Folder Include="Resources"/>
|
||||
<None Include="script_templates/**/*.*"/>
|
||||
<Compile Remove="script_templates/**/*.*"/>
|
||||
<PackageReference Include="Polonium.Generators" Version="0.1.1-x" />
|
||||
<PackageReference Include="Polonium.Tasks" Version="0.1.1-x"/>
|
||||
<AdditionalFiles Include=".polonium/**/*.*"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -16,13 +16,14 @@
|
||||
<PackageReference Include="GodotSharp" Version="4.4.0-beta.3" />
|
||||
<PackageReference Include="Polonium.Tasks" Version="0.1.1-x" />
|
||||
</ItemGroup>
|
||||
<Target Name="GenerateProxyNodes" BeforeTargets="BeforeBuild">
|
||||
<Target Name="Prepare" BeforeTargets="BeforeBuild">
|
||||
<GenerateProxyNodesTask
|
||||
SourceDirectory="$(ProjectDir)GlobalClasses"
|
||||
TemplateDirectory="$(ProjectDir)polonium_templates"
|
||||
AttributeName="ProxyNode"
|
||||
/>
|
||||
</Target>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="NuGet.config" />
|
||||
<None
|
||||
@@ -33,19 +34,28 @@
|
||||
<None
|
||||
Include="GlobalClasses/**/*.cs"
|
||||
Pack="true"
|
||||
PackagePath="build\GlobalClasses"
|
||||
PackagePath="build/GlobalClasses"
|
||||
/>
|
||||
<None
|
||||
Include="polonium_templates/**/*.cs"
|
||||
Pack="true"
|
||||
PackagePath="build/polonium_templates"
|
||||
/>
|
||||
<None
|
||||
Include=".polonium/**/*.*"
|
||||
Pack="true"
|
||||
PackagePath="build/.polonium"
|
||||
/>
|
||||
<None Include="publish" />
|
||||
<Compile Remove="polonium_templates/**/*.*" />
|
||||
<Compile Remove="GlobalClasses/**/*.cs" />
|
||||
<Folder Include="polonium_templates" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="build" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="CleanPreviousPackages" BeforeTargets="Build">
|
||||
<Message Text="Cleaning Previous Packages -------------------------" Importance="high" />
|
||||
<Message Text="Cleaning --------------------------------------------" Importance="high" />
|
||||
|
||||
17
build
Normal file
17
build
Normal file
@@ -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
|
||||
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