Browse Source

add popup method

master
jkpete 2 months ago
parent
commit
4d1d119124
  1. 5
      Example/SaveSystem/Script/ViewSaveSystem.cs
  2. 15
      addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotBasicDialog.cs
  3. 2
      addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotEditDialog.cs
  4. 58
      addons/EGFramework/Module/GenerateTools/Templete/Godot/EGCreate.cs
  5. 8
      addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotEditParam.cs

5
Example/SaveSystem/Script/ViewSaveSystem.cs

@ -37,6 +37,11 @@ namespace EGFramework.Examples.Test {
// rowData2.Init(new Dictionary<string, object>() { { "Name", "Z" }, { "Age", 1 } }); // rowData2.Init(new Dictionary<string, object>() { { "Name", "Z" }, { "Age", 1 } });
// EGodotEditParam editParam = container.CreateNode<EGodotEditParam>("editParam"); // EGodotEditParam editParam = container.CreateNode<EGodotEditParam>("editParam");
// editParam.Init(new KeyValuePair<string, object>("数量",1)); // editParam.Init(new KeyValuePair<string, object>("数量",1));
this.ExecuteAfterSecond(() =>
{
this.EGAlert("-----~!");
this.EGConfirm("fixed?", isconfirm => { GD.Print(isconfirm); });
},1.0f);
} }
public override void _ExitTree() public override void _ExitTree()

15
addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotBasicDialog.cs

@ -6,45 +6,40 @@ namespace EGFramework.UI
{ {
public static void EGAlert(this Node self, string alertMsg, string title = "Alert") public static void EGAlert(this Node self, string alertMsg, string title = "Alert")
{ {
AcceptDialog acceptDialog = self.SingletoneNode<AcceptDialog>("AlertDialog"); AcceptDialog acceptDialog = self.PopupNode<AcceptDialog>("AlertDialog");
acceptDialog.Title = title; acceptDialog.Title = title;
acceptDialog.DialogText = alertMsg; acceptDialog.DialogText = alertMsg;
acceptDialog.PopupCentered();
} }
public static void EGConfirm(this Node self, string alertMsg, Action<bool> callback, string title = "Confirm") public static void EGConfirm(this Node self, string alertMsg, Action<bool> callback, string title = "Confirm")
{ {
EGodotConfirmationDialog confirmDialog = self.SingletoneNode<EGodotConfirmationDialog>("ConfirmDialog"); EGodotConfirmationDialog confirmDialog = self.PopupNode<EGodotConfirmationDialog>("ConfirmDialog");
confirmDialog.Title = title; confirmDialog.Title = title;
confirmDialog.DialogText = alertMsg; confirmDialog.DialogText = alertMsg;
confirmDialog.PopupCentered();
confirmDialog.Init(callback); confirmDialog.Init(callback);
} }
public static void EGFileOpen(this Node self, string filePath, Action<string> selectPath, string title = "Open a file") public static void EGFileOpen(this Node self, string filePath, Action<string> selectPath, string title = "Open a file")
{ {
EGodotFileDialog fileDialog = self.SingletoneNode<EGodotFileDialog>("FileDialog"); EGodotFileDialog fileDialog = self.PopupNode<EGodotFileDialog>("FileDialog");
fileDialog.Title = title; fileDialog.Title = title;
fileDialog.RootSubfolder = filePath; fileDialog.RootSubfolder = filePath;
fileDialog.PopupCentered();
fileDialog.InitFileSelect(selectPath); fileDialog.InitFileSelect(selectPath);
} }
public static void EGFileSave(this Node self, string filePath, Action<string> selectPath, string title = "Save a file") public static void EGFileSave(this Node self, string filePath, Action<string> selectPath, string title = "Save a file")
{ {
EGodotFileDialog fileDialog = self.SingletoneNode<EGodotFileDialog>("FileDialog"); EGodotFileDialog fileDialog = self.PopupNode<EGodotFileDialog>("FileDialog");
fileDialog.Title = title; fileDialog.Title = title;
fileDialog.RootSubfolder = filePath; fileDialog.RootSubfolder = filePath;
fileDialog.PopupCentered();
fileDialog.InitSaveFileSelect(selectPath); fileDialog.InitSaveFileSelect(selectPath);
} }
public static void EGDocumentOpen(this Node self, string filePath, Action<string> selectPath, string title = "FileSelect") public static void EGDocumentOpen(this Node self, string filePath, Action<string> selectPath, string title = "FileSelect")
{ {
EGodotFileDialog fileDialog = self.SingletoneNode<EGodotFileDialog>("FileDialog"); EGodotFileDialog fileDialog = self.PopupNode<EGodotFileDialog>("FileDialog");
fileDialog.Title = title; fileDialog.Title = title;
fileDialog.RootSubfolder = filePath; fileDialog.RootSubfolder = filePath;
fileDialog.PopupCentered();
fileDialog.InitDirSelect(selectPath); fileDialog.InitDirSelect(selectPath);
} }
} }

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

