Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate AcceptDialog cancel/confirm events. #92460

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion scene/gui/dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void AcceptDialog::_input_from_window(const Ref<InputEvent> &p_event) {
}

void AcceptDialog::_parent_focused() {
if (!is_exclusive() && get_flag(FLAG_POPUP)) {
if (popped_up && !is_exclusive() && get_flag(FLAG_POPUP)) {
_cancel_pressed();
}
}
Expand All @@ -71,13 +71,22 @@ void AcceptDialog::_notification(int p_what) {
parent_visible->connect(SceneStringName(focus_entered), callable_mp(this, &AcceptDialog::_parent_focused));
}
} else {
popped_up = false;
if (parent_visible) {
parent_visible->disconnect(SceneStringName(focus_entered), callable_mp(this, &AcceptDialog::_parent_focused));
parent_visible = nullptr;
}
}
} break;

case NOTIFICATION_WM_WINDOW_FOCUS_IN: {
if (!is_in_edited_scene_root()) {
if (has_focus()) {
popped_up = true;
}
}
} break;

case NOTIFICATION_THEME_CHANGED: {
bg_panel->add_theme_style_override("panel", theme_cache.panel_style);

Expand Down Expand Up @@ -114,8 +123,14 @@ void AcceptDialog::_text_submitted(const String &p_text) {
_ok_pressed();
}

void AcceptDialog::_post_popup() {
Window::_post_popup();
popped_up = true;
}

void AcceptDialog::_ok_pressed() {
if (hide_on_ok) {
popped_up = false;
set_visible(false);
}
ok_pressed();
Expand All @@ -124,6 +139,7 @@ void AcceptDialog::_ok_pressed() {
}

void AcceptDialog::_cancel_pressed() {
popped_up = false;
Window *parent_window = parent_visible;
if (parent_visible) {
parent_visible->disconnect(SceneStringName(focus_entered), callable_mp(this, &AcceptDialog::_parent_focused));
Expand Down
2 changes: 2 additions & 0 deletions scene/gui/dialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class AcceptDialog : public Window {
HBoxContainer *buttons_hbox = nullptr;
Button *ok_button = nullptr;

bool popped_up = false;
bool hide_on_ok = true;
bool close_on_escape = true;

Expand All @@ -72,6 +73,7 @@ class AcceptDialog : public Window {
protected:
virtual Size2 _get_contents_minimum_size() const override;
virtual void _input_from_window(const Ref<InputEvent> &p_event) override;
virtual void _post_popup() override;

void _notification(int p_what);
static void _bind_methods();
Expand Down
Loading