调整了模板

This commit is contained in:
CortexCore
2023-07-17 04:10:14 +08:00
parent 498b0617f8
commit e27cce2ac3
56 changed files with 2165 additions and 581 deletions

View File

@@ -7,12 +7,11 @@ public partial class NodeBuilder : Node
{
[Export] private bool clearOnStart = true;
[Export] private bool clearTemplateOnly = true;
[Export] private Control container;
[ExportCategory("UX")]
[Export] private Control emptyHints;
[ExportCategory("Template")]
[Export] private PackedScene template;
public override void _Ready()
{
if (clearOnStart)
@@ -20,40 +19,56 @@ public partial class NodeBuilder : Node
Clear();
}
}
public Node Build()
public T Build<T>() where T : Node
{
var instance = template.Instantiate();
if (container is not null)
Node instance;
if (template is not null)
{
container.AddChild(instance);
instance = template.Instantiate<T>();
AddChild(instance);
}
else
{
instance = new PanelContainer();
var margin = new MarginContainer();
AddChild(instance);
instance.AddChild(margin);
instance = margin;
margin.AddThemeConstantOverride("theme_override_constants/margin_left",16);
margin.AddThemeConstantOverride("theme_override_constants/margin_top",16);
margin.AddThemeConstantOverride("theme_override_constants/margin_right",16);
margin.AddThemeConstantOverride("theme_override_constants/margin_button",16);
}
emptyHints?.Hide();
return instance;
}
public T Build<T>() where T : Node
{
var instance = Build() as T;
return instance;
emptyHints?.Hide();;
return instance as T;
}
public void Clear()
{
emptyHints?.Show();
if (clearTemplateOnly)
{
foreach (var x in container is not null ? container.GetChildren() : GetChildren())
foreach (var x in GetChildren())
{
if(x.SceneFilePath == template.ResourcePath)
x.QueueFree();
switch (template)
{
case null:
x.QueueFree();
break;
case (var y) when y.ResourcePath == x.SceneFilePath:
x.QueueFree();
break;
}
}
}
else
{
MathNode.ClearChild(container is not null ? container:this);
MathNode.ClearChild(this);
}
}
}