@ -95,7 +95,7 @@ namespace EGFramework.UI
{ {
public static EGodotEditDialog EGEditDialog(this Node self, Dictionary<string, object> data, Action<Dictionary<string, object>> onDataEdit, string title = "Edit") 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"); EGodotEditDialog editDialog = self.SingletoneNode<EGodotEditDialog>("Edit");
editDialog.InitDialog(data, onDataEdit, title); editDialog.InitDialog(data, onDataEdit, title);
editDialog.PopupCentered(); editDialog.PopupCentered();
return editDialog; return editDialog;

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

@ -13,11 +13,28 @@ namespace EGFramework{
public class EGSingletonNode : IEGFramework, IModule public class EGSingletonNode : IEGFramework, IModule
{ {
public IOCContainer NodeContainer = new IOCContainer(); public IOCContainer NodeContainer = new IOCContainer();
public Queue<Window> WindowCache = new Queue<Window>();
public Window CurrentWindow { set; get; }
public void Init() public void Init()
{ {
} }
public void ReturnToLastWindow()
{
if (CurrentWindow != null && !CurrentWindow.Visible)
{
GD.Print("-----");
if (this.WindowCache.Count > 0)
{
this.CurrentWindow.VisibilityChanged -= ReturnToLastWindow;
this.CurrentWindow.Hide();
this.CurrentWindow = this.WindowCache.Dequeue();
this.CurrentWindow?.PopupCentered();
}
}
}
public IArchitecture GetArchitecture() public IArchitecture GetArchitecture()
{ {
return EGArchitectureImplement.Interface; return EGArchitectureImplement.Interface;
@ -27,21 +44,23 @@ namespace EGFramework{
public static class EGCanCreateNodeExtension public static class EGCanCreateNodeExtension
{ {
public static TNode CreateNode<TNode>(this Node self) where TNode : Node,new(){ public static TNode CreateNode<TNode>(this Node self) where TNode : Node, new()
{
TNode nodeData = new TNode(); TNode nodeData = new TNode();
nodeData.Name = typeof(TNode).Name; nodeData.Name = typeof(TNode).Name;
self.AddChild(nodeData); self.AddChild(nodeData);
return nodeData; return nodeData;
} }
public static TNode CreateNode<TNode>(this Node self,string name) where TNode : Node,new(){ public static TNode CreateNode<TNode>(this Node self, string name) where TNode : Node, new()
{
TNode nodeData = new TNode(); TNode nodeData = new TNode();
nodeData.Name = name; nodeData.Name = name;
self.AddChild(nodeData); self.AddChild(nodeData);
return nodeData; return nodeData;
} }
public static TNode SingletoneNode<TNode>(this Node self) where TNode : Node, new() public static TNode SingletoneNode<TNode>(this Node self, string name) where TNode : Node, new()
{ {
TNode nodeData; TNode nodeData;
if (EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Get<TNode>() != null) if (EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Get<TNode>() != null)
@ -53,22 +72,41 @@ namespace EGFramework{
nodeData = self.GetTree().Root.CreateNode<TNode>(); nodeData = self.GetTree().Root.CreateNode<TNode>();
EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Register(nodeData); EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Register(nodeData);
} }
nodeData.Name = typeof(TNode).Name; nodeData.Name = name;
return nodeData; return nodeData;
} }
public static TNode SingletoneNode<TNode>(this Node self,string name) where TNode : Node, new()
public static TWindowNode PopupNode<TWindowNode>(this Node self, string name) where TWindowNode : Window, new()
{ {
TNode nodeData; TWindowNode nodeData;
if (EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Get<TNode>() != null) EGSingletonNode singletonNode = EGArchitectureImplement.Interface.GetModule<EGSingletonNode>();
if (singletonNode.NodeContainer.Get<TWindowNode>() != null)
{ {
nodeData = EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Get<TNode>(); nodeData = singletonNode.NodeContainer.Get<TWindowNode>();
} }
else else
{ {
nodeData = self.GetTree().Root.CreateNode<TNode>(); nodeData = self.GetTree().Root.CreateNode<TWindowNode>();
EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Register(nodeData); singletonNode.NodeContainer.Register(nodeData);
} }
singletonNode.WindowCache.Enqueue(nodeData);
nodeData.Name = name; nodeData.Name = name;
// nodeData.CloseRequested += () =>
// {
// if (!nodeData.Visible)
// {
// GD.Print("-----");
// if (singletonNode.WindowCache.Count > 0)
// {
// singletonNode.CurrentWindow = singletonNode.WindowCache.Dequeue();
// singletonNode.CurrentWindow?.PopupCentered();
// }
// }
// };
singletonNode.CurrentWindow?.Hide();
nodeData.PopupCentered();
singletonNode.CurrentWindow = nodeData;
// nodeData.VisibilityChanged += singletonNode.ReturnToLastWindow;
return nodeData; return nodeData;
} }

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

@ -125,8 +125,12 @@ namespace EGFramework.UI
ParamOperate.Name = "SelectBtn"; ParamOperate.Name = "SelectBtn";
ParamOperate.Text = "Select file"; ParamOperate.Text = "Select file";
ParamOperate.SizeFlagsHorizontal = SizeFlags.ExpandFill; ParamOperate.SizeFlagsHorizontal = SizeFlags.ExpandFill;
ParamOperate.Pressed += () => { ParamOperate.Pressed += () =>
this.EGFileOpen("res://", str => { ParamReadOnly.Text = str; }); {
this.EGFileOpen("res://", str =>
{
ParamReadOnly.Text = str;
});
}; };
// ParamOperate.Pressed += // ParamOperate.Pressed +=
this.AddChild(ParamOperate); this.AddChild(ParamOperate);

Loading…
Cancel
Save