添加了部分界面

This commit is contained in:
CortexCore
2023-07-08 00:02:32 +08:00
parent f4e85d4f9b
commit a2da9039f8
23 changed files with 768 additions and 48 deletions

View File

@@ -0,0 +1,67 @@
using Godot;
using System;
using BITKit;
namespace BITFactory;
public partial class IDIS_RegisterService : Node
{
[Export] private IDIS_Service service;
[Export] private IDIS_TemplateService templateService;
[Export] private ItemList templateList;
[Export] private LineEdit handleEdit;
[Export] private Button generateHandleButton;
[Export] private Control container;
[Export] private Button registerButton;
[Export] private Label hints;
public override void _Ready()
{
templateList.Clear();
foreach (var x in templateService.templates)
{
templateList.AddItem(x.TemplateName);
}
var lineEdit = new LineEdit();
lineEdit.PlaceholderText = "请输入标识名称";
templateList.ItemClicked += OnItemClicked;
registerButton.Pressed += Register;
generateHandleButton.Pressed += () =>
{
handleEdit.Text = $"88.123.99/{Mathf.Abs(Guid.NewGuid().GetHashCode())}";
};
}
private void OnItemClicked(long index, Vector2 atPosition, long mouseButtonIndex)
{
MathNode.RemoveAllChild(container);
var template = templateService.templates[(int) index];
var grid = new GridContainer();
grid.Columns = 2;
grid.AddThemeConstantOverride("h_separation", 64);
container.AddChild(grid);
foreach (var x in template.Formats)
{
var label = new Label();
var lineEdit = new LineEdit();
label.Text = x.format;
lineEdit.PlaceholderText = x.hint;
lineEdit.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
grid.AddChild(label);
grid.AddChild(lineEdit);
}
}
private void Register()
{
}
}

View File

@@ -163,6 +163,37 @@ public class IDIS_DBContext:DbContext
return queries.Any();
}
public bool Register(string handle)
{
var handleExists = Values.Any(x => x.Handle == handle);
if (handleExists)
{
return false;
}
var value = new IDIS_Value()
{
Handle = handle
};
Values.Add(value);
SaveChanges();
return true;
}
public void Register(string handle,string format, string value)
{
var handleExists = Values.Any(x => x.Handle == handle);
if (!handleExists)
{
Register(handle);
}
var data = new IDIS_Data()
{
Handle = handle,
Format = format,
Value = value
};
Datas.Add(data);
SaveChanges();
}
}
// ReSharper disable once IdentifierTypo
/// <summary>
@@ -177,4 +208,7 @@ public partial class IDIS_Service:Node
BIT4Log.Log<IDIS_Service>("已创建标识数据库");
Context.Database.EnsureCreated();
}
public bool Register(string handle) => Context.Register(handle);
public void Register(string handle, string format, string value) => Context.Register(handle, format, value);
}

View File

@@ -0,0 +1,158 @@
using Godot;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using BITKit;
using BITKit.IO;
using RosSharp.RosBridgeClient.MessageTypes.Moveit;
namespace BITFactory;
[Serializable]
public class IDIS_Template
{
public string TemplateName="标识注册模板";
public string TemplateDescription="该模板通常用于xxx用途";
public string IconPath="Register";
public List<(string format,string hint)> Formats=new();
}
public partial class IDIS_TemplateService : Node
{
private static string assetPath => PathHelper.GetPath("标识注册模板.zip");
private const string templateName = $"{nameof(IDIS_Template)}.json";
public readonly List<IDIS_Template> templates=new();
private readonly Queue<IDIS_Template> selectedQueue = new();
[ExportCategory("Quick Start")]
[Export] private Button createButton;
[Export] private Button newFormatButton;
[Export] private ItemList itemList;
[Export] private LineEdit templateNameEdit;
[Export] private LineEdit templateDescriptionEdit;
[Export] private Control container;
[ExportCategory("Template")]
[Export] private PackedScene templateContainer;
private bool isDirty;
private IDIS_Template _selectedTemplate=>_selectedIndex==-1?null:templates[_selectedIndex];
private int _selectedIndex=-1;
public override void _Ready()
{
if (File.Exists(assetPath) is false)
{
BIT4Log.Log<IDIS_TemplateService>($"未找到配置文件:{assetPath}");
}
var temp = BITAssets.Read<List<IDIS_Template>>(assetPath, templateName);
templates.AddRange(temp);
BIT4Log.Log<IDIS_TemplateService>($"已加载配置文件:{assetPath}");
createButton.Pressed += CreateTemplate;
newFormatButton.Pressed += CreateFormat;
itemList.ItemSelected += OnItemSelected;
itemList.ItemClicked += OnItemClicked;
templateNameEdit.TextChanged += OnTemplateNameChanged;
templateDescriptionEdit.TextChanged += OnTemplateDescriptionChanged;
MathNode.RemoveAllChild(container);
EnsureConfigure();
}
private void CreateFormat()
{
if (_selectedTemplate is null) return;
_selectedTemplate.Formats ??= new();
_selectedTemplate.Formats.Add(("新的数据格式","格式类型"));
EnsureConfigure();
}
public override void _ExitTree()
{
BITAssets.Build(assetPath,new IAsset[]
{
new BITAsset(templateName,JsonHelper.Get(templates))
});
BIT4Log.Log<IDIS_TemplateService>($"已创建配置文件:{assetPath}");
}
private void CreateTemplate()
{
templates.Add(new IDIS_Template()
{
TemplateName = "新的标识注册模板"
});
EnsureConfigure();
}
private void OnTemplateNameChanged(string text)
{
if (_selectedTemplate is null) return;
_selectedTemplate.TemplateName = text;
}
private void OnTemplateDescriptionChanged(string text)
{
if (_selectedTemplate is null) return;
_selectedTemplate.TemplateDescription = text;
}
private void EnsureConfigure()
{
itemList.Clear();
MathNode.RemoveAllChild(container);
foreach (var x in templates)
{
itemList.AddItem(x.TemplateName);
}
if (_selectedTemplate is null) return;
{
templateNameEdit.Text=_selectedTemplate.TemplateName;
templateDescriptionEdit.Text=_selectedTemplate.TemplateDescription;
for (var i = 0; i < _selectedTemplate.Formats.Count; i++)
{
var x = _selectedTemplate.Formats[i];
var _container = templateContainer.Instantiate<UXContainer>();
_container.lineEdits[0].Text = x.format;
_container.lineEdits[1].Text = x.hint;
var index = i;
_container.lineEdits[0].TextChanged += (s) =>
{
var current = _selectedTemplate.Formats[index];
current.format = s;
_selectedTemplate.Formats[index] = current;
};
_container.lineEdits[1].TextChanged += s =>
{
var current = _selectedTemplate.Formats[index];
current.hint = s;
_selectedTemplate.Formats[index] = current;
};
_container.button.Pressed += () =>
{
_selectedTemplate.Formats.RemoveAt(index);
EnsureConfigure();
};
container.AddChild(_container);
}
}
}
private void OnItemSelected(long id)
{
}
private void OnItemClicked(long index, Vector2 atPosition, long mouseButtonIndex)
{
// var currentItem = _templates[(int)index];
// templateNameEdit.Text = currentItem.TemplateName;
_selectedIndex = (int)index;
EnsureConfigure();
}
}