调整了模板

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,7 @@
[gd_scene load_steps=2 format=3 uid="uid://if0lpo1vxjax"]
[ext_resource type="Script" path="res://BITKit/Scripts/UX/UXContextMenu.cs" id="1_i7uwt"]
[node name="UXContextMenu" type="PopupMenu"]
visible = true
script = ExtResource("1_i7uwt")

View File

@ -2,12 +2,14 @@
[ext_resource type="Script" path="res://BITKit/Scripts/UX/UXContainer.cs" id="1_yrfyl"]
[node name="LineEditTemplate" type="PanelContainer" node_paths=PackedStringArray("label", "labels", "lineEdit", "lineEdits")]
[node name="LineEditTemplate" type="PanelContainer" node_paths=PackedStringArray("label", "labels", "buttons", "lineEdit", "lineEdits", "optionButtons")]
script = ExtResource("1_yrfyl")
label = NodePath("MarginContainer/Layout/0/Label")
labels = [NodePath("MarginContainer/Layout/0/Label"), NodePath("MarginContainer/Layout/1/Label"), NodePath("MarginContainer/Layout/2/Label")]
buttons = []
lineEdit = NodePath("MarginContainer/Layout/0/LineEdit")
lineEdits = [NodePath("MarginContainer/Layout/0/LineEdit"), NodePath("MarginContainer/Layout/1/LineEdit"), NodePath("MarginContainer/Layout/2/LineEdit")]
optionButtons = []
[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 2

File diff suppressed because one or more lines are too long

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();
}
}

View File

@ -0,0 +1,75 @@
using Godot;
using System;
using System.Collections.Generic;
using System.Net.Http;
// ReSharper disable MemberCanBePrivate.Global
namespace BITKit;
public partial class FormBuilder : Node
{
[ExportCategory(Constant.Header.Providers)] [Export]
private FormWeaverResource formWeaver;
[Export] private FormDBProvider formDBProvider;
[ExportCategory("UI 绑定")] [Export] private NodeBuilder nodeBuilder;
[Export] private Button submitButton;
[Export] private RichTextLabel logLabel;
public override void _Ready()
{
try
{
nodeBuilder.Clear();
if (submitButton is not null && formDBProvider is not null)
submitButton.Pressed += Submit;
}
catch (Exception)
{
GD.PushWarning(GetPath());
throw;
}
}
public override void _EnterTree()
{
formWeaver.formBuilder = this;
formWeaver.OnStart();
}
public override void _ExitTree()
{
formWeaver.OnStop();
}
public void Build(FormResource formProvider)
{
nodeBuilder.Clear();
formWeaver.Clear();
foreach (var formField in formProvider.Fields)
{
var container = nodeBuilder.Build<Control>();
formWeaver.Weaver(container, formField);
}
}
private void Submit()
{
try
{
var data = formWeaver.GetContent();
formDBProvider.Submit(data);
logLabel.Text = "提交成功:" + DateTime.Now;
}
catch (Exception e)
{
logLabel.Text = e.Message + DateTime.Now;
}
}
}

View File

@ -0,0 +1,9 @@
using Godot;
using System;
namespace BITKit;
[GlobalClass]
public abstract partial class FormDBProvider : Resource
{
public abstract void Submit(string data);
}

View File

@ -0,0 +1,20 @@
using Godot;
using System;
using BITFactory;
namespace BITKit;
public interface IFormField
{
int FieldCount { get; }
string[] FieldNames { get; }
string[] FieldTypes { get; }
string[] DefaultValues { get; }
}
[GlobalClass]
public abstract partial class FormResource : Resource
{
public abstract string Name { get; set;}
public abstract IFormField[] Fields { get; set; }
}

View File

@ -0,0 +1,14 @@
using Godot;
using System;
namespace BITKit;
[GlobalClass]
public abstract partial class FormWeaverResource : Resource,IStart,IStop
{
public FormBuilder formBuilder { get; set; }
public abstract void Weaver(Control container,IFormField formField);
public abstract string GetContent();
public abstract void Clear();
public virtual void OnStart(){}
public virtual void OnStop(){}
}

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 T Build<T>() where T : Node
{
Node instance;
if (template is not null)
{
instance = template.Instantiate<T>();
public Node Build()
{
var instance = template.Instantiate();
if (container is not null)
{
container.AddChild(instance);
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)
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);
}
}
}

View File

@ -0,0 +1,19 @@
using Godot;
using System;
using System.Linq;
using Godot.Collections;
namespace BITKit;
[GlobalClass]
public partial class ScriptableTemplate : TemplateResource
{
[Export] private Array<FormResource> templates;
public override FormResource[] GetTemplates() => templates.ToArray();
public override string[] GetTemplateNames() => templates.Select(x => x.Name).ToArray();
public override FormResource GetTemplate(string name) => templates.Single(x => x.Name == name);
public override bool IsSupportCreateTemplate => true;
public override void CreateTemplate()
{
templates.Add(new ExampleFormResource("New Template" + DateTime.Now));
}
}

View File

@ -0,0 +1,66 @@
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);
}
}

