diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2020-02-27 22:49:16 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2020-02-28 14:24:09 +0100 |
commit | 09a6a2d8f83473b4893b4dd04ff31972e267d5d6 (patch) | |
tree | 1cacdc4c74f9cc941f214b5cb7a488f5e6875e2c /scene/gui | |
parent | b8f08b42e7ca111a910f04475cb4d18435a17de1 (diff) |
Signals: Port more uses of connect_compat
Those were problematic as they call a method of their parent class,
but callable_mp does not allow that unless it's public.
To solve it, we declare a local class that calls the parent class'
method, which now needs to be protected to be accessible in the
derived class.
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/dialogs.cpp | 18 | ||||
-rw-r--r-- | scene/gui/dialogs.h | 11 |
2 files changed, 18 insertions, 11 deletions
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index 0237be8ad6..6cadd0a63e 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -338,8 +338,6 @@ void WindowDialog::_bind_methods() { ClassDB::bind_method(D_METHOD("get_resizable"), &WindowDialog::get_resizable); ClassDB::bind_method(D_METHOD("get_close_button"), &WindowDialog::get_close_button); - ClassDB::bind_method(D_METHOD("_closed"), &WindowDialog::_closed); // Still used by some connect_compat. - ADD_PROPERTY(PropertyInfo(Variant::STRING, "window_title", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT_INTL), "set_title", "get_title"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "resizable", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT_INTL), "set_resizable", "get_resizable"); } @@ -398,7 +396,7 @@ void AcceptDialog::_notification(int p_what) { } } -void AcceptDialog::_builtin_text_entered(const String &p_text) { +void AcceptDialog::_text_entered(const String &p_text) { _ok_pressed(); } @@ -410,11 +408,18 @@ void AcceptDialog::_ok_pressed() { ok_pressed(); emit_signal("confirmed"); } + void AcceptDialog::_close_pressed() { cancel_pressed(); } +// FIXME: This is redundant with _closed_pressed, but there's a slight behavior +// change (WindowDialog's _closed() also calls hide()) which should be assessed. +void AcceptDialog::_on_close_pressed() { + _closed(); // From WindowDialog. +} + String AcceptDialog::get_text() const { return label->get_text(); @@ -449,7 +454,7 @@ void AcceptDialog::register_text_enter(Node *p_line_edit) { ERR_FAIL_NULL(p_line_edit); LineEdit *line_edit = Object::cast_to<LineEdit>(p_line_edit); if (line_edit) - line_edit->connect("text_entered", callable_mp(this, &AcceptDialog::_builtin_text_entered)); + line_edit->connect("text_entered", callable_mp(this, &AcceptDialog::_text_entered)); } void AcceptDialog::_update_child_rects() { @@ -546,7 +551,7 @@ Button *AcceptDialog::add_cancel(const String &p_cancel) { if (p_cancel == "") c = RTR("Cancel"); Button *b = swap_ok_cancel ? add_button(c, true) : add_button(c); - b->connect_compat("pressed", this, "_closed"); + b->connect("pressed", callable_mp(this, &AcceptDialog::_on_close_pressed)); return b; } @@ -564,9 +569,6 @@ void AcceptDialog::_bind_methods() { ClassDB::bind_method(D_METHOD("set_autowrap", "autowrap"), &AcceptDialog::set_autowrap); ClassDB::bind_method(D_METHOD("has_autowrap"), &AcceptDialog::has_autowrap); - ClassDB::bind_method(D_METHOD("_ok"), &AcceptDialog::_ok_pressed); // Still used by some connect_compat. - ClassDB::bind_method(D_METHOD("_builtin_text_entered"), &AcceptDialog::_builtin_text_entered); // Still used by some connect_compat. - ADD_SIGNAL(MethodInfo("confirmed")); ADD_SIGNAL(MethodInfo("custom_action", PropertyInfo(Variant::STRING_NAME, "action"))); diff --git a/scene/gui/dialogs.h b/scene/gui/dialogs.h index b6381e98b4..c474f7849d 100644 --- a/scene/gui/dialogs.h +++ b/scene/gui/dialogs.h @@ -64,7 +64,6 @@ class WindowDialog : public Popup { #endif void _gui_input(const Ref<InputEvent> &p_event); - void _closed(); int _drag_hit_test(const Point2 &pos) const; protected: @@ -75,6 +74,9 @@ protected: void _notification(int p_what); static void _bind_methods(); + // Not private since used by derived classes signal. + void _closed(); + public: TextureButton *get_close_button(); @@ -113,9 +115,7 @@ class AcceptDialog : public WindowDialog { bool hide_on_ok; void _custom_action(const String &p_action); - void _ok_pressed(); void _close_pressed(); - void _builtin_text_entered(const String &p_text); void _update_child_rects(); static bool swap_ok_cancel; @@ -128,6 +128,11 @@ protected: virtual void cancel_pressed() {} virtual void custom_action(const String &) {} + // Not private since used by derived classes signal. + void _text_entered(const String &p_text); + void _ok_pressed(); + void _on_close_pressed(); + public: Size2 get_minimum_size() const; |