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. 27
      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 @@ -14,46 +14,33 @@ namespace EGFramework.UI
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.DialogText = alertMsg;
confirmDialog.PopupCentered();
confirmDialog.Connect("confirmed", Callable.From(() =>
{
callback(true);
}));
confirmDialog.Connect("canceled", Callable.From(() =>
{
callback(false);
}));
confirmDialog.Init(callback);
}
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 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>(selectPath));
// }
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);
}));
}
// 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>(selectPath));
// }
}
}

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

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

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

@ -7,5 +7,7 @@ namespace EGFramework.UI @@ -7,5 +7,7 @@ namespace EGFramework.UI
{
public IEGSaveData SaveData { set; get; }
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 @@ -101,7 +101,7 @@ namespace EGFramework.UI
InitPageData();
}
public void InitPageData()
public virtual void InitPageData()
{
if (PageAdapter.CurrentPage <= 1)
{
@ -122,6 +122,15 @@ namespace EGFramework.UI @@ -122,6 +122,15 @@ namespace EGFramework.UI
{
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()
@ -298,6 +307,7 @@ namespace EGFramework.UI @@ -298,6 +307,7 @@ namespace EGFramework.UI
{
return this.CurrentPage == MaxPage;
}
}
}

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

@ -31,12 +31,14 @@ namespace EGFramework.UI{ @@ -31,12 +31,14 @@ namespace EGFramework.UI{
Delete.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
Operate.AddChild(Delete);
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);
}
public void OnEdit(){
if(Data == null){
return ;
public void OnEdit()
{
if (Data == null)
{
return;
}
OnModify.Invoke(Data);
}
@ -56,5 +58,22 @@ namespace EGFramework.UI{ @@ -56,5 +58,22 @@ namespace EGFramework.UI{
base.RefreshData(data);
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