View File

@ -0,0 +1,17 @@
using Godot;
using System;
namespace BITKit;
[GlobalClass]
public abstract partial class TemplateResource : Resource, IStart, IStop
{
public abstract FormResource[] GetTemplates();
public abstract string[] GetTemplateNames();
public abstract FormResource GetTemplate(string name);
public abstract bool IsSupportCreateTemplate { get; }
public abstract void CreateTemplate();
public virtual void OnStart(){}
public virtual void OnStop(){}
public virtual void ManualSave(){}
}

View File

@ -11,6 +11,7 @@ public partial class BITAppForGodot : Node
{
public static readonly ValidHandle AllowCursor = new();
public static float DeltaTime { get; private set; }
public static BITAppForGodot Singleton { get; private set; }
/// <summary>
/// 在构造函数中注册Logger
@ -30,6 +31,8 @@ public partial class BITAppForGodot : Node
public override void _Ready()
{
Singleton = this;
BIT4Log.Log<BITAppForGodot>("正在创建BITWebApp");
//添加测试用HttpClient

View File

@ -21,7 +21,7 @@ public static class LabelExtensions
{
self.Text = text;
}
catch (Exception e)
catch (Exception)
{
BIT4Log.Warnning(path);
throw;

View File

@ -35,4 +35,11 @@ public static partial class MathNode
x.QueueFree();
}
}
public static T Create<T>(this Node self) where T : Node,new()
{
var t = new T();
self.AddChild(t);
return t;
}
}

View File

