创建与注册更新
现在可以注册模板并注册标识了
This commit is contained in:
@@ -1,52 +1,77 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using BITKit;
|
||||
|
||||
namespace BITFactory;
|
||||
|
||||
public partial class IDIS_RegisterService : Node
|
||||
{
|
||||
[ExportCategory("Services")]
|
||||
[Export] private IDIS_Service service;
|
||||
[Export] private IDIS_TemplateService templateService;
|
||||
|
||||
[ExportCategory("TemplateList")]
|
||||
[Export] private ItemList templateList;
|
||||
|
||||
[ExportCategory("Register Data")]
|
||||
[Export] private LineEdit handleEdit;
|
||||
[Export] private Button generateHandleButton;
|
||||
[Export] private Control container;
|
||||
[Export] private Control registerContainer;
|
||||
[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 Dictionary<int,KeyValuePair<string,string>> _currentValues = new();
|
||||
|
||||
private readonly Dictionary<int, KeyValuePair<string, string>> _currentValues = new();
|
||||
private readonly List<string> _currentReferences = new();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
templateList.ItemClicked += OnItemClicked;
|
||||
|
||||
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;
|
||||
templateList.Clear();
|
||||
foreach (var x in templateService.templates)
|
||||
{
|
||||
templateList.AddItem(x.TemplateName);
|
||||
}
|
||||
|
||||
templateList.ItemClicked += OnItemClicked;
|
||||
|
||||
registerButton.Pressed += Register;
|
||||
|
||||
generateHandleButton.Pressed += () =>
|
||||
{
|
||||
handleEdit.Text = $"88.123.99/{Mathf.Abs(Guid.NewGuid().GetHashCode())}";
|
||||
};
|
||||
|
||||
handleEdit.Editable = false;
|
||||
registerButton.Disabled = true;
|
||||
}
|
||||
|
||||
private void OnItemClicked(long index, Vector2 atPosition, long mouseButtonIndex)
|
||||
{
|
||||
MathNode.RemoveAllChild(container);
|
||||
var template = templateService.templates[(int) index];
|
||||
MathNode.RemoveAllChild(registerContainer);
|
||||
MathNode.RemoveAllChild(referenceContainer);
|
||||
|
||||
var template = templateService.templates[(int)index];
|
||||
|
||||
|
||||
var grid = new GridContainer();
|
||||
grid.Columns = 2;
|
||||
grid.AddThemeConstantOverride("h_separation", 64);
|
||||
|
||||
container.AddChild(grid);
|
||||
|
||||
registerContainer.AddChild(grid);
|
||||
|
||||
_currentValues.Clear();
|
||||
|
||||
var _dirIndex = 0;
|
||||
@@ -58,17 +83,14 @@ public partial class IDIS_RegisterService : Node
|
||||
var myIndex = _dirIndex++;
|
||||
|
||||
label.Text = x.format;
|
||||
|
||||
|
||||
lineEdit.PlaceholderText = x.hint;
|
||||
lineEdit.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
||||
|
||||
_currentValues.Add(myIndex,new KeyValuePair<string, string>(x.format,x.hint));
|
||||
|
||||
lineEdit.TextChanged += (s) =>
|
||||
{
|
||||
_currentValues[myIndex] = new KeyValuePair<string, string>(x.format, s);
|
||||
};
|
||||
|
||||
|
||||
_currentValues.Add(myIndex, new KeyValuePair<string, string>(x.format, x.hint));
|
||||
|
||||
lineEdit.TextChanged += (s) => { _currentValues[myIndex] = new KeyValuePair<string, string>(x.format, s); };
|
||||
|
||||
grid.AddChild(label);
|
||||
grid.AddChild(lineEdit);
|
||||
}
|
||||
@@ -77,15 +99,58 @@ public partial class IDIS_RegisterService : Node
|
||||
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()
|
||||
{
|
||||
var handle = handleEdit.Text;
|
||||
var json = JsonHelper.Get(_currentValues);
|
||||
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{json}");
|
||||
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.Value.Key, x.Value.Value);
|
||||
}
|
||||
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.Play();
|
||||
|
||||
handleEdit.Text = string.Empty;
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Net.Mime;
|
||||
using BITKit;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Godot;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
@@ -194,6 +195,16 @@ public class IDIS_DBContext:DbContext
|
||||
Datas.Add(data);
|
||||
SaveChanges();
|
||||
}
|
||||
|
||||
public void RegisterReference(string handle, string refenceHandle)
|
||||
{
|
||||
References.Add(new IDIS_Reference()
|
||||
{
|
||||
Handle = handle,
|
||||
RelatedHandle = refenceHandle,
|
||||
});
|
||||
SaveChanges();
|
||||
}
|
||||
}
|
||||
// ReSharper disable once IdentifierTypo
|
||||
/// <summary>
|
||||
@@ -206,9 +217,11 @@ public partial class IDIS_Service:Node
|
||||
{
|
||||
Context = new IDIS_DBContext();
|
||||
BIT4Log.Log<IDIS_Service>("已创建标识数据库");
|
||||
Context.Database.EnsureCreated();
|
||||
UniTask.Run(()=>Context.Database.EnsureCreatedAsync());
|
||||
}
|
||||
|
||||
public bool Register(string handle) => Context.Register(handle);
|
||||
public void Register(string handle, string format, string value) => Context.Register(handle, format, value);
|
||||
public void RegisterReference(string handle,string refenceHandle) => Context.RegisterReference(handle,refenceHandle);
|
||||
public static string GenerateHandle() => $"88.123.99/{Mathf.Abs(Guid.NewGuid().GetHashCode())}";
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using BITKit;
|
||||
@@ -14,6 +15,8 @@ public class IDIS_Template
|
||||
public string TemplateName="标识注册模板";
|
||||
public string TemplateDescription="该模板通常用于xxx用途";
|
||||
public string IconPath="Register";
|
||||
public DateTime CreateTime=DateTime.Now;
|
||||
public DateTime UpdateTime=DateTime.Now;
|
||||
public List<(string format,string hint)> Formats=new();
|
||||
}
|
||||
public partial class IDIS_TemplateService : Node
|
||||
@@ -29,6 +32,8 @@ public partial class IDIS_TemplateService : Node
|
||||
[Export] private LineEdit templateNameEdit;
|
||||
[Export] private LineEdit templateDescriptionEdit;
|
||||
[Export] private Control container;
|
||||
[Export] private Label templateCreateTimeLabel;
|
||||
[Export] private Label templateUpdateTimeLabel;
|
||||
[ExportCategory("Template")]
|
||||
[Export] private PackedScene templateContainer;
|
||||
|
||||
@@ -67,6 +72,7 @@ public partial class IDIS_TemplateService : Node
|
||||
if (_selectedTemplate is null) return;
|
||||
_selectedTemplate.Formats ??= new();
|
||||
_selectedTemplate.Formats.Add(("新的数据格式","格式类型"));
|
||||
_selectedTemplate.UpdateTime= DateTime.Now;
|
||||
EnsureConfigure();
|
||||
}
|
||||
|
||||
@@ -91,11 +97,13 @@ public partial class IDIS_TemplateService : Node
|
||||
{
|
||||
if (_selectedTemplate is null) return;
|
||||
_selectedTemplate.TemplateName = text;
|
||||
_selectedTemplate.UpdateTime= DateTime.Now;
|
||||
}
|
||||
private void OnTemplateDescriptionChanged(string text)
|
||||
{
|
||||
if (_selectedTemplate is null) return;
|
||||
_selectedTemplate.TemplateDescription = text;
|
||||
_selectedTemplate.UpdateTime= DateTime.Now;
|
||||
}
|
||||
private void EnsureConfigure()
|
||||
{
|
||||
@@ -108,9 +116,10 @@ public partial class IDIS_TemplateService : Node
|
||||
}
|
||||
|
||||
if (_selectedTemplate is null) return;
|
||||
{
|
||||
templateNameEdit.Text=_selectedTemplate.TemplateName;
|
||||
templateDescriptionEdit.Text=_selectedTemplate.TemplateDescription;
|
||||
templateCreateTimeLabel.Text = _selectedTemplate.CreateTime.ToString(CultureInfo.InvariantCulture);
|
||||
templateUpdateTimeLabel.Text = _selectedTemplate.UpdateTime.ToString(CultureInfo.InvariantCulture);
|
||||
|
||||
for (var i = 0; i < _selectedTemplate.Formats.Count; i++)
|
||||
{
|
||||
@@ -127,6 +136,7 @@ public partial class IDIS_TemplateService : Node
|
||||
var current = _selectedTemplate.Formats[index];
|
||||
current.format = s;
|
||||
_selectedTemplate.Formats[index] = current;
|
||||
_selectedTemplate.UpdateTime= DateTime.Now;
|
||||
};
|
||||
_container.lineEdits[1].TextChanged += s =>
|
||||
{
|
||||
@@ -142,7 +152,6 @@ public partial class IDIS_TemplateService : Node
|
||||
|
||||
container.AddChild(_container);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void OnItemSelected(long id)
|
||||
{
|
||||
|
Reference in New Issue
Block a user