调整了模板

This commit is contained in:
CortexCore
2023-07-17 04:10:14 +08:00
parent 498b0617f8
commit e27cce2ac3
56 changed files with 2165 additions and 581 deletions

View File

@@ -4,34 +4,29 @@ using Godot.Collections;
namespace BITKit;
public interface IUXContainer
{
string Text { get; set; }
void SetText(string text);
Texture2D Icon { get; set; }
void SetIcon(Texture2D texture);
}
public partial class UXContainer:Control,IUXContainer
public partial class UXContainer:Control
{
[Export] public Label label;
[Export] public RichTextLabel richTextLabel;
[Export] public Label titleLabel;
[Export] public TextureRect icon;
[Export] public Button button;
[Export] public Node contextContainer;
[ExportCategory("Label")]
[Export] public Label updateTimeLabel;
[Export] public Label createTimeLabel;
[Export] public Label headerLabel;
[ExportCategory(nameof(Label))]
[Export] public Array<Label> labels;
[ExportCategory("Button")]
[Export] public Button mainButton;
[Export] public Button secButton;
[Export] public Button thirdButton;
[ExportCategory("Text Edit")]
[ExportCategory(nameof(Button))]
[Export] public Button button;
[Export] public Array<Button> buttons;
[ExportCategory(nameof(TextEdit))]
[Export] public LineEdit lineEdit;
[Export] public Array<LineEdit> lineEdits;
[ExportCategory(nameof(OptionButton))]
[Export] public OptionButton optionButton;
[Export] public Array<OptionButton> optionButtons;
public string Text
{
get =>label is not null ? label.Text : richTextLabel.Text;
@@ -52,28 +47,4 @@ public partial class UXContainer:Control,IUXContainer
{
Text=text;
}
public void AddContainer(Node node)
{
contextContainer.AddChild(node);
}
public void ClearContainer()
{
foreach (var x in contextContainer.GetChildren())
{
x.QueueFree();
}
}
public Texture2D Icon
{
get => icon.Texture;
set => icon.Texture=value;
}
public void SetIcon(Texture2D texture)
{
Icon = texture;
}
}

View File

@@ -0,0 +1,46 @@
using System;
using Godot;
namespace BITKit;
public class UXContextMenuBuilder
{
public void Build()
{
UXContextMenu.Singleton.Position = UXContextMenu.MousePosition;
UXContextMenu.Singleton.Show();
}
}
public static class UXContextMenuExtensions
{
public static UXContextMenuBuilder AddAction(this UXContextMenuBuilder self,string name,Action action)
{
UXContextMenu.Singleton.AddItem(name);
return self;
}
}
[GlobalClass]
public partial class UXContextMenu:PopupMenu
{
public static UXContextMenu Singleton { get; private set; }
public static Vector2I MousePosition { get; private set; }
public override void _Ready()
{
Singleton = this;
}
public static UXContextMenuBuilder Create()
{
Singleton.Clear();
return new UXContextMenuBuilder();
}
public override void _Input(InputEvent @event)
{
if (@event is InputEventMouseMotion motion)
{
MousePosition = (Vector2I)motion.Position;
}
}
}

View File

@@ -16,6 +16,7 @@ public partial class UXLineEdit : LineEdit
private void OnTextChanged(string newText)
{
if (hints is null) return;
if (textValidation is not null && textValidation.IsTextValid(newText,out var errorReason) is false)
{
hints.Text = $"[color=red]{errorReason}[/color]";