@ -4,34 +4,29 @@ using Godot.Collections;
namespace BITKit;
public interface IUXContainer
{
string Text { get; set; }
void SetText(string text);
Texture2D Icon { get; set; }
void SetIcon(Texture2D texture);
}
public partial class UXContainer:Control,IUXContainer
public partial class UXContainer:Control
{
[Export] public Label label;
[Export] public RichTextLabel richTextLabel;
[Export] public Label titleLabel;
[Export] public TextureRect icon;
[Export] public Button button;
[Export] public Node contextContainer;
[ExportCategory("Label")]
[Export] public Label updateTimeLabel;
[Export] public Label createTimeLabel;
[Export] public Label headerLabel;
[ExportCategory(nameof(Label))]
[Export] public Array<Label> labels;
[ExportCategory("Button")]
[Export] public Button mainButton;
[Export] public Button secButton;
[Export] public Button thirdButton;
[ExportCategory("Text Edit")]
[ExportCategory(nameof(Button))]
[Export] public Button button;
[Export] public Array<Button> buttons;
[ExportCategory(nameof(TextEdit))]
[Export] public LineEdit lineEdit;
[Export] public Array<LineEdit> lineEdits;
[ExportCategory(nameof(OptionButton))]
[Export] public OptionButton optionButton;
[Export] public Array<OptionButton> optionButtons;
public string Text
{
get =>label is not null ? label.Text : richTextLabel.Text;
@ -52,28 +47,4 @@ public partial class UXContainer:Control,IUXContainer
{
Text=text;
}
public void AddContainer(Node node)
{
contextContainer.AddChild(node);
}
public void ClearContainer()
{
foreach (var x in contextContainer.GetChildren())
{
x.QueueFree();
}
}
public Texture2D Icon
{
get => icon.Texture;
set => icon.Texture=value;
}
public void SetIcon(Texture2D texture)
{
Icon = texture;
}
}

View File

@ -0,0 +1,46 @@
using System;
using Godot;
namespace BITKit;
public class UXContextMenuBuilder
{
public void Build()
{
UXContextMenu.Singleton.Position = UXContextMenu.MousePosition;
UXContextMenu.Singleton.Show();
}
}
public static class UXContextMenuExtensions
{
public static UXContextMenuBuilder AddAction(this UXContextMenuBuilder self,string name,Action action)
{
UXContextMenu.Singleton.AddItem(name);
return self;
}
}
[GlobalClass]
public partial class UXContextMenu:PopupMenu
{
public static UXContextMenu Singleton { get; private set; }
public static Vector2I MousePosition { get; private set; }
public override void _Ready()
{
Singleton = this;
}
public static UXContextMenuBuilder Create()
{
Singleton.Clear();
return new UXContextMenuBuilder();
}
public override void _Input(InputEvent @event)
{
if (@event is InputEventMouseMotion motion)
{
MousePosition = (Vector2I)motion.Position;
}
}
}

View File

@ -16,6 +16,7 @@ public partial class UXLineEdit : LineEdit
private void OnTextChanged(string newText)
{
if (hints is null) return;
if (textValidation is not null && textValidation.IsTextValid(newText,out var errorReason) is false)
{
hints.Text = $"[color=red]{errorReason}[/color]";

View File

@ -0,0 +1,12 @@
[gd_resource type="Resource" script_class="IDIS_AutoRegResource" load_steps=2 format=3 uid="uid://cs0mh0ev6u0cf"]
[ext_resource type="Script" path="res://Mods/工业数据采集与分析应用分享/Scripts/IDIS_AutoRegResource.cs" id="1_vgs8l"]
[resource]
script = ExtResource("1_vgs8l")
HandleSeed = ""
Format = ""
Category = ""
Name = ""
Value = ""
RefHandleSeed = ""

View File

@ -0,0 +1,12 @@
[gd_resource type="Resource" script_class="IDIS_AutoRegResource" load_steps=2 format=3 uid="uid://574gf1b8pq71"]
[ext_resource type="Script" path="res://Mods/工业数据采集与分析应用分享/Scripts/IDIS_AutoRegResource.cs" id="1_xdojh"]
[resource]
script = ExtResource("1_xdojh")
HandleSeed = ""
Format = ""
Category = ""
Name = ""
Value = ""
RefHandleSeed = ""

View File

@ -0,0 +1,12 @@
[gd_resource type="Resource" script_class="IDIS_AutoRegResource" load_steps=2 format=3 uid="uid://vsysp5ftn5do"]
[ext_resource type="Script" path="res://Mods/工业数据采集与分析应用分享/Scripts/IDIS_AutoRegResource.cs" id="1_4uwqb"]
[resource]
script = ExtResource("1_4uwqb")
HandleSeed = ""
Format = ""
Category = ""
Name = ""
Value = ""
RefHandleSeed = ""

View File

@ -0,0 +1,12 @@
[gd_resource type="Resource" script_class="IDIS_AutoRegResource" load_steps=2 format=3 uid="uid://c2he5e5rahatp"]
[ext_resource type="Script" path="res://Mods/工业数据采集与分析应用分享/Scripts/IDIS_AutoRegResource.cs" id="1_b50nr"]
[resource]
script = ExtResource("1_b50nr")
HandleSeed = ""
Format = ""
Category = ""
Name = ""
Value = ""
RefHandleSeed = ""

View File

@ -0,0 +1,12 @@
[gd_resource type="Resource" script_class="IDIS_AutoRegResource" load_steps=2 format=3 uid="uid://b38onsp3c3jem"]
[ext_resource type="Script" path="res://Mods/工业数据采集与分析应用分享/Scripts/IDIS_AutoRegResource.cs" id="1_3kqe2"]
[resource]
script = ExtResource("1_3kqe2")
HandleSeed = "th.record"
Format = "float"
Category = "环境"
Name = "温度"
Value = "42"
RefHandleSeed = ""

View File

@ -0,0 +1,12 @@
[gd_resource type="Resource" script_class="IDIS_AutoRegResource" load_steps=2 format=3 uid="uid://d3xam2no2uaas"]
[ext_resource type="Script" path="res://Mods/工业数据采集与分析应用分享/Scripts/IDIS_AutoRegResource.cs" id="1_lqwbc"]
[resource]
script = ExtResource("1_lqwbc")
HandleSeed = "th.record"
Format = "float"
Category = "环境"
Name = "湿度"
Value = "50"
RefHandleSeed = "th"

View File

@ -0,0 +1,12 @@
[gd_resource type="Resource" script_class="IDIS_AutoRegResource" load_steps=2 format=3 uid="uid://cgk1wmiqqedmi"]
[ext_resource type="Script" path="res://Mods/工业数据采集与分析应用分享/Scripts/IDIS_AutoRegResource.cs" id="1_8mak5"]
[resource]
script = ExtResource("1_8mak5")
HandleSeed = "th"
Format = "string"
Category = "参数"
Name = "型号"
Value = "th.sensor"
RefHandleSeed = "th.record"

View File

@ -0,0 +1,12 @@
[gd_resource type="Resource" script_class="IDIS_AutoRegResource" load_steps=2 format=3 uid="uid://hixuaakj8opt"]
[ext_resource type="Script" path="res://Mods/工业数据采集与分析应用分享/Scripts/IDIS_AutoRegResource.cs" id="1_hthhx"]
[resource]
script = ExtResource("1_hthhx")
HandleSeed = ""
Format = ""
Category = ""
Name = ""
Value = ""
RefHandleSeed = ""

View File

@ -0,0 +1,12 @@
[gd_resource type="Resource" script_class="IDIS_AutoRegResource" load_steps=2 format=3 uid="uid://ngju0miy7a6b"]
[ext_resource type="Script" path="res://Mods/工业数据采集与分析应用分享/Scripts/IDIS_AutoRegResource.cs" id="1_brytp"]
[resource]
script = ExtResource("1_brytp")
HandleSeed = ""
Format = ""
Category = ""
Name = ""
Value = ""
RefHandleSeed = ""

View File

@ -0,0 +1,12 @@
[gd_resource type="Resource" script_class="IDIS_AutoRegResource" load_steps=2 format=3 uid="uid://c4a5buevs88ko"]
[ext_resource type="Script" path="res://Mods/工业数据采集与分析应用分享/Scripts/IDIS_AutoRegResource.cs" id="1_25hnv"]
[resource]
script = ExtResource("1_25hnv")
HandleSeed = ""
Format = ""
Category = ""
Name = ""
Value = ""
RefHandleSeed = ""

View 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);
}
}
}

View 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();
};
}
}

View File

@ -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; }
}

