添加了标识更新
但是只有界面没有功能
This commit is contained in:
59
BITKit/Scripts/Builder/NodeBuilder.cs
Normal file
59
BITKit/Scripts/Builder/NodeBuilder.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -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())
|
||||
{
|
||||
|
26
BITKit/Scripts/Text/RegularExpressionResource.cs
Normal file
26
BITKit/Scripts/Text/RegularExpressionResource.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
14
BITKit/Scripts/Text/TextValidationResource.cs
Normal file
14
BITKit/Scripts/Text/TextValidationResource.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
|
28
BITKit/Scripts/UX/UXLineEdit.cs
Normal file
28
BITKit/Scripts/UX/UXLineEdit.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user