Before update to NET 7
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using BITKit;
|
||||
using BITKit.IO;
|
||||
using RosSharp.RosBridgeClient.MessageTypes.Moveit;
|
||||
using Godot;
|
||||
|
||||
namespace BITFactory;
|
||||
[Serializable]
|
||||
@@ -24,11 +22,11 @@ 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 NodeBuilder templateIndexBuilder;
|
||||
[Export] private LineEdit templateNameEdit;
|
||||
[Export] private LineEdit templateDescriptionEdit;
|
||||
[Export] private Control container;
|
||||
@@ -39,13 +37,13 @@ public partial class IDIS_TemplateService : Node
|
||||
|
||||
private bool isDirty;
|
||||
|
||||
private IDIS_Template _selectedTemplate=>_selectedIndex==-1?null:templates[_selectedIndex];
|
||||
private int _selectedIndex=-1;
|
||||
private IDIS_Template _selectedTemplate;
|
||||
public override void _Ready()
|
||||
{
|
||||
if (File.Exists(assetPath) is false)
|
||||
{
|
||||
BIT4Log.Log<IDIS_TemplateService>($"未找到配置文件:{assetPath}");
|
||||
Save();
|
||||
}
|
||||
var temp = BITAssets.Read<List<IDIS_Template>>(assetPath, templateName);
|
||||
|
||||
@@ -55,9 +53,6 @@ public partial class IDIS_TemplateService : Node
|
||||
createButton.Pressed += CreateTemplate;
|
||||
newFormatButton.Pressed += CreateFormat;
|
||||
|
||||
itemList.ItemSelected += OnItemSelected;
|
||||
itemList.ItemClicked += OnItemClicked;
|
||||
|
||||
templateNameEdit.TextChanged += OnTemplateNameChanged;
|
||||
templateDescriptionEdit.TextChanged += OnTemplateDescriptionChanged;
|
||||
|
||||
@@ -78,11 +73,7 @@ public partial class IDIS_TemplateService : Node
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
BITAssets.Build(assetPath,new IAsset[]
|
||||
{
|
||||
new BITAsset(templateName,JsonHelper.Get(templates))
|
||||
});
|
||||
BIT4Log.Log<IDIS_TemplateService>($"已创建配置文件:{assetPath}");
|
||||
Save();
|
||||
}
|
||||
|
||||
private void CreateTemplate()
|
||||
@@ -93,6 +84,15 @@ public partial class IDIS_TemplateService : Node
|
||||
});
|
||||
EnsureConfigure();
|
||||
}
|
||||
|
||||
private void Save()
|
||||
{
|
||||
BITAssets.Build(assetPath,new IAsset[]
|
||||
{
|
||||
new BITAsset(templateName,JsonHelper.Get(templates))
|
||||
});
|
||||
BIT4Log.Log<IDIS_TemplateService>($"已创建配置文件:{assetPath}");
|
||||
}
|
||||
private void OnTemplateNameChanged(string text)
|
||||
{
|
||||
if (_selectedTemplate is null) return;
|
||||
@@ -105,70 +105,68 @@ public partial class IDIS_TemplateService : Node
|
||||
_selectedTemplate.TemplateDescription = text;
|
||||
_selectedTemplate.UpdateTime= DateTime.Now;
|
||||
}
|
||||
|
||||
private void EnsureConfigure()
|
||||
{
|
||||
itemList.Clear();
|
||||
MathNode.ClearChild(container);
|
||||
|
||||
templateIndexBuilder.Clear();
|
||||
|
||||
foreach (var x in templates)
|
||||
{
|
||||
itemList.AddItem(x.TemplateName);
|
||||
var _container = templateIndexBuilder.Build<UXContainer>();
|
||||
_container.button.Text = x.TemplateName;
|
||||
_container.button.Pressed += () =>
|
||||
{
|
||||
_selectedTemplate = x;
|
||||
EnsureConfigure();
|
||||
};
|
||||
}
|
||||
|
||||
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++)
|
||||
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++)
|
||||
{
|
||||
var x = _selectedTemplate.Formats[i];
|
||||
var _container = templateContainer.Instantiate<UXContainer>();
|
||||
|
||||
_container.lineEdits[0].Text = x.format;
|
||||
_container.lineEdits[1].Text = x.hint;
|
||||
_container.lineEdits[2].Text = x.category;
|
||||
|
||||
var index = i;
|
||||
|
||||
_container.lineEdits[0].TextChanged += (s) =>
|
||||
{
|
||||
var x = _selectedTemplate.Formats[i];
|
||||
var _container = templateContainer.Instantiate<UXContainer>();
|
||||
|
||||
_container.lineEdits[0].Text = x.format;
|
||||
_container.lineEdits[1].Text = x.hint;
|
||||
_container.lineEdits[2].Text = x.category;
|
||||
|
||||
var index = i;
|
||||
|
||||
_container.lineEdits[0].TextChanged += (s) =>
|
||||
{
|
||||
var current = _selectedTemplate.Formats[index];
|
||||
current.format = s;
|
||||
_selectedTemplate.Formats[index] = current;
|
||||
_selectedTemplate.UpdateTime= DateTime.Now;
|
||||
};
|
||||
_container.lineEdits[1].TextChanged += s =>
|
||||
{
|
||||
var current = _selectedTemplate.Formats[index];
|
||||
current.hint = s;
|
||||
_selectedTemplate.Formats[index] = current;
|
||||
};
|
||||
_container.lineEdits[2].TextChanged += s =>
|
||||
{
|
||||
var current = _selectedTemplate.Formats[index];
|
||||
current.category = 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();
|
||||
var current = _selectedTemplate.Formats[index];
|
||||
current.format = s;
|
||||
_selectedTemplate.Formats[index] = current;
|
||||
_selectedTemplate.UpdateTime = DateTime.Now;
|
||||
};
|
||||
_container.lineEdits[1].TextChanged += s =>
|
||||
{
|
||||
var current = _selectedTemplate.Formats[index];
|
||||
current.hint = s;
|
||||
_selectedTemplate.Formats[index] = current;
|
||||
};
|
||||
_container.lineEdits[2].TextChanged += s =>
|
||||
{
|
||||
var current = _selectedTemplate.Formats[index];
|
||||
current.category = s;
|
||||
_selectedTemplate.Formats[index] = current;
|
||||
};
|
||||
_container.button.Pressed += () =>
|
||||
{
|
||||
_selectedTemplate.Formats.RemoveAt(index);
|
||||
EnsureConfigure();
|
||||
};
|
||||
|
||||
container.AddChild(_container);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user