2023-07-08 00:02:32 +08:00
|
|
|
using Godot;
|
|
|
|
using System;
|
2023-07-08 13:54:17 +08:00
|
|
|
using System.Collections.Generic;
|
2023-07-08 00:02:32 +08:00
|
|
|
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;
|
2023-07-08 13:54:17 +08:00
|
|
|
private readonly Dictionary<int,KeyValuePair<string,string>> _currentValues = new();
|
2023-07-08 00:02:32 +08:00
|
|
|
public override void _Ready()
|
|
|
|
{
|
|
|
|
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())}";
|
|
|
|
};
|
2023-07-08 14:03:19 +08:00
|
|
|
|
|
|
|
handleEdit.Editable = false;
|
|
|
|
registerButton.Disabled = true;
|
2023-07-08 00:02:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2023-07-08 13:54:17 +08:00
|
|
|
_currentValues.Clear();
|
|
|
|
|
|
|
|
var _dirIndex = 0;
|
2023-07-08 00:02:32 +08:00
|
|
|
foreach (var x in template.Formats)
|
|
|
|
{
|
|
|
|
var label = new Label();
|
|
|
|
var lineEdit = new LineEdit();
|
|
|
|
|
2023-07-08 13:54:17 +08:00
|
|
|
var myIndex = _dirIndex++;
|
|
|
|
|
2023-07-08 00:02:32 +08:00
|
|
|
label.Text = x.format;
|
|
|
|
|
|
|
|
lineEdit.PlaceholderText = x.hint;
|
|
|
|
lineEdit.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
|
|
|
|
|
2023-07-08 13:54:17 +08:00
|
|
|
_currentValues.Add(myIndex,new KeyValuePair<string, string>(x.format,x.hint));
|
|
|
|
|
|
|
|
lineEdit.TextChanged += (s) =>
|
|
|
|
{
|
|
|
|
_currentValues[myIndex] = new KeyValuePair<string, string>(x.format, s);
|
|
|
|
};
|
|
|
|
|
2023-07-08 00:02:32 +08:00
|
|
|
grid.AddChild(label);
|
|
|
|
grid.AddChild(lineEdit);
|
|
|
|
}
|
2023-07-08 14:03:19 +08:00
|
|
|
|
|
|
|
handleEdit.Editable = true;
|
|
|
|
registerButton.Disabled = false;
|
2023-07-08 00:02:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void Register()
|
|
|
|
{
|
2023-07-08 13:54:17 +08:00
|
|
|
var handle = handleEdit.Text;
|
|
|
|
var json = JsonHelper.Get(_currentValues);
|
|
|
|
BIT4Log.Log<IDIS_RegisterService>($"注册标识:{handle}");
|
|
|
|
BIT4Log.Log<IDIS_RegisterService>($"\n{json}");
|
|
|
|
foreach (var x in _currentValues)
|
|
|
|
{
|
|
|
|
service.Register(handle, x.Value.Key, x.Value.Value);
|
|
|
|
}
|
2023-07-08 00:02:32 +08:00
|
|
|
}
|
|
|
|
}
|