Godot Version
v4.3.stable.mono.official.77dcf97d8
Question
I have a C# script on a node2d which opens a PopupPanel inherited class called SavePopup. SavePopup takes a callback, which opens a FileDialog. This FileDialog doesn’t work properly. Although the dialog opens, the save, cancel, and X buttons are all unclickable, and the dialog cannot be closed. When the save function is called directly from the main window, it works without issue.
Code to open popup:
[Export]
private SavePopup saveConfirmation;
…
saveConfirmation.display(saveDialogConfirmation);
Callback function:
private void saveDialogConfirmation(bool saveFirst)
{
if (saveFirst)
{
GD.Print(“Let’s save first…”);
if (Save())
{
GD.Print(“Save done, let’s leave!”);
GetTree().Quit();
}
}
else
{
GD.Print(“I’m out of here…”);
GetTree().Quit();
}
}
Save Function snippet:
dialog = new FileDialog();
dialog.Access = FileDialog.AccessEnum.Filesystem;
dialog.UseNativeDialog = true;
AddChild(dialog);
dialog.FileMode = FileDialog.FileModeEnum.SaveFile;
dialog.ClearFilters();
dialog.AddFilter(“All Files”, “*”);
dialog.Show();
string fileName = dialog.CurrentFile;
if (fileName == null || fileName == “”)
{
GD.Print(“Save Cancelled!”);
return false;
}
…actual save code…
return true;
Popup code:
public partial class SavePopup : PopupPanel
{public delegate void savePopupCallback(bool save); private savePopupCallback callback = delegate { }; public void display(savePopupCallback func) { callback = func; Show(); } public void cancelButtonPressed() { Hide(); } public void saveButtonPressed() { callback.Invoke(true); Hide(); }
}