Fix duplicate AcceptDialog cancel/confirm events.

This commit is contained in:
bruvzg 2024-05-28 09:41:04 +03:00
parent be56cab58c
commit 3e691e026b
No known key found for this signature in database
GPG Key ID: 7960FCF39844EC38
2 changed files with 19 additions and 1 deletions

View File

@ -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();
}
}
@ -71,6 +71,7 @@ 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;
@ -78,6 +79,14 @@ void AcceptDialog::_notification(int p_what) {
}
} 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);
@ -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();
@ -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));

View File

@ -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;
@ -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();