From d65fea19625c8c41faf49520b641f16b6919f83a Mon Sep 17 00:00:00 2001 From: jkpete <1031139173@qq.com> Date: Thu, 14 Aug 2025 17:33:58 +0800 Subject: [PATCH] fixed EditList --- Example/SaveSystem/Script/ViewSaveSystem.cs | 14 +- .../Templete/Godot/UI/EGodotEditList.cs | 123 ++++++++++++++++++ 2 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditList.cs diff --git a/Example/SaveSystem/Script/ViewSaveSystem.cs b/Example/SaveSystem/Script/ViewSaveSystem.cs index c82dc74..2e18844 100644 --- a/Example/SaveSystem/Script/ViewSaveSystem.cs +++ b/Example/SaveSystem/Script/ViewSaveSystem.cs @@ -22,7 +22,7 @@ namespace EGFramework.Examples.Test // GD.Print(Tr("Data")+"+___+"); // TestTable(); // TestJson(); - this.CallDeferred("TestDialog"); + // this.CallDeferred("TestDialog"); // SchoolType school = SchoolType.London; // school.EGenerateMappingByEnum(); // foreach (KeyValuePair selectOptions in school.EGenerateMappingByEnum()) @@ -32,6 +32,7 @@ namespace EGFramework.Examples.Test // TestDialog(); // TestMySQL(); // EG.Print(OS.GetLocaleLanguage()); + TestEdit(); } public override void _ExitTree() @@ -78,6 +79,17 @@ namespace EGFramework.Examples.Test }, "Edit"); } + public void TestEdit() + { + DataStudent dataStudent = new DataStudent("ZG",10); + container = this.GetNode("TabContainer"); + EGodotEditList editList = container.CreateNode(); + editList.InitList(dataStudent.EGenerateDictiontaryByObject(), e => + { + GD.Print("Name:" + e["Name"] + "Age:" + e["Age"] + "School:" + e["School"] + "Path:" + e["Path"]); + }, "Edit"); + } + public void TestJson() { string json = @"{ diff --git a/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditList.cs b/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditList.cs new file mode 100644 index 0000000..01b8c0a --- /dev/null +++ b/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditList.cs @@ -0,0 +1,123 @@ +using Godot; +using System; +using System.Collections.Generic; + +namespace EGFramework.UI +{ + public partial class EGodotEditList : VBoxContainer + { + public Label Title { set; get; } + public HBoxContainer OperateGroup { set; get; } + public VBoxContainer EditList { get; set; } + public Button ConfirmButton { set; get; } + public Button CancelButton { set; get; } + public List EditListItem { get; set; } + public Label ErrorTips { get; set; } + + public EasyEvent> OnEdit { set; get; } = new EasyEvent>(); + private Dictionary EditCache { set; get; } = new Dictionary(); + private IUnRegister OnDataEdit { set; get; } + + public List ParamUIs { set; get; } = new List(); + private bool IsInit { set; get; } = false; + + const int DefaultWidth = 640; + const int DefaultHeight = 320; + + public void InitList(Dictionary data, Action> onDataEdit, string title = "Edit Data") + { + if (!IsInit) + { + Title = new Label(); + Title.Name = "Title"; + Title.HorizontalAlignment = HorizontalAlignment.Center; + this.AddChild(Title); + this.Name = "EditList"; + this.ErrorTips = new Label(); + ErrorTips.Name = "ErrorTips"; + this.AddChild(ErrorTips); + ErrorTips.Visible = false; + + EditList = new VBoxContainer(); + EditList.Name = "EditContainer"; + EditList.SizeFlagsVertical = Control.SizeFlags.ExpandFill; + this.AddChild(EditList); + + this.OperateGroup = new HBoxContainer(); + this.OperateGroup.Name = "OperateGroup"; + this.AddChild(OperateGroup); + + this.ConfirmButton = new Button(); + this.ConfirmButton.Name = "ConfirmButton"; + this.ConfirmButton.Text = "OK"; + this.ConfirmButton.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill; + this.ConfirmButton.Connect("pressed", Callable.From(OnConfirm)); + this.CancelButton = new Button(); + this.CancelButton.Name = "CancelButton"; + this.CancelButton.Text = "Cancel"; + this.CancelButton.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill; + this.OperateGroup.AddChild(ConfirmButton); + this.OperateGroup.AddChild(CancelButton); + + IsInit = true; + } + + + + + EditList.ClearChildren(); + ParamUIs.Clear(); + this.Title.Text = title; + OnDataEdit = OnEdit.Register(onDataEdit); + foreach (KeyValuePair param in data) + { + EGodotEditParam paramUI = new EGodotEditParam(); + EditList.AddChild(paramUI); + paramUI.Init(param); + ParamUIs.Add(paramUI); + } + + + } + + public void OnConfirm() + { + EditCache.Clear(); + foreach (EGodotEditParam paramUI in ParamUIs) + { + EditCache.Add(paramUI.GetKey(), paramUI.GetValue()); + } + try + { + OnEdit.Invoke(EditCache); + OnDataEdit.UnRegister(); + this.Visible = false; + } + catch (NullReferenceException) + { + this.OnErrorTips("某项数据不能为空!"); + } + catch (FormatException) + { + this.OnErrorTips("某项数据格式不准确!"); + } + catch (Exception e) + { + this.OnErrorTips(e.ToString()); + throw; + } + } + + public void OnErrorTips(string tips) + { + ErrorTips.Visible = true; + ErrorTips.Text = tips; + } + + public void OnCancel() + { + OnDataEdit.UnRegister(); + this.Visible = false; + } + } +}