调整了模板
This commit is contained in:
23
Mods/工业数据采集与分析应用分享/Scripts/Builder/IDIS_RegisterDB.cs
Normal file
23
Mods/工业数据采集与分析应用分享/Scripts/Builder/IDIS_RegisterDB.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BITKit;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace BITFactory;
|
||||
[GlobalClass]
|
||||
public partial class IDIS_RegisterDB : FormDBProvider
|
||||
{
|
||||
public override void Submit(string data)
|
||||
{
|
||||
var jObject = JsonConvert.DeserializeObject<JObject>(data);
|
||||
var handle = jObject["handle"]!.ToObject<string>();
|
||||
var values = jObject["values"]!.ToObject<List<IDIS_Data>>();
|
||||
|
||||
foreach (var x in values)
|
||||
{
|
||||
IDIS_Service.Singleton.Register(handle,x.Name, x.Format, x.Value,x.Category);
|
||||
}
|
||||
}
|
||||
}
|
77
Mods/工业数据采集与分析应用分享/Scripts/Builder/IDIS_RegisterWeaver.cs
Normal file
77
Mods/工业数据采集与分析应用分享/Scripts/Builder/IDIS_RegisterWeaver.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
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();
|
||||
};
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using BITKit;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace BITFactory;
|
||||
|
||||
[Serializable]
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class IDIS_TemplateForm:IFormField
|
||||
{
|
||||
[JsonProperty]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty]
|
||||
public string Type { get; set; }
|
||||
[JsonProperty]
|
||||
public string DefaultValue { get; set; }
|
||||
[JsonProperty]
|
||||
public string Category { get; set; }
|
||||
public int FieldCount => 4;
|
||||
public string[] FieldNames => new string[]
|
||||
{
|
||||
nameof(Name),
|
||||
nameof(Type),
|
||||
nameof(DefaultValue),
|
||||
nameof(Category),
|
||||
};
|
||||
public string[] FieldTypes => FieldNames;
|
||||
public string[] DefaultValues => FieldNames;
|
||||
}
|
||||
|
||||
[GlobalClass]
|
||||
public partial class IDIS_TemplateFormResource : FormResource
|
||||
{
|
||||
public override string Name { get; set; }
|
||||
public override IFormField[] Fields { get; set; }
|
||||
}
|
79
Mods/工业数据采集与分析应用分享/Scripts/Builder/IDIS_TemplateResource.cs
Normal file
79
Mods/工业数据采集与分析应用分享/Scripts/Builder/IDIS_TemplateResource.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using BITKit;
|
||||
using BITKit.IO;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace BITFactory;
|
||||
[GlobalClass]
|
||||
public partial class IDIS_TemplateResource : TemplateResource
|
||||
{
|
||||
private static readonly List<FormResource> Templates=new();
|
||||
private static InitializationState state = InitializationState.None;
|
||||
private static string assetPath => PathHelper.GetPath("标识模板资源包.zip");
|
||||
private static string entryPath => "Templates.json";
|
||||
public override FormResource[] GetTemplates()
|
||||
{
|
||||
EnsureCreated();
|
||||
return Templates.ToArray();
|
||||
}
|
||||
public override string[] GetTemplateNames()
|
||||
{
|
||||
EnsureCreated();
|
||||
return Templates.Select(x => x.Name).ToArray();
|
||||
}
|
||||
public override FormResource GetTemplate(string name)
|
||||
{
|
||||
EnsureCreated();
|
||||
return Templates.Single(x => x.Name == name);
|
||||
}
|
||||
public override bool IsSupportCreateTemplate => true;
|
||||
public override void CreateTemplate()
|
||||
{
|
||||
Templates.Add(new IDIS_TemplateFormResource()
|
||||
{
|
||||
Name = "新的标识模板:"+Guid.NewGuid(),
|
||||
Fields = new IFormField[]
|
||||
{
|
||||
new IDIS_TemplateForm()
|
||||
}
|
||||
});
|
||||
}
|
||||
private void EnsureCreated()
|
||||
{
|
||||
if (state != InitializationState.None) return;
|
||||
if (File.Exists(assetPath))
|
||||
{
|
||||
foreach (var x in BITAssets.Read<KeyValuePair<string,IDIS_TemplateForm[]>[]>(assetPath, entryPath))
|
||||
{
|
||||
Templates.Add(new IDIS_TemplateFormResource()
|
||||
{
|
||||
Name = x.Key,
|
||||
Fields = x.Value.Select(_=>_ as IFormField).ToArray()
|
||||
});
|
||||
}
|
||||
}
|
||||
state = InitializationState.Initialized;
|
||||
}
|
||||
|
||||
public override void OnStop()
|
||||
{
|
||||
ManualSave();
|
||||
}
|
||||
|
||||
public override void ManualSave()
|
||||
{
|
||||
// var values = new System.Collections.Generic.Dictionary<string, List<IFormField>>(
|
||||
// Templates.Select(x=>new KeyValuePair<string, List<IFormField>>(
|
||||
// x.Key,x.Value.Fields.ToList()
|
||||
// ))
|
||||
// );
|
||||
var values = Templates.Select(x => new KeyValuePair<string, object>(
|
||||
x.Name, x.Fields
|
||||
));
|
||||
BITAssets.Build(assetPath,new BITAsset(entryPath,JsonHelper.Get(values)));
|
||||
}
|
||||
}
|
143
Mods/工业数据采集与分析应用分享/Scripts/Builder/IDIS_TemplateWeaver.cs
Normal file
143
Mods/工业数据采集与分析应用分享/Scripts/Builder/IDIS_TemplateWeaver.cs
Normal file
@@ -0,0 +1,143 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BITKit;
|
||||
|
||||
namespace BITFactory;
|
||||
[GlobalClass]
|
||||
public partial class IDIS_TemplateWeaver : FormWeaverResource
|
||||
{
|
||||
[Export] private NodePath addFieldsButtonPath;
|
||||
[Export] private NodePath templateBuilderPath;
|
||||
[Export] private NodePath templateNameEditPath;
|
||||
[Export] private NodePath saveTemplateNameButtonPath;
|
||||
private Button addFieldsButton => formBuilder.GetNode<Button>(addFieldsButtonPath);
|
||||
private TemplateBuilder templateBuilder => formBuilder.GetNode<TemplateBuilder>(templateBuilderPath);
|
||||
private LineEdit templateNameEdit => formBuilder.GetNode<LineEdit>(templateNameEditPath);
|
||||
private Button saveTemplateNameButton => formBuilder.GetNode<Button>(saveTemplateNameButtonPath);
|
||||
|
||||
private readonly List<IDIS_TemplateForm> fields = new();
|
||||
public override void Weaver(Control container, IFormField formField)
|
||||
{
|
||||
var field = formField as IDIS_TemplateForm;
|
||||
|
||||
fields.Add(field);
|
||||
|
||||
var hBox = container.Create<HBoxContainer>();
|
||||
var nameEdit = hBox.Create<LineEdit>();
|
||||
var typeButton = hBox.Create<OptionButton>();
|
||||
var defaultValueEdit = hBox.Create<LineEdit>();
|
||||
var categoryEdit = hBox.Create<LineEdit>();
|
||||
var removeButton = hBox.Create<Button>();
|
||||
|
||||
nameEdit.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||||
typeButton.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||||
defaultValueEdit.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||||
categoryEdit.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||||
|
||||
nameEdit.PlaceholderText="名称";
|
||||
typeButton.Text = "类型";
|
||||
defaultValueEdit.PlaceholderText="默认值";
|
||||
categoryEdit.PlaceholderText="分类";
|
||||
|
||||
typeButton.GetPopup().AddItem("string");
|
||||
typeButton.GetPopup().AddItem("int");
|
||||
typeButton.GetPopup().AddItem("ulong");
|
||||
typeButton.GetPopup().AddItem("double");
|
||||
typeButton.GetPopup().AddItem("h_site");
|
||||
typeButton.GetPopup().AddItem("base64");
|
||||
typeButton.GetPopup().AddItem("guid");
|
||||
|
||||
typeButton.Selected = 0;
|
||||
|
||||
nameEdit.Text = field!.Name;
|
||||
typeButton.Text = field!.Type;
|
||||
defaultValueEdit.Text = field!.DefaultValue;
|
||||
categoryEdit.Text = field!.Category;
|
||||
removeButton.Text= "删除";
|
||||
|
||||
nameEdit.TextChanged+=x=>field!.Name=x;
|
||||
typeButton.ItemSelected+=x=>field!.Type=typeButton.GetPopup().GetItemText((int)x);
|
||||
defaultValueEdit.TextChanged+=x=>field!.DefaultValue=x;
|
||||
categoryEdit.TextChanged+=x=>field!.Category=x;
|
||||
|
||||
removeButton.Pressed+=()=>
|
||||
{
|
||||
fields.Remove(field!);
|
||||
container.QueueFree();
|
||||
|
||||
var current = templateBuilder.CurrentTemplate.Fields.ToList();
|
||||
current.Remove(formField);
|
||||
templateBuilder.CurrentTemplate.Fields = current.ToArray();
|
||||
};
|
||||
}
|
||||
|
||||
public override string GetContent()
|
||||
{
|
||||
if (fields.Any(x =>
|
||||
{
|
||||
switch (x.Name, x.Type, x.DefaultValue, x.Category)
|
||||
{
|
||||
case ("", _, _, _):
|
||||
case (_, "", _, _):
|
||||
case (_, _, "", _):
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}))
|
||||
{
|
||||
throw new InvalidOperationException("请填写完整");
|
||||
}
|
||||
var value = JsonHelper.Get(fields);
|
||||
return value;
|
||||
}
|
||||
public override void Clear()
|
||||
{
|
||||
fields.Clear();
|
||||
templateNameEdit.Text = templateBuilder.CurrentTemplate?.Name;
|
||||
}
|
||||
public override void OnStart()
|
||||
{
|
||||
addFieldsButton.Pressed+=AddFields;
|
||||
|
||||
templateNameEdit.TextSubmitted+=ChangeCurrentTemplateName;
|
||||
saveTemplateNameButton.Pressed+=()=>
|
||||
{
|
||||
ChangeCurrentTemplateName(templateNameEdit.Text);
|
||||
};
|
||||
}
|
||||
private void AddFields()
|
||||
{
|
||||
var current = templateBuilder.CurrentTemplate.Fields.ToList();
|
||||
current.Add(new IDIS_TemplateForm()
|
||||
{
|
||||
|
||||
});
|
||||
templateBuilder.CurrentTemplate.Fields = current.ToArray();
|
||||
|
||||
templateBuilder.Rebuild();
|
||||
}
|
||||
|
||||
private void ChangeCurrentTemplateName(string newName)
|
||||
{
|
||||
if(templateBuilder.CurrentTemplate==null) return;
|
||||
|
||||
if (templateBuilder.template.GetTemplates().Any(x => x.Name == newName))
|
||||
// ReSharper disable once StringLiteralTypo
|
||||
newName+=DateTime.Now.ToString("mmss");
|
||||
|
||||
templateBuilder.CurrentTemplate.Name = newName;
|
||||
|
||||
templateBuilder.template.ManualSave();
|
||||
|
||||
templateBuilder.Rebuild();
|
||||
|
||||
UXContextMenu
|
||||
.Create()
|
||||
.AddAction("New PopopMenu",null)
|
||||
.Build();
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user