From 4f393ca54b19a2e585b62e27d7ec94bbdf563d52 Mon Sep 17 00:00:00 2001 From: jkpete <1031139173@qq.com> Date: Thu, 26 Jun 2025 12:02:07 +0800 Subject: [PATCH] add path select pararms --- .../Godot/Dialog/EGodotBasicDialog.cs | 44 ++++++------ .../Templete/Godot/Dialog/EGodotFileDialog.cs | 70 +++++++++++++++++++ .../Templete/Godot/UI/EGodotEditParam.cs | 15 ++++ .../Templete/Variant/EGDataStruct.cs | 10 ++- 4 files changed, 117 insertions(+), 22 deletions(-) create mode 100644 addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotFileDialog.cs diff --git a/addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotBasicDialog.cs b/addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotBasicDialog.cs index 7dce73c..14bc30f 100644 --- a/addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotBasicDialog.cs +++ b/addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotBasicDialog.cs @@ -21,26 +21,28 @@ namespace EGFramework.UI confirmDialog.Init(callback); } - // public static void EGFileSingleSelect(this Node self, string filePath, Action selectPath, string title = "FileSelect") - // { - // FileDialog fileDialog = self.SingletoneNode("FileDialog"); - // fileDialog.Title = title; - // fileDialog.Size = new Vector2I(480, 320); - // fileDialog.FileMode = FileDialog.FileModeEnum.OpenFile; - // fileDialog.RootSubfolder = filePath; - // fileDialog.PopupCentered(); - // fileDialog.Connect("file_selected", Callable.From(selectPath)); - // } - - // public static void EGDocumentSelect(this Node self, string filePath, Action selectPath, string title = "FileSelect") - // { - // FileDialog fileDialog = self.SingletoneNode("FileDialog"); - // fileDialog.Title = title; - // fileDialog.Size = new Vector2I(480, 320); - // fileDialog.FileMode = FileDialog.FileModeEnum.OpenDir; - // fileDialog.RootSubfolder = filePath; - // fileDialog.PopupCentered(); - // fileDialog.Connect("file_selected", Callable.From(selectPath)); - // } + public static void EGFileOpen(this Node self, string filePath, Action selectPath, string title = "Open a file") + { + EGodotFileDialog fileDialog = self.SingletoneNode("FileDialog"); + fileDialog.Title = title; + fileDialog.RootSubfolder = filePath; + fileDialog.InitFileSelect(selectPath); + } + + public static void EGFileSave(this Node self, string filePath, Action selectPath, string title = "Save a file") + { + EGodotFileDialog fileDialog = self.SingletoneNode("FileDialog"); + fileDialog.Title = title; + fileDialog.RootSubfolder = filePath; + fileDialog.InitSaveFileSelect(selectPath); + } + + public static void EGDocumentOpen(this Node self, string filePath, Action selectPath, string title = "FileSelect") + { + EGodotFileDialog fileDialog = self.SingletoneNode("FileDialog"); + fileDialog.Title = title; + fileDialog.RootSubfolder = filePath; + fileDialog.InitDirSelect(selectPath); + } } } diff --git a/addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotFileDialog.cs b/addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotFileDialog.cs new file mode 100644 index 0000000..79d6309 --- /dev/null +++ b/addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotFileDialog.cs @@ -0,0 +1,70 @@ + +using System; +using Godot; + +namespace EGFramework.UI +{ + public partial class EGodotFileDialog : FileDialog, IEGFramework + { + private EasyEventOnce OnFileSelect { set; get; } = new EasyEventOnce(); + private EasyEventOnce OnDirSelect { set; get; } = new EasyEventOnce(); + private EasyEventOnce OnFilesSelect { set; get; } = new EasyEventOnce(); + + private bool IsInit { set; get; } = false; + public void Init() + { + if (!IsInit) + { + this.FileSelected += OnFileSelect.Invoke; + this.DirSelected += OnDirSelect.Invoke; + this.FilesSelected += OnFilesSelect.Invoke; + this.Size = new Vector2I(480, 320); + IsInit = true; + } + } + public void InitFileSelect(Action callback) + { + OnFileSelect.Register(callback); + Init(); + this.FileMode = FileModeEnum.OpenFile; + this.PopupCentered(); + } + + public void InitDirSelect(Action callback) + { + OnDirSelect.Register(callback); + this.FileMode = FileModeEnum.OpenDir; + Init(); + this.PopupCentered(); + } + + public void InitFilesSelect(Action callback) + { + OnFilesSelect.Register(callback); + this.FileMode = FileModeEnum.OpenFiles; + Init(); + this.PopupCentered(); + } + + public void InitAnySelect(Action singleSelectCallback, Action multiSelectCallback) + { + OnFileSelect.Register(singleSelectCallback); + OnDirSelect.Register(singleSelectCallback); + OnFilesSelect.Register(multiSelectCallback); + this.FileMode = FileModeEnum.OpenAny; + Init(); + this.PopupCentered(); + } + + public void InitSaveFileSelect(Action callback) + { + OnFileSelect.Register(callback); + this.FileMode = FileModeEnum.SaveFile; + Init(); + this.PopupCentered(); + } + + + + } +} diff --git a/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditParam.cs b/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditParam.cs index c0f21a8..7ef97ce 100644 --- a/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditParam.cs +++ b/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditParam.cs @@ -13,6 +13,7 @@ namespace EGFramework.UI public Label ParamReadOnly { get; set; } public SpinBox ParamSpinBox { get; set; } public HSlider ParamSlider { get; set; } + public Button ParamOperate { get; set; } private Type ValueType { set; get; } public override void Init(KeyValuePair editValue) @@ -112,6 +113,20 @@ namespace EGFramework.UI ParamSlider.Value = rangeParam.Value; this.AddChild(ParamSlider); } + else if (editValue.Value is EGPathSelect) + { + EGPathSelect pathSelect = (EGPathSelect)editValue.Value; + this.ParamReadOnly = new Label(); + ParamReadOnly.Name = "ParamReadOnly"; + ParamReadOnly.SizeFlagsHorizontal = SizeFlags.ExpandFill; + ParamReadOnly.Text = pathSelect.Path; + this.AddChild(ParamReadOnly); + this.ParamOperate = new Button(); + ParamOperate.Name = "Select file"; + ParamOperate.SizeFlagsHorizontal = SizeFlags.ExpandFill; + // ParamOperate.Pressed += + this.AddChild(ParamOperate); + } } public string GetKey() diff --git a/addons/EGFramework/Module/GenerateTools/Templete/Variant/EGDataStruct.cs b/addons/EGFramework/Module/GenerateTools/Templete/Variant/EGDataStruct.cs index 5ff42df..5554950 100644 --- a/addons/EGFramework/Module/GenerateTools/Templete/Variant/EGDataStruct.cs +++ b/addons/EGFramework/Module/GenerateTools/Templete/Variant/EGDataStruct.cs @@ -27,7 +27,15 @@ namespace EGFramework Value = value; } } - public interface IEGReadOnlyString{ + + public struct EGPathSelect + { + public string Path { set; get; } + public bool IsDir { set; get; } + } + + public interface IEGReadOnlyString + { public string GetString(); } public struct EGReadOnlyString : IEGReadOnlyString{