View 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)));
}
}

View 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();
}
}

View File

@ -0,0 +1,19 @@
using Godot;
using System;
namespace BITFactory;
[GlobalClass]
public partial class IDIS_AutoRegResource : Resource
{
[Export] public string HandleSeed;
[ExportCategory("IDIS")]
[Export] public string Format;
[Export] public string Category;
[Export] public string Name;
[Export] public string Value;
[ExportCategory("标识引用")]
[Export] public string RefHandleSeed;
}

View File

@ -0,0 +1,85 @@
using Godot;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BITFactory;
using BITKit;
using Godot.Collections;
namespace BITFactory;
public partial class IDIS_AutoRegister : Node
{
[Export] private Array<IDIS_AutoRegResource> regResources;
[ExportCategory("UI 绑定")]
[Export] private Array<ProgressBar> progressBars;
[Export] private RichTextLabel logLabel;
private readonly Queue<ProgressBar> _progressQueue = new();
private ProgressBar _currentProgressBar;
private void Register()
{
BIT4Log.Log<IDIS_AutoRegister>("开始自动注册中...");
var seeds = new List<string>();
foreach (var x in regResources)
{
seeds.Add(x.HandleSeed);
if (string.IsNullOrEmpty(x.RefHandleSeed) is false)
{
seeds.Add(x.RefHandleSeed);
}
}
seeds = seeds.Distinct().ToList();
var handles =
new System.Collections.Generic.Dictionary<string, string>(seeds.Select(x =>
new KeyValuePair<string, string>(x, IDIS_Service.GenerateHandle())));
try
{
foreach (var x in regResources)
{
var handle = handles[x.HandleSeed];
IDIS_Service.Singleton.Register(handle, x.Name, x.Format, x.Value, x.Category);
if (string.IsNullOrEmpty(x.RefHandleSeed) is false && handles.TryGetValue(x.RefHandleSeed, out var refHandle))
{
IDIS_Service.Singleton.RegisterReference(handle, refHandle);
}
logLabel.Text+=$"\n[{DateTime.Now}]{x.Name} 已注册,使用标识: {handle}";
}
}
catch (Exception e)
{
logLabel.Text += $"\n[color=red]错误:\n{e.Message}[/color]";
}
foreach (var x in progressBars)
{
x.Value = x.MinValue;
_progressQueue.Enqueue(x);
}
}
public override void _Process(double delta)
{
switch (_currentProgressBar)
{
case null when _progressQueue.Count == 0:
return;
case null:
_progressQueue.TryDequeue(out _currentProgressBar);
return;
case (var x) when x.Value >= x.MaxValue:
_progressQueue.TryDequeue(out _currentProgressBar);
return;
default:
_currentProgressBar.Value +=
Mathf.Lerp(_currentProgressBar.MinValue, _currentProgressBar.MaxValue, delta);
break;
}
}
}

View File

@ -1,155 +0,0 @@
using Godot;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using BITKit;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
namespace BITFactory;
public partial class IDIS_RegisterService : Node
{
[ExportCategory("Services")]
[Export] private IDIS_Service service;
[Export] private IDIS_TemplateService templateService;
[ExportCategory("UI 绑定")]
[Export] private NodeBuilder templateIndexBuilder;
[Export] private LineEdit handleEdit;
[Export] private Button generateHandleButton;
[Export] private NodeBuilder templateFormatBuilder;
[Export] private Button registerButton;
[Export] private ProgressBar registerProgress;
[ExportCategory("Register Reference")]
[Export] private Control referenceContainer;
[Export] private Button addReferenceButton;
[ExportCategory("Hints")]
[Export] private Label hints;
private readonly List<(string format,string value,string category)> _currentValues = new();
private readonly List<string> _currentReferences = new();
public override void _Ready()
{
registerButton.Pressed += Register;
generateHandleButton.Pressed += ()=>handleEdit.Text = IDIS_Service.GenerateHandle();
addReferenceButton.Pressed += AddReferenceEdit;
handleEdit.Editable = false;
registerButton.Disabled = true;
Rebuild();
}
private void Rebuild()
{
if (Engine.IsEditorHint()) return;
templateIndexBuilder.Clear();
templateFormatBuilder.Clear();
foreach (var x in templateService.templates)
{
var container = templateIndexBuilder.Build<UXContainer>();
container.button.Text = x.TemplateName;
container.button.Pressed += () =>
{
Entry(x);
};
}
}
private void Entry(IDIS_Template template)
{
_currentValues.Clear();
templateFormatBuilder.Clear();
var currentIndex = 0;
foreach (var x in template.Formats)
{
var myIndex = currentIndex++;
_currentValues.Add((x.format, string.Empty, x.category));
var formatContainer = templateFormatBuilder.Build<UXContainer>();
formatContainer.labels[0].Text = x.format;
formatContainer.lineEdits[0].PlaceholderText = x.hint;
formatContainer.lineEdits[0].TextChanged += s =>
{
var value = _currentValues[myIndex];
value.value = s;
_currentValues[myIndex] = value;
};
}
handleEdit.Editable = true;
registerButton.Disabled = false;
}
private void AddReferenceEdit()
{
var lineEdit = new LineEdit();
var currentIndex = referenceContainer.GetChildCount();
_currentReferences.Add(string.Empty);
lineEdit.TextChanged += s =>
{
_currentReferences[currentIndex] = s;
};
lineEdit.Text = "88.123.99/";
referenceContainer.AddChild(lineEdit);
}
private void Register()
{
if (_currentValues.Any(x =>
string.IsNullOrEmpty(x.format) || string.IsNullOrEmpty(x.value) || string.IsNullOrEmpty(x.category)))
{
hints.SetTextAsync("请填写完整的数据格式");
return;
}
var handle = string.IsNullOrEmpty(handleEdit.Text) ? IDIS_Service.GenerateHandle() : handleEdit.Text;
var dataJson = JsonHelper.Get(_currentValues);
var referenceJson = JsonHelper.Get(_currentReferences);
BIT4Log.Log<IDIS_RegisterService>($"注册标识:{handle}");
BIT4Log.Log<IDIS_RegisterService>($"\n{dataJson}");
BIT4Log.Log<IDIS_RegisterService>("注册引用:");
BIT4Log.Log<IDIS_RegisterService>($"\n{referenceJson}");
hints.Text="正在注册...";
service.Register(handle);
foreach (var x in _currentValues)
{
service.Register(handle, x.format, x.value,x.category);
}
foreach (var x in _currentReferences)
{
service.RegisterReference(handle, x);
}
var tween = CreateTween();
registerButton.Disabled = true;
registerProgress.Value = 0;
tween.TweenProperty(registerProgress, "value", registerProgress.MaxValue, 0.5f);
tween.Finished+= () =>
{
registerProgress.Value = 0;
registerProgress.Visible = false;
registerButton.Disabled = false;
hints.Text = "注册成功";
tween.Stop();
};
tween.Play();
handleEdit.Text = string.Empty;
}
}

