diff --git a/scene/2d/touch_screen_button.cpp b/scene/2d/touch_screen_button.cpp index 86577c5e0..0b8d520a4 100644 --- a/scene/2d/touch_screen_button.cpp +++ b/scene/2d/touch_screen_button.cpp @@ -36,9 +36,19 @@ #include "scene/resources/bit_map.h" #include "scene/resources/rectangle_shape_2d.h" #include "scene/resources/texture.h" +#include "scene/scene_string_names.h" void TouchScreenButton::set_texture(const Ref &p_texture) { + if (texture == p_texture) { + return; + } + if (texture.is_valid()) { + texture->disconnect(SceneStringNames::get_singleton()->changed, this, "update"); + } texture = p_texture; + if (texture.is_valid()) { + texture->connect(SceneStringNames::get_singleton()->changed, this, "update", varray(), CONNECT_REFERENCE_COUNTED); + } update(); } @@ -47,7 +57,16 @@ Ref TouchScreenButton::get_texture() const { } void TouchScreenButton::set_texture_pressed(const Ref &p_texture_pressed) { + if (texture_pressed == p_texture_pressed) { + return; + } + if (texture_pressed.is_valid()) { + texture_pressed->disconnect(SceneStringNames::get_singleton()->changed, this, "update"); + } texture_pressed = p_texture_pressed; + if (texture_pressed.is_valid()) { + texture_pressed->connect(SceneStringNames::get_singleton()->changed, this, "update", varray(), CONNECT_REFERENCE_COUNTED); + } update(); } @@ -64,16 +83,16 @@ Ref TouchScreenButton::get_bitmask() const { } void TouchScreenButton::set_shape(const Ref &p_shape) { - if (shape.is_valid()) { - shape->disconnect("changed", this, "update"); + if (shape == p_shape) { + return; + } + if (shape.is_valid()) { + shape->disconnect(SceneStringNames::get_singleton()->changed, this, "update"); } - shape = p_shape; - if (shape.is_valid()) { - shape->connect("changed", this, "update"); + shape->connect(SceneStringNames::get_singleton()->changed, this, "update"); } - update(); }