67 lines
1.4 KiB
C#
67 lines
1.4 KiB
C#
|
using Godot;
|
||
|
using System;
|
||
|
// ReSharper disable MemberCanBePrivate.Global
|
||
|
|
||
|
namespace BITKit;
|
||
|
public partial class TemplateBuilder : Node
|
||
|
{
|
||
|
[Export] public TemplateResource template;
|
||
|
|
||
|
[ExportCategory("Index")]
|
||
|
[Export] private NodeBuilder indexBuilder;
|
||
|
|
||
|
[ExportCategory("Weaver")]
|
||
|
[Export] private FormBuilder formBuilder;
|
||
|
|
||
|
[ExportCategory("UI 绑定")] [Export]
|
||
|
private Button createTemplateButton;
|
||
|
|
||
|
public FormResource CurrentTemplate { get; private set; }
|
||
|
private ButtonGroup _buttonGroup;
|
||
|
public override void _Ready()
|
||
|
{
|
||
|
_buttonGroup = new ButtonGroup();
|
||
|
|
||
|
if (template.IsSupportCreateTemplate && createTemplateButton is not null)
|
||
|
{
|
||
|
createTemplateButton.Pressed += template.CreateTemplate;
|
||
|
createTemplateButton.Pressed += Rebuild;
|
||
|
}
|
||
|
|
||
|
Rebuild();
|
||
|
}
|
||
|
|
||
|
public override void _EnterTree()
|
||
|
{
|
||
|
template.OnStart();
|
||
|
}
|
||
|
|
||
|
public override void _ExitTree()
|
||
|
{
|
||
|
template.OnStop();
|
||
|
}
|
||
|
|
||
|
public void Rebuild()
|
||
|
{
|
||
|
indexBuilder.Clear();
|
||
|
|
||
|
foreach (var name in template.GetTemplateNames())
|
||
|
{
|
||
|
var container = indexBuilder.Build<UXContainer>();
|
||
|
var _template = this.template.GetTemplate(name);
|
||
|
|
||
|
container.button.Text = name;
|
||
|
container.button.ButtonGroup = _buttonGroup;
|
||
|
container.button.ToggleMode = true;
|
||
|
|
||
|
container.button.Pressed += () =>
|
||
|
{
|
||
|
CurrentTemplate = _template;
|
||
|
formBuilder.Build(_template);
|
||
|
};
|
||
|
}
|
||
|
if(CurrentTemplate is not null)
|
||
|
formBuilder.Build(CurrentTemplate);
|
||
|
}
|
||
|
}
|