From 015b3ff47d323209cebdeebe62c470073b1dc1cd Mon Sep 17 00:00:00 2001 From: jkpete <1031139173@qq.com> Date: Thu, 19 Jun 2025 17:53:22 +0800 Subject: [PATCH] fix generate rowdata and params --- Example/SaveSystem/Script/ViewSaveSystem.cs | 2 + ...{EGBasicDialog.cs => EGodotBasicDialog.cs} | 2 +- .../Templete/Godot/Dialog/EGodotEditDialog.cs | 106 ++++++++++++++++++ .../Templete/Godot/EGodotEditDialog.cs | 78 ------------- .../Templete/Godot/UI/EGodotEditParam.cs | 51 +++++---- .../Templete/Godot/UI/EGodotParam.cs | 34 ++++++ .../Godot/{ => UI}/EGodotTableRowData.cs | 29 +++-- .../Module/NodeExtension/EGNode.cs | 20 +++- 8 files changed, 205 insertions(+), 117 deletions(-) rename addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/{EGBasicDialog.cs => EGodotBasicDialog.cs} (97%) create mode 100644 addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotEditDialog.cs delete mode 100644 addons/EGFramework/Module/GenerateTools/Templete/Godot/EGodotEditDialog.cs create mode 100644 addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotParam.cs rename addons/EGFramework/Module/GenerateTools/Templete/Godot/{ => UI}/EGodotTableRowData.cs (71%) diff --git a/Example/SaveSystem/Script/ViewSaveSystem.cs b/Example/SaveSystem/Script/ViewSaveSystem.cs index 19ca704..5be98ff 100644 --- a/Example/SaveSystem/Script/ViewSaveSystem.cs +++ b/Example/SaveSystem/Script/ViewSaveSystem.cs @@ -43,6 +43,8 @@ namespace EGFramework.Examples.Test{ rowData.Init(new Dictionary() { { "Name", "Tom" }, { "Age", 18 } }); EGodotRowData rowData2 = table.CreateNode("RowData2"); rowData2.Init(new Dictionary() { { "Name", "Z" }, { "Age", 1 } }); + EGodotEditParam editParam = table.CreateNode("editParam"); + editParam.Init(new KeyValuePair("数量",1)); } public override void _ExitTree() diff --git a/addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGBasicDialog.cs b/addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotBasicDialog.cs similarity index 97% rename from addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGBasicDialog.cs rename to addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotBasicDialog.cs index 80a2d4a..df25c45 100644 --- a/addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGBasicDialog.cs +++ b/addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotBasicDialog.cs @@ -2,7 +2,7 @@ using System; using Godot; namespace EGFramework.UI { - public static class EGBasicDialogExtension + public static class EGodotBasicDialogExtension { public static void EGAlert(this Node self, string alertMsg, string title = "Alert") { diff --git a/addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotEditDialog.cs b/addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotEditDialog.cs new file mode 100644 index 0000000..c48c72a --- /dev/null +++ b/addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotEditDialog.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using Godot; + +namespace EGFramework.UI +{ + public partial class EGodotEditDialog : ConfirmationDialog, IEGFramework + { + public VBoxContainer EditList { get; set; } + 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 InitDialog(Dictionary data, Action> onDataEdit, string title = "Edit Data", int width = DefaultWidth, int height = DefaultHeight) + { + if (!IsInit) + { + EditList = new VBoxContainer(); + EditList.Name = "EditList"; + EditList.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill; + this.AddChild(EditList); + this.Connect("confirmed", Callable.From(OnConfirm)); + this.Size = new Vector2I(width, height); + IsInit = true; + } + this.EditList.ClearChildren(); + ParamUIs.Clear(); + this.Title = title; + OnDataEdit = OnEdit.Register(onDataEdit); + this.ErrorTips = new Label(); + ErrorTips.Name = "ErrorTips"; + ErrorTips.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill; + EditList.AddChild(ErrorTips); + ErrorTips.Visible = false; + foreach (KeyValuePair param in data) + { + EGodotEditParam paramUI = new EGodotEditParam(); + this.EditList.AddChild(paramUI); + paramUI.Init(param); + ParamUIs.Add(paramUI); + } + this.PopupCentered(); + } + + public void OnConfirm() + { + EditCache.Clear(); + foreach (EGodotEditParam paramUI in ParamUIs) + { + EditCache.Add(paramUI.GetKey(), paramUI.GetValue()); + + GD.Print(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; + } + } + public static class EGodotEditDialogExtension + { + public static EGodotEditDialog EGEditDialog(this Node self, Dictionary data, Action> onDataEdit, string title = "Edit") + { + EGodotEditDialog editDialog = self.SingletoneNode("FileDialog"); + editDialog.InitDialog(data, onDataEdit, title); + editDialog.PopupCentered(); + return editDialog; + } + } +} \ No newline at end of file diff --git a/addons/EGFramework/Module/GenerateTools/Templete/Godot/EGodotEditDialog.cs b/addons/EGFramework/Module/GenerateTools/Templete/Godot/EGodotEditDialog.cs deleted file mode 100644 index 4e8ff21..0000000 --- a/addons/EGFramework/Module/GenerateTools/Templete/Godot/EGodotEditDialog.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System; -using System.Collections.Generic; -using Godot; - -namespace EGFramework.UI -{ - public partial class EGodotEditDialog : ConfirmationDialog,IEGFramework - { - public VBoxContainer EditList { get; set; } - 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; - - public void InitDialog(Dictionary data,Action> onDataEdit,string title = "Edit Data"){ - if(!IsInit){ - EditList = new VBoxContainer(); - EditList.Name = "EditList"; - EditList.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill; - this.AddChild(EditList); - this.ErrorTips = new Label(); - ErrorTips.Name = "ErrorTips"; - ErrorTips.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill; - EditList.AddChild(ErrorTips); - IsInit = true; - } - this.Title = title; - ErrorTips.Visible = false; - OnDataEdit = OnEdit.Register(onDataEdit); - this.EditList.ClearChildren(); - ParamUIs.Clear(); - foreach(KeyValuePair param in data){ - EGodotEditParam paramUI = new EGodotEditParam(); - this.EditList.AddChild(paramUI); - paramUI.Init(param); - ParamUIs.Add(paramUI); - } - this.Connect("confirmed",Callable.From(OnConfirm)); - this.PopupCentered(); - } - - 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; - } - } -} \ No newline at end of file diff --git a/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditParam.cs b/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditParam.cs index 9e42f1a..e5d13f9 100644 --- a/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditParam.cs +++ b/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditParam.cs @@ -1,17 +1,11 @@ +using System; using System.Collections.Generic; using Godot; namespace EGFramework.UI { - public interface IEGodotParam : IEGodotData + public partial class EGodotEditParam : EGodotParam, IEGFramework { - public void Init(KeyValuePair data); - public void RefreshData(KeyValuePair data); - public KeyValuePair GetData(); - } - public partial class EGodotEditParam : HBoxContainer, IEGFramework - { - public Label ParamName { get; set; } public LineEdit ParamEdit { get; set; } public OptionButton ParamOption { get; set; } public CheckButton ParamCheck { get; set; } @@ -19,18 +13,11 @@ namespace EGFramework.UI public Label ParamReadOnly { get; set; } public SpinBox ParamSpinBox { get; set; } public HSlider ParamSlider { get; set; } + private Type ValueType { set; get; } - public KeyValuePair EditValue { get; set; } - - public void Init(KeyValuePair editValue) + public override void Init(KeyValuePair editValue) { - EditValue = editValue; - this.ParamName = new Label(); - ParamName.Name = "ParamName"; - ParamName.Text = editValue.Key; - ParamName.SizeFlagsHorizontal = SizeFlags.ExpandFill; - this.AddChild(ParamName); - ParamName.Text = editValue.Key; + base.Init(editValue); if (editValue.Value is string) { this.ParamEdit = new LineEdit(); @@ -74,32 +61,35 @@ namespace EGFramework.UI this.ParamSpinBox = new SpinBox(); ParamSpinBox.Name = "ParamSpinBox"; ParamSpinBox.SizeFlagsHorizontal = SizeFlags.ExpandFill; - ParamSpinBox.Value = (int)editValue.Value; ParamSpinBox.MaxValue = int.MaxValue; ParamSpinBox.MinValue = int.MinValue; + ParamSpinBox.Value = (int)editValue.Value; this.AddChild(ParamSpinBox); + ValueType = typeof(int); } else if (editValue.Value is float) { this.ParamSpinBox = new SpinBox(); ParamSpinBox.Name = "ParamSpinBox"; ParamSpinBox.SizeFlagsHorizontal = SizeFlags.ExpandFill; - ParamSpinBox.Value = (float)editValue.Value; ParamSpinBox.MaxValue = float.MaxValue; ParamSpinBox.MinValue = float.MinValue; + ParamSpinBox.Value = (float)editValue.Value; ParamSpinBox.Step = 0.01f; this.AddChild(ParamSpinBox); + ValueType = typeof(float); } else if (editValue.Value is double) { this.ParamSpinBox = new SpinBox(); ParamSpinBox.Name = "ParamSpinBox"; ParamSpinBox.SizeFlagsHorizontal = SizeFlags.ExpandFill; - ParamSpinBox.Value = (double)editValue.Value; ParamSpinBox.MaxValue = double.MaxValue; ParamSpinBox.MinValue = double.MinValue; + ParamSpinBox.Value = (double)editValue.Value; ParamSpinBox.Step = 0.0001f; this.AddChild(ParamSpinBox); + ValueType = typeof(double); } else if (editValue.Value is EGRangeParam) { @@ -117,7 +107,7 @@ namespace EGFramework.UI public string GetKey() { - return EditValue.Key; + return ParamValue.Key; } public object GetValue() @@ -140,6 +130,14 @@ namespace EGFramework.UI } else if (ParamSpinBox != null) { + if (ValueType == typeof(int)) + { + return (int)ParamSpinBox.Value; + } + else if(ValueType == typeof(float)) + { + return (float)ParamSpinBox.Value; + } return ParamSpinBox.Value; } else if (ParamSlider != null) @@ -149,5 +147,14 @@ namespace EGFramework.UI return null; } + public override KeyValuePair GetData() + { + return new KeyValuePair(GetKey(), GetValue()); + } + + public override void RefreshData(KeyValuePair data) + { + //this param cannot be Refreshed,please remove and recreate a new EGodotEditParam. + } } } \ No newline at end of file diff --git a/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotParam.cs b/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotParam.cs new file mode 100644 index 0000000..f6d9bb4 --- /dev/null +++ b/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotParam.cs @@ -0,0 +1,34 @@ +using System.Collections.Generic; +using Godot; + +namespace EGFramework.UI +{ + public interface IEGodotParam : IEGodotData + { + public void Init(KeyValuePair data); + public void RefreshData(KeyValuePair data); + public KeyValuePair GetData(); + } + public abstract partial class EGodotParam : BoxContainer, IEGFramework, IEGodotParam + { + public Label ParamName { get; set; } + public KeyValuePair ParamValue { get; set; } + + public virtual void Init(KeyValuePair paramValue) + { + ParamValue = paramValue; + this.ParamName = new Label(); + ParamName.Name = "ParamName"; + ParamName.Text = ParamValue.Key; + ParamName.SizeFlagsHorizontal = SizeFlags.ExpandFill; + this.AddChild(ParamName); + } + public void RefreshData() + { + this.RefreshData(this.ParamValue); + } + public abstract KeyValuePair GetData(); + + public abstract void RefreshData(KeyValuePair data); + } +} \ No newline at end of file diff --git a/addons/EGFramework/Module/GenerateTools/Templete/Godot/EGodotTableRowData.cs b/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotTableRowData.cs similarity index 71% rename from addons/EGFramework/Module/GenerateTools/Templete/Godot/EGodotTableRowData.cs rename to addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotTableRowData.cs index 943fda1..e84333b 100644 --- a/addons/EGFramework/Module/GenerateTools/Templete/Godot/EGodotTableRowData.cs +++ b/addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotTableRowData.cs @@ -9,12 +9,9 @@ namespace EGFramework.UI{ public Button Modify { get; set; } public Button Delete { get; set; } - private Action> OnDataEdit; - public override void Init(Dictionary data) { base.Init(data); - Operate = new HBoxContainer(); Operate.Name = "Operate"; Operate.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill; @@ -31,18 +28,28 @@ namespace EGFramework.UI{ Operate.AddChild(Delete); Modify.Connect("pressed",Callable.From(OnEdit)); Delete.Connect("pressed",Callable.From(OnDelete)); - OnDataEdit = e => { - - }; } public void OnEdit(){ - // if(Data == null){ - // return ; - // } - // this.EditParams(Data.GetModifyParams(),OnDataEdit,"修改"); + if(Data == null){ + return ; + } + this.EGEditDialog(Data,OnDataEdit,"修改"); + } + + public virtual void OnDataEdit(Dictionary e) + { + this.Data = e; + this.RefreshData(); } - public void OnDelete(){ + public override void RefreshData(Dictionary data) + { + base.RefreshData(data); + Operate.ToEnd(); + } + + public void OnDelete() + { } } diff --git a/addons/EGFramework/Module/NodeExtension/EGNode.cs b/addons/EGFramework/Module/NodeExtension/EGNode.cs index a4060c4..67eb9e5 100644 --- a/addons/EGFramework/Module/NodeExtension/EGNode.cs +++ b/addons/EGFramework/Module/NodeExtension/EGNode.cs @@ -4,15 +4,19 @@ using System; namespace EGFramework{ public static class EGNodeExtension { - public static TModule NodeModule(this Node self) where TModule : Node,IModule,new(){ - if(EGArchitectureImplement.Interface.IsInitModule()){ + public static TModule NodeModule(this Node self) where TModule : Node, IModule, new() + { + if (EGArchitectureImplement.Interface.IsInitModule()) + { TModule module = new TModule(); module.Name = typeof(TModule).ToString(); Print(module.Name); self.AddChild(module); EGArchitectureImplement.Interface.RegisterModule(module); return module; - }else{ + } + else + { return EGArchitectureImplement.Interface.GetModule(); } } @@ -29,12 +33,13 @@ namespace EGFramework{ { foreach (Node child in itemContainer.GetChildren()) { - if(child.GetType()==typeof(T)){ + if (child.GetType() == typeof(T)) + { child.QueueFree(); } } } - + [Obsolete("This method can be replaced by ClearChildren