Browse Source

add basic dialog

master
jkpete 2 months ago
parent
commit
09bbf71694
  1. 19
      Example/SaveSystem/Script/ViewSaveSystem.cs
  2. 59
      addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGBasicDialog.cs
  3. 76
      addons/EGFramework/Module/GenerateTools/Templete/Godot/EGCreate.cs
  4. 41
      addons/EGFramework/Module/GenerateTools/Templete/Godot/EGodotTableRowData.cs
  5. 52
      addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGRowData.cs
  6. 84
      addons/EGFramework/Module/NodeExtension/EGCreate.cs
  7. 2
      project.godot

19
Example/SaveSystem/Script/ViewSaveSystem.cs

@ -14,19 +14,19 @@ namespace EGFramework.Examples.Test{
public override void _Ready() public override void _Ready()
{ {
DataList = new string[3][]; DataList = new string[3][];
string[] a = {"Name","Age"}; string[] a = { "Name", "Age" };
DataList[0] = a; DataList[0] = a;
string[] b = {"Tom","18"}; string[] b = { "Tom", "18" };
DataList[1] = b; DataList[1] = b;
string[] c = {"Jerry","20"}; string[] c = { "Jerry", "20" };
DataList[2] = c; DataList[2] = c;
this.GetNode<TabContainer>("TabContainer").CreateTable(DataList,"Student"); this.GetNode<TabContainer>("TabContainer").CreateTable(DataList, "Student");
DataStudent dataStudent = new DataStudent("S",18); DataStudent dataStudent = new DataStudent("S", 18);
DataStudent dataStudent2 = new DataStudent(null,20); DataStudent dataStudent2 = new DataStudent(null, 20);
List<DataStudent> dataStudents = new List<DataStudent>(); List<DataStudent> dataStudents = new List<DataStudent>();
dataStudents.Add(dataStudent); dataStudents.Add(dataStudent);
dataStudents.Add(dataStudent2); dataStudents.Add(dataStudent2);
EGodotTable table = this.GetNode<TabContainer>("TabContainer").CreateTable<DataStudent>(dataStudents,"Teacher"); EGodotTable table = this.GetNode<TabContainer>("TabContainer").CreateTable<DataStudent>(dataStudents, "Teacher");
// Button btn = this.CreateNode<Button>("Test"); // Button btn = this.CreateNode<Button>("Test");
// btn.Text = "Test"; // btn.Text = "Test";
// btn.Position = new Vector2(100,100); // btn.Position = new Vector2(100,100);
@ -40,13 +40,12 @@ namespace EGFramework.Examples.Test{
// }); // });
EGodotTableRowData rowData = table.CreateNode<EGodotTableRowData>("RowData"); EGodotTableRowData rowData = table.CreateNode<EGodotTableRowData>("RowData");
rowData.InitRowData(new Dictionary<string, object>() {{"Name","Tom"},{"Age",18}}); rowData.InitRowData(new Dictionary<string, object>() { { "Name", "Tom" }, { "Age", 18 } });
} }
public override void _ExitTree() public override void _ExitTree()
{ {
} }

59
addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGBasicDialog.cs

@ -0,0 +1,59 @@
using System;
using Godot;
namespace EGFramework.UI
{
public static class EGBasicDialogExtension
{
public static void EGAlert(this Node self, string alertMsg, string title = "Alert")
{
AcceptDialog acceptDialog = self.SingletoneNode<AcceptDialog>("AlertDialog");
acceptDialog.Title = title;
acceptDialog.DialogText = alertMsg;
acceptDialog.PopupCentered();
}
public static void EGConfirm(this Node self, string alertMsg, Action<bool> callback, string title = "Confirm")
{
ConfirmationDialog confirmDialog = self.SingletoneNode<ConfirmationDialog>("ConfirmDialog");
confirmDialog.Title = title;
confirmDialog.DialogText = alertMsg;
confirmDialog.PopupCentered();
confirmDialog.Connect("confirmed", Callable.From(() =>
{
callback(true);
}));
confirmDialog.Connect("canceled", Callable.From(() =>
{
callback(false);
}));
}
public static void EGFileSingleSelect(this Node self, string filePath, Action<string> selectPath, string title = "FileSelect")
{
FileDialog fileDialog = self.SingletoneNode<FileDialog>("FileDialog");
fileDialog.Title = title;
fileDialog.Size = new Vector2I(480, 320);
fileDialog.FileMode = FileDialog.FileModeEnum.OpenFile;
fileDialog.RootSubfolder = filePath;
fileDialog.PopupCentered();
fileDialog.Connect("file_selected", Callable.From<string>(path =>
{
selectPath(path);
}));
}
public static void EGDocumentSelect(this Node self, string filePath, Action<string> selectPath, string title = "FileSelect")
{
FileDialog fileDialog = self.SingletoneNode<FileDialog>("FileDialog");
fileDialog.Title = title;
fileDialog.Size = new Vector2I(480, 320);
fileDialog.FileMode = FileDialog.FileModeEnum.OpenDir;
fileDialog.RootSubfolder = filePath;
fileDialog.PopupCentered();
fileDialog.Connect("file_selected", Callable.From<string>(path =>
{
selectPath(path);
}));
}
}
}

76
addons/EGFramework/Module/GenerateTools/Templete/Godot/EGCreate.cs

@ -0,0 +1,76 @@
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{
public class EGSingletonNode : IEGFramework, IModule
{
public IOCContainer NodeContainer = new IOCContainer();
public void Init()
{
}
public IArchitecture GetArchitecture()
{
return EGArchitectureImplement.Interface;
}
}
public static class EGCanCreateNodeExtension
{
public static TNode CreateNode<TNode>(this Node self) where TNode : Node,new(){
TNode nodeData = new TNode();
nodeData.Name = typeof(TNode).Name;
self.AddChild(nodeData);
return nodeData;
}
public static TNode CreateNode<TNode>(this Node self,string name) where TNode : Node,new(){
TNode nodeData = new TNode();
nodeData.Name = name;
self.AddChild(nodeData);
return nodeData;
}
public static TNode SingletoneNode<TNode>(this Node self) where TNode : Node, new()
{
TNode nodeData;
if (EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Get<TNode>() != null)
{
nodeData = EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Get<TNode>();
}
else
{
nodeData = self.CreateNode<TNode>();
EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Register(nodeData);
}
nodeData.Name = typeof(TNode).Name;
return nodeData;
}
public static TNode SingletoneNode<TNode>(this Node self,string name) where TNode : Node, new()
{
TNode nodeData;
if (EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Get<TNode>() != null)
{
nodeData = EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Get<TNode>();
}
else
{
nodeData = self.CreateNode<TNode>();
EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Register(nodeData);
}
nodeData.Name = name;
return nodeData;
}
}
}

41
addons/EGFramework/Module/GenerateTools/Templete/Godot/EGodotTableRowData.cs

@ -3,47 +3,18 @@ using System.Collections.Generic;
using Godot; using Godot;
namespace EGFramework.UI{ namespace EGFramework.UI{
public partial class EGodotTableRowData : PanelContainer,IEGFramework public partial class EGodotTableRowData : EGRowData
{ {
public Button ItemHover { get; set; }
public ColorRect Line { get; set; }
public ColorRect BackGround { get; set; }
public HBoxContainer List { get; set; }
public Control Operate { get; set; } public Control Operate { get; set; }
public Button Modify { get; set; } public Button Modify { get; set; }
public Button Delete { get; set; } public Button Delete { get; set; }
private Dictionary<string,object> Data { get; set; }
private Action<Dictionary<string,object>> OnDataEdit; private Action<Dictionary<string,object>> OnDataEdit;
public void InitRowData(Dictionary<string,object> data){ public override void InitRowData(Dictionary<string, object> data)
this.Data = data; {
BackGround = new ColorRect(); base.InitRowData(data);
BackGround.Name = "BackGround";
BackGround.Color = new Color(0.5f,0.5f,1f);
BackGround.SizeFlagsHorizontal = SizeFlags.ExpandFill;
BackGround.SizeFlagsVertical = SizeFlags.ExpandFill;
this.AddChild(BackGround);
List = new HBoxContainer();
List.Name = "TableRow_"+Resource.GenerateSceneUniqueId();
List.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
this.AddChild(List);
Line = new ColorRect();
Line.Name = "Line";
Line.Color = new Color(0.5f,0.5f,0.5f);
Line.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
Line.SizeFlagsVertical = Control.SizeFlags.ShrinkEnd;
Line.CustomMinimumSize = new Vector2(0,1);
this.AddChild(Line);
foreach(KeyValuePair<string,object> kv in data){
this.List.AddChild(new Label(){
Name = kv.Key,
Text = kv.Value.ToString(),
HorizontalAlignment = HorizontalAlignment.Center,
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill
});
}
Operate = new HBoxContainer(); Operate = new HBoxContainer();
Operate.Name = "Operate"; Operate.Name = "Operate";
Operate.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill; Operate.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
@ -63,9 +34,7 @@ namespace EGFramework.UI{
OnDataEdit = e => { OnDataEdit = e => {
}; };
this.AddThemeStyleboxOverride("panel",new StyleBoxEmpty());
} }
public void OnEdit(){ public void OnEdit(){
// if(Data == null){ // if(Data == null){
// return ; // return ;

52
addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGRowData.cs

@ -0,0 +1,52 @@
using Godot;
using System;
using System.Collections.Generic;
namespace EGFramework.UI
{
public interface IEGRowData
{
}
public partial class EGRowData : PanelContainer, IEGFramework
{
public Button ItemHover { get; set; }
public ColorRect Line { get; set; }
public ColorRect BackGround { get; set; }
public HBoxContainer List { get; set; }
protected Dictionary<string, object> Data { get; set; }
public virtual void InitRowData(Dictionary<string,object> data){
this.Data = data;
BackGround = new ColorRect();
BackGround.Name = "BackGround";
BackGround.Color = new Color(0.5f,0.5f,1f);
BackGround.SizeFlagsHorizontal = SizeFlags.ExpandFill;
BackGround.SizeFlagsVertical = SizeFlags.ExpandFill;
this.AddChild(BackGround);
List = new HBoxContainer();
List.Name = "TableRow_"+Resource.GenerateSceneUniqueId();
List.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
this.AddChild(List);
Line = new ColorRect();
Line.Name = "Line";
Line.Color = new Color(0.5f,0.5f,0.5f);
Line.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
Line.SizeFlagsVertical = Control.SizeFlags.ShrinkEnd;
Line.CustomMinimumSize = new Vector2(0,1);
this.AddChild(Line);
foreach(KeyValuePair<string,object> kv in data){
this.List.AddChild(new Label(){
Name = kv.Key,
Text = kv.Value.ToString(),
HorizontalAlignment = HorizontalAlignment.Center,
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill
});
}
this.AddThemeStyleboxOverride("panel",new StyleBoxEmpty());
}
}
}

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

@ -1,84 +0,0 @@
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{
public class EGSingletonNode : IEGFramework, IModule
{
public IOCContainer NodeContainer = new IOCContainer();
public void Init()
{
}
public IArchitecture GetArchitecture()
{
return EGArchitectureImplement.Interface;
}
}
public static class EGCanCreateNodeExtension
{
public static TNode CreateNode<TNode>(this Node self) where TNode : Node,new(){
TNode nodeData = new TNode();
nodeData.Name = typeof(TNode).Name;
self.AddChild(nodeData);
return nodeData;
}
public static TNode CreateNode<TNode>(this Node self,string name) where TNode : Node,new(){
TNode nodeData = new TNode();
nodeData.Name = name;
self.AddChild(nodeData);
return nodeData;
}
public static void Alert(this Node self,string alertMsg,string title = "Alert"){
AcceptDialog acceptDialog;
if(EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Get<AcceptDialog>()!=null){
acceptDialog = EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Get<AcceptDialog>();
}else{
acceptDialog = self.CreateNode<AcceptDialog>();
}
EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Register(acceptDialog);
acceptDialog.Name = "AlertDialog";
acceptDialog.Title = title;
acceptDialog.DialogText = alertMsg;
acceptDialog.PopupCentered();
}
public static void Confirm(this Node self,string alertMsg,Action<bool> callback,string title = "Confirm"){
ConfirmationDialog confirmDialog;
if(EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Get<ConfirmationDialog>()!=null){
confirmDialog = EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Get<ConfirmationDialog>();
}else{
confirmDialog = self.CreateNode<ConfirmationDialog>();
}
EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Register(confirmDialog);
confirmDialog.Name = "ConfirmDialog";
confirmDialog.Title = title;
confirmDialog.DialogText = alertMsg;
confirmDialog.PopupCentered();
confirmDialog.Connect("confirmed",Callable.From(() => {
callback(true);
}));
confirmDialog.Connect("canceled",Callable.From(() => {
callback(false);
}));
}
public static Tree CreateTree(this Node self,string treeName = "Tree"){
Tree tree = new Tree();
tree.Name = treeName;
self.AddChild(tree);
return tree;
}
}
}

2
project.godot

@ -12,7 +12,7 @@ config_version=5
config/name="EGFramework" config/name="EGFramework"
config/tags=PackedStringArray("official") config/tags=PackedStringArray("official")
run/main_scene="res://Example/ProtocolHelper/Scene/ProtocolHelper.tscn" run/main_scene="res://Example/SaveSystem/Scene/SaveSystem.tscn"
config/features=PackedStringArray("4.3", "C#", "GL Compatibility") config/features=PackedStringArray("4.3", "C#", "GL Compatibility")
config/icon="res://EGFramework.svg" config/icon="res://EGFramework.svg"

Loading…
Cancel
Save