78 lines
1.8 KiB
C#
78 lines
1.8 KiB
C#
|
using Godot;
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using BITKit;
|
||
|
|
||
|
namespace BITFactory;
|
||
|
[GlobalClass]
|
||
|
public partial class IDIS_RegisterWeaver : FormWeaverResource
|
||
|
{
|
||
|
[Export] private NodePath handleEditPath;
|
||
|
[Export] private NodePath generateButtonPath;
|
||
|
|
||
|
private LineEdit handleEdit=>formBuilder.GetNode<LineEdit>(handleEditPath);
|
||
|
private Button generateButton=>formBuilder.GetNode<Button>(generateButtonPath);
|
||
|
|
||
|
private readonly List<IDIS_Data> _values=new();
|
||
|
public override void Weaver(Control container, IFormField formField)
|
||
|
{
|
||
|
var field = (IDIS_TemplateForm)formField;
|
||
|
|
||
|
var data = new IDIS_Data();
|
||
|
|
||
|
var vBox = container.Create<HBoxContainer>();
|
||
|
|
||
|
var label = vBox.Create<Label>();
|
||
|
var typeLabel = vBox.Create<Label>();
|
||
|
var valueEdit = vBox.Create<LineEdit>();
|
||
|
|
||
|
var myIndex = _values.Count;
|
||
|
_values.Add(data);
|
||
|
|
||
|
label.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||
|
typeLabel.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||
|
valueEdit.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||
|
|
||
|
label.Text = field.Name;
|
||
|
typeLabel.Text = field.Type;
|
||
|
valueEdit.PlaceholderText = field.DefaultValue;
|
||
|
|
||
|
data.Category = field.Category;
|
||
|
data.Handle = handleEdit.Text;
|
||
|
data.Format = field.Type;
|
||
|
|
||
|
valueEdit.TextChanged += x => data.Value = x;
|
||
|
}
|
||
|
|
||
|
public override string GetContent()
|
||
|
{
|
||
|
if (string.IsNullOrEmpty(handleEdit.Text))
|
||
|
{
|
||
|
throw new InvalidOperationException("[color=red]输入的标识码为空[/color]");
|
||
|
}
|
||
|
|
||
|
var value = new Dictionary<object, object>
|
||
|
{
|
||
|
{ "handle", handleEdit.Text },
|
||
|
{ "values",_values},
|
||
|
};
|
||
|
|
||
|
var json = JsonHelper.Get(value);
|
||
|
|
||
|
return json;
|
||
|
}
|
||
|
|
||
|
public override void Clear()
|
||
|
{
|
||
|
_values.Clear();
|
||
|
}
|
||
|
|
||
|
public override void OnStart()
|
||
|
{
|
||
|
generateButton.Pressed += () =>
|
||
|
{
|
||
|
handleEdit.Text = IDIS_Service.GenerateHandle();
|
||
|
};
|
||
|
}
|
||
|
}
|