Browse Source

fix confirmation bugs

master
jkpete 2 months ago
parent
commit
b943c4bba8
  1. 57
      addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotBasicDialog.cs
  2. 20
      addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotConfirmationDialog.cs
  3. 4
      addons/EGFramework/Module/GenerateTools/Templete/Godot/EGCreate.cs
  4. 2
      addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotSaveTable.cs
  5. 12
      addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotTable.cs
  6. 25
      addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotTableRowData.cs

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

@ -14,46 +14,33 @@ namespace EGFramework.UI
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")
{ {
ConfirmationDialog confirmDialog = self.SingletoneNode<ConfirmationDialog>("ConfirmDialog"); EGodotConfirmationDialog confirmDialog = self.SingletoneNode<EGodotConfirmationDialog>("ConfirmDialog");
confirmDialog.Title = title; confirmDialog.Title = title;
confirmDialog.DialogText = alertMsg; confirmDialog.DialogText = alertMsg;
confirmDialog.PopupCentered(); confirmDialog.PopupCentered();
confirmDialog.Connect("confirmed", Callable.From(() => confirmDialog.Init(callback);
{
callback(true);
}));
confirmDialog.Connect("canceled", Callable.From(() =>
{
callback(false);
}));
} }
public static void EGFileSingleSelect(this Node self, string filePath, Action<string> selectPath, string title = "FileSelect") // public static void EGFileSingleSelect(this Node self, string filePath, Action<string> selectPath, string title = "FileSelect")
{ // {
FileDialog fileDialog = self.SingletoneNode<FileDialog>("FileDialog"); // FileDialog fileDialog = self.SingletoneNode<FileDialog>("FileDialog");
fileDialog.Title = title; // fileDialog.Title = title;
fileDialog.Size = new Vector2I(480, 320); // fileDialog.Size = new Vector2I(480, 320);
fileDialog.FileMode = FileDialog.FileModeEnum.OpenFile; // fileDialog.FileMode = FileDialog.FileModeEnum.OpenFile;
fileDialog.RootSubfolder = filePath; // fileDialog.RootSubfolder = filePath;
fileDialog.PopupCentered(); // fileDialog.PopupCentered();
fileDialog.Connect("file_selected", Callable.From<string>(path => // fileDialog.Connect("file_selected", Callable.From<string>(selectPath));
{ // }
selectPath(path);
}));
}
public static void EGDocumentSelect(this Node self, string filePath, Action<string> selectPath, string title = "FileSelect") // public static void EGDocumentSelect(this Node self, string filePath, Action<string> selectPath, string title = "FileSelect")
{ // {
FileDialog fileDialog = self.SingletoneNode<FileDialog>("FileDialog"); // FileDialog fileDialog = self.SingletoneNode<FileDialog>("FileDialog");
fileDialog.Title = title; // fileDialog.Title = title;
fileDialog.Size = new Vector2I(480, 320); // fileDialog.Size = new Vector2I(480, 320);
fileDialog.FileMode = FileDialog.FileModeEnum.OpenDir; // fileDialog.FileMode = FileDialog.FileModeEnum.OpenDir;
fileDialog.RootSubfolder = filePath; // fileDialog.RootSubfolder = filePath;
fileDialog.PopupCentered(); // fileDialog.PopupCentered();
fileDialog.Connect("file_selected", Callable.From<string>(path => // fileDialog.Connect("file_selected", Callable.From<string>(selectPath));
{ // }
selectPath(path);
}));
}
} }
} }

20
addons/EGFramework/Module/GenerateTools/Templete/Godot/Dialog/EGodotConfirmationDialog.cs

@ -0,0 +1,20 @@
using System;
using Godot;
namespace EGFramework.UI {
public partial class EGodotConfirmationDialog : ConfirmationDialog, IEGFramework
{
private EasyEventOnce<bool> OnConfirm { set; get; } = new EasyEventOnce<bool>();
private bool IsInit { set; get; } = false;
public void Init(Action<bool> callback)
{
OnConfirm.Register(callback);
if (!IsInit)
{
this.Confirmed += () => OnConfirm.Invoke(true);
this.Canceled += () => OnConfirm.Invoke(false);
IsInit = true;
}
}
}
}

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

@ -50,7 +50,7 @@ namespace EGFramework{
} }
else else
{ {
nodeData = self.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 = typeof(TNode).Name;
@ -65,7 +65,7 @@ namespace EGFramework{
} }
else else
{ {
nodeData = self.CreateNode<TNode>(); nodeData = self.GetTree().Root.CreateNode<TNode>();
EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Register(nodeData); EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Register(nodeData);
} }
nodeData.Name = name; nodeData.Name = name;

2
addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotSaveTable.cs

@ -7,5 +7,7 @@ namespace EGFramework.UI
{ {
public IEGSaveData SaveData { set; get; } public IEGSaveData SaveData { set; get; }
public Dictionary<string, string> TitleList { set; get; } = new Dictionary<string, string>(); public Dictionary<string, string> TitleList { set; get; } = new Dictionary<string, string>();
} }
} }

12
addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotTable.cs

@ -101,7 +101,7 @@ namespace EGFramework.UI
InitPageData(); InitPageData();
} }
public void InitPageData() public virtual void InitPageData()
{ {
if (PageAdapter.CurrentPage <= 1) if (PageAdapter.CurrentPage <= 1)
{ {
@ -122,6 +122,15 @@ namespace EGFramework.UI
{ {
this.EGEditDialog(data, rowData.OnDataEdit, "Modify"); this.EGEditDialog(data, rowData.OnDataEdit, "Modify");
}); });
rowData.OnDelete.Register(() =>
{
GD.Print("Delete : " + rowData.GetData()["Name"]);
this.TableData.Remove(rowData.GetData());
PageAdapter.DataLength--;
PageAdapter.Reload(PageAdapter.DataLength, PageLimit);
InitPageData();
OnPageChanged.Invoke();
});
} }
} }
public void InitPageMenu() public void InitPageMenu()
@ -298,6 +307,7 @@ namespace EGFramework.UI
{ {
return this.CurrentPage == MaxPage; return this.CurrentPage == MaxPage;
} }
} }
} }

25
addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotTableRowData.cs

@ -31,11 +31,13 @@ namespace EGFramework.UI{
Delete.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill; Delete.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
Operate.AddChild(Delete); Operate.AddChild(Delete);
Modify.Connect("pressed", Callable.From(OnEdit)); Modify.Connect("pressed", Callable.From(OnEdit));
Delete.Connect("pressed", Callable.From(OnDelete.Invoke)); Delete.Connect("pressed", Callable.From(OnDeleteSelf));
this.CustomMinimumSize = new Vector2(0, 32); this.CustomMinimumSize = new Vector2(0, 32);
} }
public void OnEdit(){ public void OnEdit()
if(Data == null){ {
if (Data == null)
{
return; return;
} }
OnModify.Invoke(Data); OnModify.Invoke(Data);
@ -56,5 +58,22 @@ namespace EGFramework.UI{
base.RefreshData(data); base.RefreshData(data);
Operate.ToEnd(); Operate.ToEnd();
} }
public void OnDeleteSelf()
{
this.EGConfirm("Delete this data? this operate cannot be canceled.", e =>
{
if (e)
{
OnDelete.Invoke();
}
}, "Delete");
}
public override void _ExitTree()
{
Modify.Disconnect("pressed", Callable.From(OnEdit));
Delete.Disconnect("pressed", Callable.From(OnDeleteSelf));
base._ExitTree();
}
} }
} }
Loading…
Cancel
Save