Browse Source

fixed to generate

master
jkpete 3 months ago
parent
commit
ab01db9bdf
  1. 90
      addons/EGFramework/Module/GenerateTools/DataGenerate/EGSvgGenerator.cs
  2. 12
      addons/EGFramework/Module/GenerateTools/DataInterface/ITableData.cs
  3. 6
      addons/EGFramework/Module/GenerateTools/GenerateToolsInterface.cs
  4. 63
      addons/EGFramework/Module/GenerateTools/PlatformGenerate/EGGodotUIGenerator.cs
  5. 3
      addons/EGFramework/Module/GenerateTools/PlatformInterface/IGodotTable.cs
  6. 54
      addons/EGFramework/Module/NodeExtension/EGCreate.cs

90
addons/EGFramework/Module/GenerateTools/DataGenerate/EGSvgGenerator.cs

@ -0,0 +1,90 @@
namespace EGFramework{
public class EGSvgGenerator : IGenerateToolsInterface
{
public string SvgHeader { get ; private set;}
public const string SvgFooter = "</svg>";
public int Width { get; set; }
public int Height { get; set; }
public EGSvgViewBox ViewBox { get; set; }
public EGSvgGenerator(int width, int height, EGSvgViewBox viewBox)
{
Width = width;
Height = height;
ViewBox = viewBox;
SvgHeader = $"<svg width=\"{width}\" height=\"{height}\" viewBox=\"{viewBox.X} {viewBox.Y} {viewBox.Width} {viewBox.Height}\" xmlns=\"http://www.w3.org/2000/svg\">";
}
public void DrawCircle(float x, float y, float radius, string color)
{
// Implementation for drawing a circle in SVG format
string svgCircle = $"<circle cx=\"{x}\" cy=\"{y}\" r=\"{radius}\" fill=\"{color}\" />";
}
public void DrawEllipse(float cx, float cy, float rx, float ry, string color)
{
// Implementation for drawing an ellipse in SVG format
string svgEllipse = $"<ellipse cx=\"{cx}\" cy=\"{cy}\" rx=\"{rx}\" ry=\"{ry}\" fill=\"{color}\" />";
}
public void DrawPolygon(float[] points, string color)
{
// Implementation for drawing a polygon in SVG format
string svgPolygon = "<polygon points=\"";
for (int i = 0; i < points.Length; i += 2)
{
svgPolygon += $"{points[i]},{points[i + 1]} ";
}
svgPolygon += $"\" fill=\"{color}\" />";
}
public void DrawPolyline(float[] points, string color)
{
// Implementation for drawing a polyline in SVG format
string svgPolyline = "<polyline points=\"";
for (int i = 0; i < points.Length; i += 2)
{
svgPolyline += $"{points[i]},{points[i + 1]} ";
}
svgPolyline += $"\" stroke=\"{color}\" fill=\"none\" />";
}
public void DrawPath(string d, string color)
{
// Implementation for drawing a path in SVG format
string svgPath = $"<path d=\"{d}\" fill=\"{color}\" />";
}
public void DrawRectangle(float x, float y, float width, float height, string color)
{
// Implementation for drawing a rectangle in SVG format
string svgRectangle = $"<rect x=\"{x}\" y=\"{y}\" width=\"{width}\" height=\"{height}\" fill=\"{color}\" />";
}
public void DrawLine(float x1, float y1, float x2, float y2, string color)
{
// Implementation for drawing a line in SVG format
string svgLine = $"<line x1=\"{x1}\" y1=\"{y1}\" x2=\"{x2}\" y2=\"{y2}\" stroke=\"{color}\" />";
}
public void DrawText(float x, float y, string text, string color)
{
// Implementation for drawing text in SVG format
string svgText = $"<text x=\"{x}\" y=\"{y}\" fill=\"{color}\">{text}</text>";
}
public string GenerateCode<T>()
{
return typeof(T).Name;
}
}
public struct EGSvgViewBox {
public float X { get; set; }
public float Y { get; set; }
public float Width { get; set; }
public float Height { get; set; }
public EGSvgViewBox(float x, float y, float width, float height)
{
X = x;
Y = y;
Width = width;
Height = height;
}
}
}

12
addons/EGFramework/Module/GenerateTools/DataInterface/ITableData.cs

@ -1,5 +1,6 @@
public interface ITableData namespace EGFramework{
{ public interface ITableData
{
/// <summary> /// <summary>
/// Get the data of the table. /// Get the data of the table.
/// </summary> /// </summary>
@ -10,9 +11,10 @@ public interface ITableData
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
string[] GetTableHeader(); string[] GetTableHeader();
} }
public interface ITableRowData public interface ITableRowData
{ {
string[] GetRowData(); string[] GetRowData();
}
} }

6
addons/EGFramework/Module/GenerateTools/GenerateToolsInterface.cs

@ -0,0 +1,6 @@
namespace EGFramework{
public interface IGenerateToolsInterface
{
public string GenerateCode<T>();
}
}

63
addons/EGFramework/Module/GenerateTools/PlatformGenerate/EGGodotUIGenerator.cs

@ -0,0 +1,63 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Godot;
namespace EGFramework{
public static class EGGodotTableGenerator {
public static HBoxContainer CreateRowData(this Node self,string[] titleList,string rowName = "RowData"){
HBoxContainer RowData = new HBoxContainer();
RowData.Name = rowName;
foreach(string s in titleList){
Label label = new Label();
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);
}
self.AddChild(RowData);
return RowData;
}
public static VBoxContainer CreateTable(this Node self,string[][] tableStr,string tableName = "Table"){
VBoxContainer Table = new VBoxContainer();
Table.Name = tableName;
int dataPointer = 0;
foreach(string[] s in tableStr){
Table.CreateRowData(s,"tableRowData"+dataPointer);
dataPointer++;
}
self.AddChild(Table);
return Table;
}
public static VBoxContainer CreateTable<T>(this Node self,IEnumerable<T> 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;
}
}
}

3
addons/EGFramework/Module/GenerateTools/PlatformInterface/IGodotTable.cs

@ -0,0 +1,3 @@
namespace EGFramework{
}

54
addons/EGFramework/Module/NodeExtension/EGCreate.cs

@ -54,60 +54,6 @@ namespace EGFramework{
acceptDialog.DialogText = alertMsg; acceptDialog.DialogText = alertMsg;
acceptDialog.PopupCentered(); acceptDialog.PopupCentered();
} }
public static HBoxContainer CreateRowData(this Node self,string[] titleList,string rowName = "RowData"){
HBoxContainer RowData = new HBoxContainer();
RowData.Name = rowName;
foreach(string s in titleList){
Label label = new Label();
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);
}
self.AddChild(RowData);
return RowData;
}
public static VBoxContainer CreateTable(this Node self,string[][] tableStr,string tableName = "Table"){
VBoxContainer Table = new VBoxContainer();
Table.Name = tableName;
int dataPointer = 0;
foreach(string[] s in tableStr){
Table.CreateRowData(s,"tableRowData"+dataPointer);
dataPointer++;
}
self.AddChild(Table);
return Table;
}
public static VBoxContainer CreateTable<T>(this Node self,IEnumerable<T> 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"){ public static Tree CreateTree(this Node self,string treeName = "Tree"){
Tree tree = new Tree(); Tree tree = new Tree();
tree.Name = treeName; tree.Name = treeName;

Loading…
Cancel
Save