You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
Fix internal events not being delivered to some Window types
`AcceptDialog`, `Popup` and `PopupMenu` no longer subscribe to "window_input" signal, because that is only sent if it is not an internal signal. Instead they receive events in `_input_from_window`. They ensure that the event is also propagated to their super-function, just like previously the signals would be treated.
This commit is contained in:
@@ -42,6 +42,7 @@ void AcceptDialog::_input_from_window(const Ref<InputEvent> &p_event) {
|
|||||||
if (close_on_escape && p_event->is_action_pressed(SNAME("ui_cancel"), false, true)) {
|
if (close_on_escape && p_event->is_action_pressed(SNAME("ui_cancel"), false, true)) {
|
||||||
_cancel_pressed();
|
_cancel_pressed();
|
||||||
}
|
}
|
||||||
|
Window::_input_from_window(p_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AcceptDialog::_parent_focused() {
|
void AcceptDialog::_parent_focused() {
|
||||||
@@ -428,8 +429,6 @@ AcceptDialog::AcceptDialog() {
|
|||||||
ok_button->connect("pressed", callable_mp(this, &AcceptDialog::_ok_pressed));
|
ok_button->connect("pressed", callable_mp(this, &AcceptDialog::_ok_pressed));
|
||||||
|
|
||||||
set_title(TTRC("Alert!"));
|
set_title(TTRC("Alert!"));
|
||||||
|
|
||||||
connect("window_input", callable_mp(this, &AcceptDialog::_input_from_window));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AcceptDialog::~AcceptDialog() {
|
AcceptDialog::~AcceptDialog() {
|
||||||
|
|||||||
@@ -65,11 +65,11 @@ class AcceptDialog : public Window {
|
|||||||
|
|
||||||
static bool swap_cancel_ok;
|
static bool swap_cancel_ok;
|
||||||
|
|
||||||
void _input_from_window(const Ref<InputEvent> &p_event);
|
|
||||||
void _parent_focused();
|
void _parent_focused();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual Size2 _get_contents_minimum_size() const override;
|
virtual Size2 _get_contents_minimum_size() const override;
|
||||||
|
virtual void _input_from_window(const Ref<InputEvent> &p_event) override;
|
||||||
|
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ void Popup::_input_from_window(const Ref<InputEvent> &p_event) {
|
|||||||
if (get_flag(FLAG_POPUP) && p_event->is_action_pressed(SNAME("ui_cancel"), false, true)) {
|
if (get_flag(FLAG_POPUP) && p_event->is_action_pressed(SNAME("ui_cancel"), false, true)) {
|
||||||
_close_pressed();
|
_close_pressed();
|
||||||
}
|
}
|
||||||
|
Window::_input_from_window(p_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Popup::_initialize_visible_parents() {
|
void Popup::_initialize_visible_parents() {
|
||||||
@@ -204,8 +205,6 @@ Popup::Popup() {
|
|||||||
set_flag(FLAG_BORDERLESS, true);
|
set_flag(FLAG_BORDERLESS, true);
|
||||||
set_flag(FLAG_RESIZE_DISABLED, true);
|
set_flag(FLAG_RESIZE_DISABLED, true);
|
||||||
set_flag(FLAG_POPUP, true);
|
set_flag(FLAG_POPUP, true);
|
||||||
|
|
||||||
connect("window_input", callable_mp(this, &Popup::_input_from_window));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Popup::~Popup() {
|
Popup::~Popup() {
|
||||||
|
|||||||
@@ -47,14 +47,13 @@ class Popup : public Window {
|
|||||||
Ref<StyleBox> panel_style;
|
Ref<StyleBox> panel_style;
|
||||||
} theme_cache;
|
} theme_cache;
|
||||||
|
|
||||||
void _input_from_window(const Ref<InputEvent> &p_event);
|
|
||||||
|
|
||||||
void _initialize_visible_parents();
|
void _initialize_visible_parents();
|
||||||
void _deinitialize_visible_parents();
|
void _deinitialize_visible_parents();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void _close_pressed();
|
void _close_pressed();
|
||||||
virtual Rect2i _popup_adjust_rect() const override;
|
virtual Rect2i _popup_adjust_rect() const override;
|
||||||
|
virtual void _input_from_window(const Ref<InputEvent> &p_event) override;
|
||||||
|
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
void _validate_property(PropertyInfo &p_property) const;
|
void _validate_property(PropertyInfo &p_property) const;
|
||||||
|
|||||||
@@ -378,9 +378,16 @@ void PopupMenu::_submenu_timeout() {
|
|||||||
submenu_over = -1;
|
submenu_over = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PopupMenu::gui_input(const Ref<InputEvent> &p_event) {
|
void PopupMenu::_input_from_window(const Ref<InputEvent> &p_event) {
|
||||||
ERR_FAIL_COND(p_event.is_null());
|
if (p_event.is_valid()) {
|
||||||
|
_input_from_window_internal(p_event);
|
||||||
|
} else {
|
||||||
|
WARN_PRINT_ONCE("PopupMenu has received an invalid InputEvent. Consider filtering invalid events out.");
|
||||||
|
}
|
||||||
|
Popup::_input_from_window(p_event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PopupMenu::_input_from_window_internal(const Ref<InputEvent> &p_event) {
|
||||||
if (!items.is_empty()) {
|
if (!items.is_empty()) {
|
||||||
Input *input = Input::get_singleton();
|
Input *input = Input::get_singleton();
|
||||||
Ref<InputEventJoypadMotion> joypadmotion_event = p_event;
|
Ref<InputEventJoypadMotion> joypadmotion_event = p_event;
|
||||||
@@ -2799,8 +2806,6 @@ PopupMenu::PopupMenu() {
|
|||||||
scroll_container->add_child(control, false, INTERNAL_MODE_FRONT);
|
scroll_container->add_child(control, false, INTERNAL_MODE_FRONT);
|
||||||
control->connect("draw", callable_mp(this, &PopupMenu::_draw_items));
|
control->connect("draw", callable_mp(this, &PopupMenu::_draw_items));
|
||||||
|
|
||||||
connect("window_input", callable_mp(this, &PopupMenu::gui_input));
|
|
||||||
|
|
||||||
submenu_timer = memnew(Timer);
|
submenu_timer = memnew(Timer);
|
||||||
submenu_timer->set_wait_time(0.3);
|
submenu_timer->set_wait_time(0.3);
|
||||||
submenu_timer->set_one_shot(true);
|
submenu_timer->set_one_shot(true);
|
||||||
|
|||||||
@@ -112,7 +112,6 @@ class PopupMenu : public Popup {
|
|||||||
|
|
||||||
void _shape_item(int p_idx);
|
void _shape_item(int p_idx);
|
||||||
|
|
||||||
virtual void gui_input(const Ref<InputEvent> &p_event);
|
|
||||||
void _activate_submenu(int p_over, bool p_by_keyboard = false);
|
void _activate_submenu(int p_over, bool p_by_keyboard = false);
|
||||||
void _submenu_timeout();
|
void _submenu_timeout();
|
||||||
|
|
||||||
@@ -191,10 +190,12 @@ class PopupMenu : public Popup {
|
|||||||
void _minimum_lifetime_timeout();
|
void _minimum_lifetime_timeout();
|
||||||
void _close_pressed();
|
void _close_pressed();
|
||||||
void _menu_changed();
|
void _menu_changed();
|
||||||
|
void _input_from_window_internal(const Ref<InputEvent> &p_event);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void add_child_notify(Node *p_child) override;
|
virtual void add_child_notify(Node *p_child) override;
|
||||||
virtual void remove_child_notify(Node *p_child) override;
|
virtual void remove_child_notify(Node *p_child) override;
|
||||||
|
virtual void _input_from_window(const Ref<InputEvent> &p_event) override;
|
||||||
|
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
bool _set(const StringName &p_name, const Variant &p_value);
|
bool _set(const StringName &p_name, const Variant &p_value);
|
||||||
|
|||||||
@@ -1543,7 +1543,12 @@ void Window::_window_input(const Ref<InputEvent> &p_ev) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p_ev->get_device() != InputEvent::DEVICE_ID_INTERNAL) {
|
// If the event needs to be handled in a Window-derived class, then it should overwrite
|
||||||
|
// `_input_from_window` instead of subscribing to the `window_input` signal, because the signal
|
||||||
|
// filters out internal events.
|
||||||
|
_input_from_window(p_ev);
|
||||||
|
|
||||||
|
if (p_ev->get_device() != InputEvent::DEVICE_ID_INTERNAL && is_inside_tree()) {
|
||||||
emit_signal(SceneStringNames::get_singleton()->window_input, p_ev);
|
emit_signal(SceneStringNames::get_singleton()->window_input, p_ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -239,6 +239,7 @@ protected:
|
|||||||
virtual void _post_popup() {}
|
virtual void _post_popup() {}
|
||||||
|
|
||||||
virtual void _update_theme_item_cache();
|
virtual void _update_theme_item_cache();
|
||||||
|
virtual void _input_from_window(const Ref<InputEvent> &p_event) {}
|
||||||
|
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|||||||
Reference in New Issue
Block a user