Browse Source

fix generate rowdata and params

master
jkpete 2 months ago
parent
commit
015b3ff47d
  1. 2
      Example/SaveSystem/Script/ViewSaveSystem.cs
  2. 2
      addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotBasicDialog.cs
  3. 106
      addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotEditDialog.cs
  4. 78
      addons/EGFramework/Module/GenerateTools/Templete/Godot/EGodotEditDialog.cs
  5. 51
      addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditParam.cs
  6. 34
      addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotParam.cs
  7. 29
      addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotTableRowData.cs
  8. 20
      addons/EGFramework/Module/NodeExtension/EGNode.cs

2
Example/SaveSystem/Script/ViewSaveSystem.cs

@ -43,6 +43,8 @@ namespace EGFramework.Examples.Test{ @@ -43,6 +43,8 @@ namespace EGFramework.Examples.Test{
rowData.Init(new Dictionary<string, object>() { { "Name", "Tom" }, { "Age", 18 } });
EGodotRowData rowData2 = table.CreateNode<EGodotRowData>("RowData2");
rowData2.Init(new Dictionary<string, object>() { { "Name", "Z" }, { "Age", 1 } });
EGodotEditParam editParam = table.CreateNode<EGodotEditParam>("editParam");
editParam.Init(new KeyValuePair<string, object>("数量",1));
}
public override void _ExitTree()

2
addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGBasicDialog.cs → addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotBasicDialog.cs

@ -2,7 +2,7 @@ using System; @@ -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")
{

106
addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotEditDialog.cs

@ -0,0 +1,106 @@ @@ -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<HBoxContainer> EditListItem { get; set; }
public Label ErrorTips { get; set; }
public EasyEvent<Dictionary<string, object>> OnEdit { set; get; } = new EasyEvent<Dictionary<string, object>>();
private Dictionary<string, object> EditCache { set; get; } = new Dictionary<string, object>();
private IUnRegister OnDataEdit { set; get; }
public List<EGodotEditParam> ParamUIs { set; get; } = new List<EGodotEditParam>();
private bool IsInit { set; get; } = false;
const int DefaultWidth = 640;
const int DefaultHeight = 320;
public void InitDialog(Dictionary<string, object> data, Action<Dictionary<string, object>> 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<string, object> 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<string, object> data, Action<Dictionary<string, object>> onDataEdit, string title = "Edit")
{
EGodotEditDialog editDialog = self.SingletoneNode<EGodotEditDialog>("FileDialog");
editDialog.InitDialog(data, onDataEdit, title);
editDialog.PopupCentered();
return editDialog;
}
}
}

78
addons/EGFramework/Module/GenerateTools/Templete/Godot/EGodotEditDialog.cs

@ -1,78 +0,0 @@ @@ -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<HBoxContainer> EditListItem { get; set; }
public Label ErrorTips { get; set; }
public EasyEvent<Dictionary<string,object>> OnEdit { set; get; } = new EasyEvent<Dictionary<string, object>>();
private Dictionary<string,object> EditCache { set; get; } = new Dictionary<string, object>();
private IUnRegister OnDataEdit { set; get; }
public List<EGodotEditParam> ParamUIs { set; get; } = new List<EGodotEditParam>();
private bool IsInit { set; get; } = false;
public void InitDialog(Dictionary<string,object> data,Action<Dictionary<string,object>> 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<string,object> 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;
}
}
}

51
addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditParam.cs

@ -1,17 +1,11 @@ @@ -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<string, object> data);
public void RefreshData(KeyValuePair<string, object> data);
public KeyValuePair<string, object> 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 @@ -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<string, object> EditValue { get; set; }
public void Init(KeyValuePair<string, object> editValue)
public override void Init(KeyValuePair<string, object> 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 @@ -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 @@ -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 @@ -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 @@ -149,5 +147,14 @@ namespace EGFramework.UI
return null;
}
public override KeyValuePair<string, object> GetData()
{
return new KeyValuePair<string, object>(GetKey(), GetValue());
}
public override void RefreshData(KeyValuePair<string, object> data)
{
//this param cannot be Refreshed,please remove and recreate a new EGodotEditParam.
}
}
}

34
addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotParam.cs

@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
using System.Collections.Generic;
using Godot;
namespace EGFramework.UI
{
public interface IEGodotParam : IEGodotData
{
public void Init(KeyValuePair<string, object> data);
public void RefreshData(KeyValuePair<string, object> data);
public KeyValuePair<string, object> GetData();
}
public abstract partial class EGodotParam : BoxContainer, IEGFramework, IEGodotParam
{
public Label ParamName { get; set; }
public KeyValuePair<string, object> ParamValue { get; set; }
public virtual void Init(KeyValuePair<string, object> 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<string, object> GetData();
public abstract void RefreshData(KeyValuePair<string, object> data);
}
}

29
addons/EGFramework/Module/GenerateTools/Templete/Godot/EGodotTableRowData.cs → addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotTableRowData.cs

@ -9,12 +9,9 @@ namespace EGFramework.UI{ @@ -9,12 +9,9 @@ namespace EGFramework.UI{
public Button Modify { get; set; }
public Button Delete { get; set; }
private Action<Dictionary<string,object>> OnDataEdit;
public override void Init(Dictionary<string, object> data)
{
base.Init(data);
Operate = new HBoxContainer();
Operate.Name = "Operate";
Operate.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
@ -31,18 +28,28 @@ namespace EGFramework.UI{ @@ -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<string, object> e)
{
this.Data = e;
this.RefreshData();
}
public void OnDelete(){
public override void RefreshData(Dictionary<string, object> data)
{
base.RefreshData(data);
Operate.ToEnd();
}
public void OnDelete()
{
}
}

20
addons/EGFramework/Module/NodeExtension/EGNode.cs

@ -4,15 +4,19 @@ using System; @@ -4,15 +4,19 @@ using System;
namespace EGFramework{
public static class EGNodeExtension
{
public static TModule NodeModule<TModule>(this Node self) where TModule : Node,IModule,new(){
if(EGArchitectureImplement.Interface.IsInitModule<TModule>()){
public static TModule NodeModule<TModule>(this Node self) where TModule : Node, IModule, new()
{
if (EGArchitectureImplement.Interface.IsInitModule<TModule>())
{
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<TModule>();
}
}
@ -29,12 +33,13 @@ namespace EGFramework{ @@ -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<Label>")]
public static void ClearChildrenLabel(this Node itemContainer)
{
@ -47,5 +52,10 @@ namespace EGFramework{ @@ -47,5 +52,10 @@ namespace EGFramework{
}
}
public static void ToEnd(this Node child)
{
child.GetParent()?.MoveChild(child,-1);
}
}
}
Loading…
Cancel
Save