添加了标识更新

但是只有界面没有功能
This commit is contained in:
CortexCore
2023-07-11 00:14:36 +08:00
parent d8d34766c0
commit ca824c3b32
21 changed files with 742 additions and 126 deletions

View File

@@ -0,0 +1,59 @@
using Godot;
using System;
// ReSharper disable MemberCanBePrivate.Global
namespace BITKit;
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)
{
Clear();
}
}
public Node Build()
{
var instance = template.Instantiate();
if (container is not null)
{
container.AddChild(instance);
}
else
{
AddChild(instance);
}
emptyHints?.Hide();
return instance;
}
public T Build<T>() where T : Node
{
var instance = Build() as T;
return instance;
}
public void Clear()
{
emptyHints?.Show();
if (clearTemplateOnly)
{
foreach (var x in container is not null ? container.GetChildren() : GetChildren())
{
if(x.SceneFilePath == template.ResourcePath)
x.QueueFree();
}
}
else
{
MathNode.ClearChild(container is not null ? container:this);
}
}
}

View File

@@ -28,7 +28,7 @@ public static partial class MathNode
return nodes.Distinct();
}
public static void RemoveAllChild(Node self)
public static void ClearChild(Node self)
{
foreach (var x in self.GetChildren())
{

View File

@@ -0,0 +1,26 @@
using Godot;
using System;
using System.Runtime.InteropServices.ComTypes;
using System.Text.RegularExpressions;
using BITKit;
namespace BITKit;
[GlobalClass]
public partial class RegularExpressionResource : TextValidationResource
{
[Export] private string regex;
[Export] private string errorReason;
public override bool IsTextValid(string text, out string _errorReason)
{
switch (Regex.IsMatch(text, regex))
{
case true:
_errorReason = string.Empty;
return true;
case false:
_errorReason = errorReason;
return false;
}
}
}

View File

@@ -0,0 +1,14 @@
using System;
using Godot;
namespace BITKit;
[GlobalClass]
public partial class TextValidationResource:Resource,ITextValidation
{
public virtual bool IsTextValid(string text,out string errorReason)
{
throw new NotImplementedException();
}
}

View File

@@ -0,0 +1,28 @@
using Godot;
using System;
using BITKit;
namespace BITFactory;
public partial class UXLineEdit : LineEdit
{
[Export] private TextValidationResource textValidation;
[Export] private RichTextLabel hints;
public override void _Ready()
{
TextChanged += OnTextChanged;
}
private void OnTextChanged(string newText)
{
if (textValidation is not null && textValidation.IsTextValid(newText,out var errorReason) is false)
{
hints.Text = $"[color=red]{errorReason}[/color]";
}
else
{
hints.Text = string.Empty;
}
}
}

View File

@@ -22,6 +22,10 @@ public partial class UXWindowService : Control
ShowWindow(window);
};
}
if(tabs.Count>0)
{
ShowWindow(windows[0]);
}
}
private void ShowWindow(CanvasItem window)
{
@@ -30,6 +34,12 @@ public partial class UXWindowService : Control
//if(window.Visible is true && window != x)
x.Hide();
}
var index = windows.IndexOf(window as Control);
if (index is not -1)
{
tabs[index].ButtonPressed = true;
}
window.Show();
}
}