调整了模板

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

@@ -0,0 +1,46 @@
using Godot;
using System;
using System.Collections.Generic;
using BITFactory;
namespace BITKit;
[GlobalClass]
public partial class ExampleFormResource : FormResource
{
public ExampleFormResource(){}
public ExampleFormResource(string name)
{
this.name = name;
}
public struct FormField : IFormField
{
public int FieldCount => 2;
public string[] FieldNames => new[] {"Filed 1", "Field 2"};
public string[] FieldTypes=> new[] {"string", "int"};
public string[] DefaultValues=> new[] {"null", "0"};
}
[Export] private string name;
public override string Name
{
get => name;
set => name = value;
}
public override IFormField[] Fields
{
get
{
var list = new List<IFormField>();
for (var i = 0; i < GD.RandRange(1, 6); i++)
{
list.Add(new FormField());
}
return list.ToArray();
}
set => throw new NotImplementedException();
}
}

View File

@@ -0,0 +1,60 @@
using Godot;
using System;
using System.Collections.Generic;
using BITFactory;
namespace BITKit;
[GlobalClass]
public partial class ExampleFormWeaver : FormWeaverResource
{
private readonly List<List<string>> _values=new();
public override void Weaver(Control container, IFormField formField)
{
var layout = new HBoxContainer();
var index = _values.Count;
var list = new List<string>();
_values.Add(list);
for (var i = 0; i < formField.FieldCount; i++)
{
var label = new Label();
var lineEdit = new UXLineEdit();
var myIndex = i;
list.Add(string.Empty);
lineEdit.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
var name = formField.FieldNames[i];
var type = formField.FieldTypes[i];
var DefaultValue = formField.DefaultValues[i];
label.Text = name;
lineEdit.PlaceholderText = DefaultValue;
layout.AddChild(label);
layout.AddChild(lineEdit);
lineEdit.TextChanged += s =>
{
list[myIndex] = s;
};
}
container.AddChild(layout);
}
public override string GetContent()
{
var value = JsonHelper.Get(_values);
GD.Print(value);
return value;
}
public override void Clear()
{
_values.Clear();
}
}