Browse Source

fixed EditList

master
jkpete 2 months ago
parent
commit
d65fea1962
  1. 14
      Example/SaveSystem/Script/ViewSaveSystem.cs
  2. 123
      addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditList.cs

14
Example/SaveSystem/Script/ViewSaveSystem.cs

@ -22,7 +22,7 @@ namespace EGFramework.Examples.Test
// GD.Print(Tr("Data")+"+___+"); // GD.Print(Tr("Data")+"+___+");
// TestTable(); // TestTable();
// TestJson(); // TestJson();
this.CallDeferred("TestDialog"); // this.CallDeferred("TestDialog");
// SchoolType school = SchoolType.London; // SchoolType school = SchoolType.London;
// school.EGenerateMappingByEnum(); // school.EGenerateMappingByEnum();
// foreach (KeyValuePair<int, string> selectOptions in school.EGenerateMappingByEnum()) // foreach (KeyValuePair<int, string> selectOptions in school.EGenerateMappingByEnum())
@ -32,6 +32,7 @@ namespace EGFramework.Examples.Test
// TestDialog(); // TestDialog();
// TestMySQL(); // TestMySQL();
// EG.Print(OS.GetLocaleLanguage()); // EG.Print(OS.GetLocaleLanguage());
TestEdit();
} }
public override void _ExitTree() public override void _ExitTree()
@ -78,6 +79,17 @@ namespace EGFramework.Examples.Test
}, "Edit"); }, "Edit");
} }
public void TestEdit()
{
DataStudent dataStudent = new DataStudent("ZG",10);
container = this.GetNode<TabContainer>("TabContainer");
EGodotEditList editList = container.CreateNode<EGodotEditList>();
editList.InitList(dataStudent.EGenerateDictiontaryByObject(), e =>
{
GD.Print("Name:" + e["Name"] + "Age:" + e["Age"] + "School:" + e["School"] + "Path:" + e["Path"]);
}, "Edit");
}
public void TestJson() public void TestJson()
{ {
string json = @"{ string json = @"{

123
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<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 InitList(Dictionary<string, object> data, Action<Dictionary<string, object>> 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<string, object> 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;
}
}
}
Loading…
Cancel
Save