From 954ceefcafca208130ff3d52b682b7eb7a693baa Mon Sep 17 00:00:00 2001 From: jkpete <1031139173@qq.com> Date: Wed, 6 Aug 2025 16:25:21 +0800 Subject: [PATCH] add Enum type to egeditParam Option button --- Example/SaveSystem/Script/ViewSaveSystem.cs | 41 +++++++++++++------ .../Godot/Dialog/EGodotBasicDialog.cs | 3 +- .../Templete/Godot/UI/EGodotEditParam.cs | 14 ++++++- .../Templete/Godot/UI/EGodotTable.cs | 14 ++----- .../Templete/Variant/EGVariantGenerator.cs | 13 ++++++ addons/EGFramework/Translate/EGFramework.csv | 2 + 6 files changed, 61 insertions(+), 26 deletions(-) diff --git a/Example/SaveSystem/Script/ViewSaveSystem.cs b/Example/SaveSystem/Script/ViewSaveSystem.cs index 6eed4ff..c82dc74 100644 --- a/Example/SaveSystem/Script/ViewSaveSystem.cs +++ b/Example/SaveSystem/Script/ViewSaveSystem.cs @@ -8,18 +8,27 @@ using LiteDB; using Newtonsoft.Json; using Renci.SshNet; -namespace EGFramework.Examples.Test { +namespace EGFramework.Examples.Test +{ public partial class ViewSaveSystem : Node, IEGFramework { public string[][] DataList { get; set; } public string[][] DataList2 { get; set; } - Container container{ set; get; } + Container container { set; get; } public override void _Ready() { // TestTree(); // TranslationServer.SetLocale("jp"); - TestTable(); + // GD.Print(Tr("Data")+"+___+"); + // TestTable(); // TestJson(); + this.CallDeferred("TestDialog"); + // SchoolType school = SchoolType.London; + // school.EGenerateMappingByEnum(); + // foreach (KeyValuePair selectOptions in school.EGenerateMappingByEnum()) + // { + // GD.Print(selectOptions.Key+"---"+selectOptions.Value); + // } // TestDialog(); // TestMySQL(); // EG.Print(OS.GetLocaleLanguage()); @@ -62,15 +71,11 @@ namespace EGFramework.Examples.Test { public void TestDialog() { - DataStudent dataStudent = new DataStudent(); - dataStudent.EGenerateDictiontaryByObject(); - this.ExecuteAfterSecond(() => + DataStudent dataStudent = new DataStudent("ZG",10); + this.EGEditDialog(dataStudent.EGenerateDictiontaryByObject(), e => { - this.EGEditDialog(new DataStudent().EGenerateDictiontaryByObject(), e => - { - GD.Print("Name:" + e["Name"] + "Age:" + e["Age"]); - }, "Edit"); - }, 0.2f); + GD.Print("Name:" + e["Name"] + "Age:" + e["Age"]+"School:" + e["School"] + "Path:" + e["Path"]); + }, "Edit"); } public void TestJson() @@ -149,11 +154,13 @@ namespace EGFramework.Examples.Test { public string Name { get; set; } public int Age; public EGPathSelect Path { set; get; } + public SchoolType School { set; get; } public DataStudent(string name, int age) { Name = name; Age = age; ID = 0; + School = SchoolType.MIT; Path = new EGPathSelect(); } } @@ -164,7 +171,7 @@ namespace EGFramework.Examples.Test { public string Name { get; set; } public int Age { set; get; } public string Path { set; get; } - public DataStu(string name, int age,string path) + public DataStu(string name, int age, string path) { Name = name; Age = age; @@ -172,7 +179,7 @@ namespace EGFramework.Examples.Test { Path = path; } } - + public struct DataPerson { public string id { get; set; } @@ -180,4 +187,12 @@ namespace EGFramework.Examples.Test { public string workPlace { set; get; } public string policeNum { set; get; } } + + public enum SchoolType + { + Tsinghua = 0, + MIT = 1, + London = 2, + Data = 3 + } } \ No newline at end of file diff --git a/addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotBasicDialog.cs b/addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotBasicDialog.cs index 2fe1b16..4673b76 100644 --- a/addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotBasicDialog.cs +++ b/addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotBasicDialog.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using Godot; namespace EGFramework.UI { @@ -23,7 +24,7 @@ namespace EGFramework.UI { EGodotFileDialog fileDialog = self.PopupNode("FileDialog"); fileDialog.Title = title; - fileDialog.RootSubfolder = filePath; + fileDialog.RootSubfolder = Path.GetDirectoryName(filePath); fileDialog.InitFileSelect(selectPath); } diff --git a/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditParam.cs b/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditParam.cs index 0bc81e6..0f8971a 100644 --- a/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditParam.cs +++ b/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditParam.cs @@ -67,6 +67,18 @@ namespace EGFramework.UI } this.ParamOption.Selected = this.ParamOption.GetItemIndex(((EGSelectParam)editValue.Value).SelectID); } + else if (editValue.Value is Enum) + { + this.ParamOption = new OptionButton(); + ParamOption.Name = "ParamOption"; + ParamOption.SizeFlagsHorizontal = SizeFlags.ExpandFill; + this.AddChild(ParamOption); + foreach (KeyValuePair selectOptions in editValue.Value.GetType().EGenerateMappingByEnum()) + { + this.ParamOption.AddItem(selectOptions.Value, selectOptions.Key); + } + this.ParamOption.Selected = this.ParamOption.GetItemIndex((int)editValue.Value); + } else if (editValue.Value is int) { this.ParamSpinBox = new SpinBox(); @@ -128,7 +140,7 @@ namespace EGFramework.UI ParamOperate.SizeFlagsHorizontal = SizeFlags.ExpandFill; ParamOperate.Pressed += () => { - this.EGFileOpen("res://", str => + this.EGFileOpen("", str => { ParamPathSelect.Text = str; }); diff --git a/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotTable.cs b/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotTable.cs index 44635b4..19c8d91 100644 --- a/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotTable.cs +++ b/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotTable.cs @@ -33,7 +33,7 @@ namespace EGFramework.UI protected EasyEvent> AddData { set; get; } = new EasyEvent>(); - public Vector2 MinimumFunctionButtonSize = new Vector2(120, 0); + public Vector2 MinimumFunctionButtonSize = new Vector2(60, 0); public string TableName { set; get; } = "-"; @@ -341,9 +341,9 @@ namespace EGFramework.UI public void Search() { - if (SearchEdit.Text == "" && FieldSelect.Text == "") + if (SearchEdit.Text == "" || FieldSelect.Text == "") { - this.EGAlert("Please input key word in search edit and select a field.", "Message not enough!"); + this.EGAlert("MissingMessage", "MessageNotEnough"); } else { @@ -454,12 +454,4 @@ namespace EGFramework.UI } - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] - public class EGTitleAttribute : Attribute - { - public string _name { set; get; } - public EGTitleAttribute(string name){ - this._name = name; - } - } } \ No newline at end of file diff --git a/addons/EGFramework/Module/GenerateTools/Templete/Variant/EGVariantGenerator.cs b/addons/EGFramework/Module/GenerateTools/Templete/Variant/EGVariantGenerator.cs index d84a61c..43e06d6 100644 --- a/addons/EGFramework/Module/GenerateTools/Templete/Variant/EGVariantGenerator.cs +++ b/addons/EGFramework/Module/GenerateTools/Templete/Variant/EGVariantGenerator.cs @@ -123,5 +123,18 @@ namespace EGFramework{ } return result; } + + public static Dictionary EGenerateMappingByEnum(this Type self) + { + Dictionary result = new Dictionary(); + foreach (var value in Enum.GetValues(self)) + { + if (!result.ContainsKey((int)value)) + { + result.Add((int)value, value.ToString()); + } + } + return result; + } } } \ No newline at end of file diff --git a/addons/EGFramework/Translate/EGFramework.csv b/addons/EGFramework/Translate/EGFramework.csv index 1214cce..8e444ea 100644 --- a/addons/EGFramework/Translate/EGFramework.csv +++ b/addons/EGFramework/Translate/EGFramework.csv @@ -5,6 +5,8 @@ Output,Output,导出,エクスポート Input,Input,导入,インポート Search,Search,查找,検索する PlaceholderSearch,Please input keyword,请输入关键词,キーワードを入力してください +MissingMessage,Please input key word in search edit and select a field,请在搜索编辑中输入关键字并选择一个字段,検索編集にキーワードを入力し、フィールドを選んでください +MessageNotEnough,Message not enough,消息不足,メッセージが足りません Reset,Reset,重置,リセット To,To,到,へ Page,Page,页,ページ