View File

@ -95,7 +95,7 @@ public partial class IDIS_SearchService : Node
{
var container = valueTemplate.Instantiate<UXContainer>();
container.labels[0].Text = x.Format;
container.labels[0].Text = x.Name;
container.labels[1].Text = x.Value;
container.labels[2].Text = x.UpdateTime.ToString(CultureInfo.InvariantCulture);
container.labels[3].Text = x.CreateTime.ToString(CultureInfo.InvariantCulture);

View File

@ -72,6 +72,10 @@ public class IDIS_Data:IDIS_Base
/// </summary>
public string Handle { get; set; }
/// <summary>
/// 记录的名称,通常为中文
/// </summary>
public string Name { get; set; }
/// <summary>
/// 值类型,例如string,url,site
/// </summary>
public string Format { get; set; }
@ -184,7 +188,7 @@ public class IDIS_DBContext:DbContext
SaveChangesAsync();
return true;
}
public void Register(string handle,string format, string value,string category)
public void Register(string handle,string name,string format, string value,string category)
{
var handleExists = Values.Any(x => x.Handle == handle);
if (!handleExists)
@ -193,6 +197,7 @@ public class IDIS_DBContext:DbContext
}
var data = new IDIS_Data()
{
Name = name,
Handle = handle,
Format = format,
Value = value,
@ -228,6 +233,7 @@ public class IDIS_DBContext:DbContext
/// </summary>
public partial class IDIS_Service:Node
{
public static IDIS_Service Singleton { get; private set; }
private static IDIS_DBContext Context;
public override void _Ready()
{
@ -236,6 +242,11 @@ public partial class IDIS_Service:Node
UniTask.Run(()=>Context.Database.EnsureCreatedAsync());
}
public override void _EnterTree()
{
Singleton = this;
}
public override void _ExitTree()
{
Context.Dispose();
@ -244,7 +255,7 @@ public partial class IDIS_Service:Node
public bool Query(string word,out IDIS_Query[] queries) => Context.Query(word, out queries);
public bool Register(string handle) => Context.Register(handle);
public void Register(string handle, string format, string value,string category) => Context.Register(handle, format, value,category);
public void Register(string handle,string name, string format, string value,string category) => Context.Register(handle,name, format, value,category);
public void RegisterReference(string handle,string refenceHandle) => Context.RegisterReference(handle,refenceHandle);
public static string GenerateHandle() => $"88.123.99/{Mathf.Abs(Guid.NewGuid().GetHashCode())}";
public bool Query(string key, out IDIS_Query query) => Context.Query(key, out query);

View File

@ -99,8 +99,8 @@ public partial class IDIS_THService : Node
switch (currentUpdateMode)
{
case UpdateMode.Insert:
service.Register(handle ,"温度", temperature, "环境");
service.Register(handle, "湿度", humidity, "环境");
service.Register(handle,"温度" ,"float", temperature, "环境");
service.Register(handle, "湿度","float", humidity, "环境");
break;
case UpdateMode.Update:
if (service.Update(handle, "温度",temperature) is false)

View File

@ -4,11 +4,13 @@
[ext_resource type="Texture2D" uid="uid://dyxw5ocfiamgi" path="res://Mods/工业数据采集与分析应用分享/Arts/Images/标准ModbusRTU图片.jpg" id="1_yd6oj"]
[ext_resource type="PackedScene" uid="uid://dghty7km181mc" path="res://Mods/工业数据采集与分析应用分享/Templates/关联标识.tscn" id="2_so2ho"]
[node name="TrackContainer" type="PanelContainer" node_paths=PackedStringArray("labels", "lineEdits")]
[node name="TrackContainer" type="PanelContainer" node_paths=PackedStringArray("labels", "buttons", "lineEdits", "optionButtons")]
custom_minimum_size = Vector2(1280, 512)
script = ExtResource("1_4faap")
labels = []
buttons = []
lineEdits = []
optionButtons = []
[node name="VFlex" type="VBoxContainer" parent="."]
layout_mode = 2
@ -91,44 +93,60 @@ layout_mode = 2
theme_type_variation = &"WhitePanel"
text = "订单信息"
[node name="关联标识" parent="VFlex/MarginContainer/HBoxContainer/MarginContainer/VBoxContainer/ScrollContainer/VBoxContainer" node_paths=PackedStringArray("labels") instance=ExtResource("2_so2ho")]
[node name="关联标识" parent="VFlex/MarginContainer/HBoxContainer/MarginContainer/VBoxContainer/ScrollContainer/VBoxContainer" node_paths=PackedStringArray("labels", "buttons", "optionButtons") instance=ExtResource("2_so2ho")]
layout_mode = 2
labels = []
buttons = []
optionButtons = []
[node name="Label2" type="Label" parent="VFlex/MarginContainer/HBoxContainer/MarginContainer/VBoxContainer/ScrollContainer/VBoxContainer"]
layout_mode = 2
theme_type_variation = &"WhitePanel"
text = "生产设备"
[node name="关联标识2" parent="VFlex/MarginContainer/HBoxContainer/MarginContainer/VBoxContainer/ScrollContainer/VBoxContainer" node_paths=PackedStringArray("labels") instance=ExtResource("2_so2ho")]
[node name="关联标识2" parent="VFlex/MarginContainer/HBoxContainer/MarginContainer/VBoxContainer/ScrollContainer/VBoxContainer" node_paths=PackedStringArray("labels", "buttons", "optionButtons") instance=ExtResource("2_so2ho")]
layout_mode = 2
labels = []
buttons = []
optionButtons = []
[node name="关联标识3" parent="VFlex/MarginContainer/HBoxContainer/MarginContainer/VBoxContainer/ScrollContainer/VBoxContainer" node_paths=PackedStringArray("labels") instance=ExtResource("2_so2ho")]
[node name="关联标识3" parent="VFlex/MarginContainer/HBoxContainer/MarginContainer/VBoxContainer/ScrollContainer/VBoxContainer" node_paths=PackedStringArray("labels", "buttons", "optionButtons") instance=ExtResource("2_so2ho")]
layout_mode = 2
labels = []
buttons = []
optionButtons = []
[node name="Label3" type="Label" parent="VFlex/MarginContainer/HBoxContainer/MarginContainer/VBoxContainer/ScrollContainer/VBoxContainer"]
layout_mode = 2
theme_type_variation = &"WhitePanel"
text = "生产环境"
[node name="关联标识4" parent="VFlex/MarginContainer/HBoxContainer/MarginContainer/VBoxContainer/ScrollContainer/VBoxContainer" node_paths=PackedStringArray("labels") instance=ExtResource("2_so2ho")]
[node name="关联标识4" parent="VFlex/MarginContainer/HBoxContainer/MarginContainer/VBoxContainer/ScrollContainer/VBoxContainer" node_paths=PackedStringArray("labels", "buttons", "optionButtons") instance=ExtResource("2_so2ho")]
layout_mode = 2
labels = []
buttons = []
optionButtons = []
[node name="关联标识5" parent="VFlex/MarginContainer/HBoxContainer/MarginContainer/VBoxContainer/ScrollContainer/VBoxContainer" node_paths=PackedStringArray("labels") instance=ExtResource("2_so2ho")]
[node name="关联标识5" parent="VFlex/MarginContainer/HBoxContainer/MarginContainer/VBoxContainer/ScrollContainer/VBoxContainer" node_paths=PackedStringArray("labels", "buttons", "optionButtons") instance=ExtResource("2_so2ho")]
layout_mode = 2
labels = []
buttons = []
optionButtons = []
[node name="关联标识6" parent="VFlex/MarginContainer/HBoxContainer/MarginContainer/VBoxContainer/ScrollContainer/VBoxContainer" node_paths=PackedStringArray("labels") instance=ExtResource("2_so2ho")]
[node name="关联标识6" parent="VFlex/MarginContainer/HBoxContainer/MarginContainer/VBoxContainer/ScrollContainer/VBoxContainer" node_paths=PackedStringArray("labels", "buttons", "optionButtons") instance=ExtResource("2_so2ho")]
layout_mode = 2
labels = []
buttons = []
optionButtons = []
[node name="关联标识7" parent="VFlex/MarginContainer/HBoxContainer/MarginContainer/VBoxContainer/ScrollContainer/VBoxContainer" node_paths=PackedStringArray("labels") instance=ExtResource("2_so2ho")]
[node name="关联标识7" parent="VFlex/MarginContainer/HBoxContainer/MarginContainer/VBoxContainer/ScrollContainer/VBoxContainer" node_paths=PackedStringArray("labels", "buttons", "optionButtons") instance=ExtResource("2_so2ho")]
layout_mode = 2
labels = []
buttons = []
optionButtons = []
[node name="关联标识8" parent="VFlex/MarginContainer/HBoxContainer/MarginContainer/VBoxContainer/ScrollContainer/VBoxContainer" node_paths=PackedStringArray("labels") instance=ExtResource("2_so2ho")]
[node name="关联标识8" parent="VFlex/MarginContainer/HBoxContainer/MarginContainer/VBoxContainer/ScrollContainer/VBoxContainer" node_paths=PackedStringArray("labels", "buttons", "optionButtons") instance=ExtResource("2_so2ho")]
layout_mode = 2
labels = []
buttons = []
optionButtons = []

View File

@ -2,14 +2,16 @@
[ext_resource type="Script" path="res://BITKit/Scripts/UX/UXContainer.cs" id="1_fp0bm"]
[node name="标识数据模板" type="PanelContainer" node_paths=PackedStringArray("label", "contextContainer", "labels", "lineEdits")]
[node name="标识数据模板" type="PanelContainer" node_paths=PackedStringArray("label", "contextContainer", "labels", "buttons", "lineEdits", "optionButtons")]
custom_minimum_size = Vector2(512, 100)
size_flags_horizontal = 3
script = ExtResource("1_fp0bm")
label = NodePath("Layout/Label")
contextContainer = NodePath("Layout/MarginContainer/UXContainer-Container")
labels = []
buttons = []
lineEdits = []
optionButtons = []
[node name="Layout" type="VBoxContainer" parent="."]
layout_mode = 2

View File

@ -2,16 +2,18 @@
[ext_resource type="Script" path="res://BITKit/Scripts/UX/UXContainer.cs" id="1_dre1u"]
[node name="标识模板格式" type="VBoxContainer" node_paths=PackedStringArray("button", "labels", "lineEdits")]
[node name="标识模板格式" type="VBoxContainer" node_paths=PackedStringArray("labels", "button", "buttons", "lineEdits", "optionButtons")]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_dre1u")
button = NodePath("HBoxContainer/delete-button")
labels = []
button = NodePath("HBoxContainer/delete-button")
buttons = []
lineEdits = [NodePath("HBoxContainer/name-edit"), NodePath("HBoxContainer/hint-edit"), NodePath("HBoxContainer/category-edit")]
optionButtons = []
[node name="HBoxContainer" type="HBoxContainer" parent="."]
layout_mode = 2

View File

@ -7,6 +7,7 @@ namespace BITFactory;
public partial class CourseElement : Node
{
private static Node CurrentScene;
private static string CurrentScenePath=string.Empty;
[Export]
public PackedScene CourseScene;
@ -41,7 +42,7 @@ public partial class CourseElement : Node
Stopwatch stopwatch = new();
stopwatch.Start();
if (CurrentScene?.Name == CourseScene?.ResourceName)
if (CurrentScenePath == CourseScene?.ResourcePath)
{
BIT4Log.Log<CourseElement>($"已返回当前课程");
UXService.Open(CurrentScene as Control);
@ -54,6 +55,7 @@ public partial class CourseElement : Node
BIT4Log.Log<CourseElement>($"已释放当前课程:\t{CurrentScene.Name}");
}
CurrentScene = CourseScene!.Instantiate();
CurrentScenePath = CourseScene.ResourcePath;
GetTree().Root.AddChild(CurrentScene);
UXService.Open(CurrentScene as Control);
BIT4Log.Log<CourseElement>($"已加载新的课程:\t{CourseScene.ResourceName}");

View File

@ -141,9 +141,9 @@ public partial class SearchEngine:Node,ISearchEngine
instance.titleLabel.Text = entry.Display ?? entry.Id ?? entry.Key;
instance.Text = entry.Value;
instance.updateTimeLabel.Text = entry.UpdateDate.ToString(CultureInfo.InvariantCulture);
instance.createTimeLabel.Text = entry.CreateDate.ToString(CultureInfo.InvariantCulture);
instance.headerLabel.Text = entry.Key;
instance.labels[0].Text = entry.UpdateDate.ToString(CultureInfo.InvariantCulture);
instance.labels[1].Text = entry.CreateDate.ToString(CultureInfo.InvariantCulture);
instance.labels[2].Text = entry.Key;
}
}

View File

@ -30,7 +30,7 @@
CreateTime: 2023年7月5日16:15:46
}
{
Format: 生产厂家
Format: string
Value: Intelli工业
LastUpdateTime: 2023年7月6日16:15:42
CreateTime: 2023年7月5日16:15:46

View File

@ -0,0 +1,33 @@
using Godot;
using System;
namespace BITKit;
#if TOOLS
using Godot;
[Tool]
public partial class InspectorPlugins : EditorInspectorPlugin
{
public override bool _CanHandle(GodotObject @object)
{
return @object is Node;
}
public override bool _ParseProperty(
GodotObject @object,
Variant.Type type,
string name,
PropertyHint hintType,
string hintString,
PropertyUsageFlags usageFlags, bool wide)
{
// We handle properties of type integer.
if (type != Variant.Type.Int) return false;
// Create an instance of the custom property editor and register
// it to a specific property path.
AddPropertyEditor(name, new RandomIntEditor());
// Inform the editor to remove the default property editor for
// this property type.
return true;
}
}
#endif

View File

@ -0,0 +1,63 @@
using Godot;
using System;
namespace BITKit;
#if TOOLS
using Godot;
[Tool]
public partial class RandomIntEditor : EditorProperty
{
// The main control for editing the property.
private Button _propertyControl = new Button();
// An internal value of the property.
private int _currentValue = 0;
// A guard against internal changes when the property is updated.
private bool _updating = false;
public RandomIntEditor()
{
// Add the control as a direct child of EditorProperty node.
AddChild(_propertyControl);
// Make sure the control is able to retain the focus.
AddFocusable(_propertyControl);
// Setup the initial state and connect to the signal to track changes.
RefreshControlText();
//_propertyControl.Connect("pressed", this, nameof(OnButtonPressed));
}
private void OnButtonPressed()
{
// Ignore the signal if the property is currently being updated.
if (_updating)
{
return;
}
// Generate a new random integer between 0 and 99.
_currentValue = (int)GD.Randi() % 100;
RefreshControlText();
EmitChanged(GetEditedProperty(), _currentValue);
}
public override void _UpdateProperty()
{
// Read the current value from the property.
var newValue = (int)GetEditedObject().Get(GetEditedProperty());
if (newValue == _currentValue)
{
return;
}
// Update the control with the new value.
_updating = true;
_currentValue = newValue;
RefreshControlText();
_updating = false;
}
private void RefreshControlText()
{
_propertyControl.Text = $"Value: {_currentValue}";
}
}
#endif

View File

@ -1,18 +0,0 @@
#if TOOLS
using Godot;
namespace BITKit;
[Tool]
public partial class RefencePlugin : EditorPlugin
{
public override void _EnterTree()
{
// Initialization of the plugin goes here.
}
public override void _ExitTree()
{
// Clean-up of the plugin goes here.
}
}
#endif

View File

@ -0,0 +1,24 @@
[gd_scene load_steps=2 format=3 uid="uid://r7xpryghff3b"]
[ext_resource type="Script" path="res://addons/BITPlugins/ReferenceExamples.cs" id="1_h7isd"]
[node name="ReferenceContainer" type="PanelContainer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_h7isd")
[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 2
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
text = "引用插件"
[node name="Node" type="Node" parent="."]
script = ExtResource("1_h7isd")

View File

@ -0,0 +1,8 @@
using Godot;
using System;
namespace BITKit;
public partial class ReferenceExamples : Node
{
}

View File

@ -0,0 +1,23 @@
using Godot;
using System;
#if TOOLS
namespace BITKit;
[Tool]
public partial class ReferencePlugins : EditorPlugin
{
private InspectorPlugins _plugin;
private PackedScene _containerTemplate = GD.Load<PackedScene>("res://addons/BITPlugins/ReferenceContainer.tscn");
public override void _EnterTree()
{
_plugin = new InspectorPlugins();
AddInspectorPlugin(_plugin);
}
public override void _ExitTree()
{
RemoveInspectorPlugin(_plugin);
}
}
#endif

View File

@ -1,18 +0,0 @@
using Godot;
namespace BITKit;
#if TOOLS
[Tool]
public partial class RegistryPlugin : EditorPlugin
{
public override void _EnterTree()
{
// var type = typeof(StringResource);
// const string classPath = "res://Artists/Scripts/Resource/StringResource.cs";
// var script = GD.Load<Script>(classPath);
// GD.Print($"已加载{script.ResourceName??script.ToString()}");
// AddCustomType(type.Name, "Resource", script, null);
}
}
#endif

View File

@ -4,4 +4,4 @@ name="BITPlugins"
description="BITKit为Godot支持的插件 "
author="军火商小火柴"
version=""
script="RegistryPlugin.cs"
script="ReferencePlugins.cs"

View File

@ -23,6 +23,7 @@ EntitiesManager="*res://Artists/Services/entities_manager.tscn"
BITApp="*res://Artists/Services/BITApp.tscn"
UXMetaService="*res://Artists/Services/UXMetaService.tscn"
UXService="*res://Artists/Services/UXService.tscn"
ContextMenu="*res://Artists/Services/UXContextMenu.tscn"
[display]
@ -57,7 +58,6 @@ cycle_debug_menu={
[rendering]
driver/threads/thread_model=2
textures/vram_compression/import_etc2_astc=true
global_illumination/voxel_gi/quality=1
environment/ssao/half_size=false