Skip to content

Commit 9bb858c

Browse files
committed
Merge pull request godotengine#92460 from bruvzg/adlg_cancel_conf
Fix duplicate AcceptDialog cancel/confirm events.
2 parents 21810ca + 3e691e0 commit 9bb858c

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

scene/gui/dialogs.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void AcceptDialog::_input_from_window(const Ref<InputEvent> &p_event) {
4747
}
4848

4949
void AcceptDialog::_parent_focused() {
50-
if (!is_exclusive() && get_flag(FLAG_POPUP)) {
50+
if (popped_up && !is_exclusive() && get_flag(FLAG_POPUP)) {
5151
_cancel_pressed();
5252
}
5353
}
@@ -71,13 +71,22 @@ void AcceptDialog::_notification(int p_what) {
7171
parent_visible->connect(SceneStringName(focus_entered), callable_mp(this, &AcceptDialog::_parent_focused));
7272
}
7373
} else {
74+
popped_up = false;
7475
if (parent_visible) {
7576
parent_visible->disconnect(SceneStringName(focus_entered), callable_mp(this, &AcceptDialog::_parent_focused));
7677
parent_visible = nullptr;
7778
}
7879
}
7980
} break;
8081

82+
case NOTIFICATION_WM_WINDOW_FOCUS_IN: {
83+
if (!is_in_edited_scene_root()) {
84+
if (has_focus()) {
85+
popped_up = true;
86+
}
87+
}
88+
} break;
89+
8190
case NOTIFICATION_THEME_CHANGED: {
8291
bg_panel->add_theme_style_override("panel", theme_cache.panel_style);
8392

@@ -114,8 +123,14 @@ void AcceptDialog::_text_submitted(const String &p_text) {
114123
_ok_pressed();
115124
}
116125

126+
void AcceptDialog::_post_popup() {
127+
Window::_post_popup();
128+
popped_up = true;
129+
}
130+
117131
void AcceptDialog::_ok_pressed() {
118132
if (hide_on_ok) {
133+
popped_up = false;
119134
set_visible(false);
120135
}
121136
ok_pressed();
@@ -124,6 +139,7 @@ void AcceptDialog::_ok_pressed() {
124139
}
125140

126141
void AcceptDialog::_cancel_pressed() {
142+
popped_up = false;
127143
Window *parent_window = parent_visible;
128144
if (parent_visible) {
129145
parent_visible->disconnect(SceneStringName(focus_entered), callable_mp(this, &AcceptDialog::_parent_focused));

scene/gui/dialogs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class AcceptDialog : public Window {
5151
HBoxContainer *buttons_hbox = nullptr;
5252
Button *ok_button = nullptr;
5353

54+
bool popped_up = false;
5455
bool hide_on_ok = true;
5556
bool close_on_escape = true;
5657

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

7678
void _notification(int p_what);
7779
static void _bind_methods();

0 commit comments

Comments
 (0)