diff --git a/Example/SaveSystem/Script/ViewSaveSystem.cs b/Example/SaveSystem/Script/ViewSaveSystem.cs index 9a8ad30..07d4e21 100644 --- a/Example/SaveSystem/Script/ViewSaveSystem.cs +++ b/Example/SaveSystem/Script/ViewSaveSystem.cs @@ -20,14 +20,12 @@ namespace EGFramework.Examples.Test{ string[] c = {"Jerry","20"}; DataList[2] = c; this.GetNode("TabContainer").CreateTable(DataList,"Student"); - DataList2 = new string[3][]; - string[] d = {"Name","Age"}; - DataList2[0] = d; - string[] e = {"Jim","60"}; - DataList2[1] = e; - string[] f = {"Bob","50"}; - DataList2[2] = f; - this.GetNode("TabContainer").CreateTable(DataList2,"Teacher"); + DataStudent dataStudent = new DataStudent("S",18); + DataStudent dataStudent2 = new DataStudent(null,20); + List dataStudents = new List(); + dataStudents.Add(dataStudent); + dataStudents.Add(dataStudent2); + this.GetNode("TabContainer").CreateTable(dataStudents,"Teacher"); } public override void _ExitTree() @@ -36,4 +34,14 @@ namespace EGFramework.Examples.Test{ } } + public struct DataStudent{ + public string Name { get; set; } + public int Age; + public int ID; + public DataStudent(string name,int age){ + Name = name; + Age = age; + ID = 0; + } + } } \ No newline at end of file diff --git a/addons/EGFramework/Module/NodeExtension/EGCreate.cs b/addons/EGFramework/Module/NodeExtension/EGCreate.cs index f5a4c51..cad2cb4 100644 --- a/addons/EGFramework/Module/NodeExtension/EGCreate.cs +++ b/addons/EGFramework/Module/NodeExtension/EGCreate.cs @@ -1,5 +1,11 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; using System.Runtime.CompilerServices; using Godot; +using Mysqlx.Crud; using static Godot.GD; namespace EGFramework{ @@ -53,8 +59,13 @@ namespace EGFramework{ RowData.Name = rowName; foreach(string s in titleList){ Label label = new Label(); - label.Name = s; - label.Text = s; + if(s != null){ + label.Name = s; + label.Text = s; + }else{ + label.Name = "Null"; + label.Text = "Null"; + } label.HorizontalAlignment = HorizontalAlignment.Center; label.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill; RowData.AddChild(label); @@ -71,8 +82,37 @@ namespace EGFramework{ dataPointer++; } self.AddChild(Table); - EG.Print("CreateTable",tableStr.Length); return Table; } + public static VBoxContainer CreateTable(this Node self,IEnumerable tableData,string tableName = "ObjectTable",int limit = 0){ + VBoxContainer Table = new VBoxContainer(); + Table.Name = tableName; + MemberInfo[] propertyNames = typeof(T).GetProperties(); + MemberInfo[] fieldNames = typeof(T).GetFields(); + MemberInfo[] memberInfos = propertyNames.Concat(fieldNames).ToArray(); + string[] propertyName = new string[memberInfos.Length]; + int dataPointer = 0; + for (int i = 0; i < memberInfos.Length; i++) + { + propertyName[i] = memberInfos[i].Name; + } + Table.CreateRowData(propertyName,"Title"); + foreach (T t in tableData) + { + string[] s = t.GetType().GetProperties().Select(p => p.GetValue(t)?.ToString()).ToArray(); + string[] a = t.GetType().GetFields().Select(p => p.GetValue(t)?.ToString()).ToArray(); + string[] result = s.Concat(a).ToArray(); + Table.CreateRowData(result, "tableRowData"+dataPointer); + dataPointer++; + } + self.AddChild(Table); + return Table; + } + public static Tree CreateTree(this Node self,string treeName = "Tree"){ + Tree tree = new Tree(); + tree.Name = treeName; + self.AddChild(tree); + return tree; + } } }