From 19afaa0203fbe5638b9be35f7e43bdba3b8a3641 Mon Sep 17 00:00:00 2001 From: Yuri Roubinsky Date: Sat, 12 Jun 2021 07:44:38 +0300 Subject: [PATCH] Fixed a bunch of connection errors in TextureEditorPlugin --- doc/classes/Sprite3D.xml | 5 +++++ doc/classes/StyleBoxTexture.xml | 7 ------- editor/plugins/texture_region_editor_plugin.cpp | 17 +++++++++++++---- scene/2d/mesh_instance_2d.cpp | 3 ++- scene/2d/multimesh_instance_2d.cpp | 3 ++- scene/2d/sprite_2d.cpp | 2 +- scene/3d/sprite_3d.cpp | 2 ++ scene/gui/nine_patch_rect.cpp | 3 ++- scene/resources/style_box.cpp | 3 --- scene/scene_string_names.cpp | 1 + scene/scene_string_names.h | 1 + 11 files changed, 29 insertions(+), 18 deletions(-) diff --git a/doc/classes/Sprite3D.xml b/doc/classes/Sprite3D.xml index a7d61a6bab2..8c4b9e7d10d 100644 --- a/doc/classes/Sprite3D.xml +++ b/doc/classes/Sprite3D.xml @@ -39,6 +39,11 @@ Emitted when the [member frame] changes. + + + Emitted when the [member texture] changes. + + diff --git a/doc/classes/StyleBoxTexture.xml b/doc/classes/StyleBoxTexture.xml index 895d0c357dd..f4a1f1f01d6 100644 --- a/doc/classes/StyleBoxTexture.xml +++ b/doc/classes/StyleBoxTexture.xml @@ -127,13 +127,6 @@ The texture to use when drawing this style box. - - - - Emitted when the stylebox's texture is changed. - - - Stretch the stylebox's texture. This results in visible distortion unless the texture size matches the stylebox's size perfectly. diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index 95261606744..686ff0f9ef8 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -863,13 +863,13 @@ Sprite2D *TextureRegionEditor::get_sprite() { void TextureRegionEditor::edit(Object *p_obj) { if (node_sprite) { - node_sprite->disconnect("changed", callable_mp(this, &TextureRegionEditor::_texture_changed)); + node_sprite->disconnect("texture_changed", callable_mp(this, &TextureRegionEditor::_texture_changed)); } if (node_sprite_3d) { - node_sprite_3d->disconnect("changed", callable_mp(this, &TextureRegionEditor::_texture_changed)); + node_sprite_3d->disconnect("texture_changed", callable_mp(this, &TextureRegionEditor::_texture_changed)); } if (node_ninepatch) { - node_ninepatch->disconnect("changed", callable_mp(this, &TextureRegionEditor::_texture_changed)); + node_ninepatch->disconnect("texture_changed", callable_mp(this, &TextureRegionEditor::_texture_changed)); } if (obj_styleBox.is_valid()) { obj_styleBox->disconnect("changed", callable_mp(this, &TextureRegionEditor::_texture_changed)); @@ -881,13 +881,22 @@ void TextureRegionEditor::edit(Object *p_obj) { node_sprite = Object::cast_to(p_obj); node_sprite_3d = Object::cast_to(p_obj); node_ninepatch = Object::cast_to(p_obj); + + bool is_resource = false; if (Object::cast_to(p_obj)) { obj_styleBox = Ref(Object::cast_to(p_obj)); + is_resource = true; } if (Object::cast_to(p_obj)) { atlas_tex = Ref(Object::cast_to(p_obj)); + is_resource = true; + } + + if (is_resource) { + p_obj->connect("changed", callable_mp(this, &TextureRegionEditor::_texture_changed)); + } else { + p_obj->connect("texture_changed", callable_mp(this, &TextureRegionEditor::_texture_changed)); } - p_obj->connect("changed", callable_mp(this, &TextureRegionEditor::_texture_changed)); _edit_region(); } else { node_sprite = nullptr; diff --git a/scene/2d/mesh_instance_2d.cpp b/scene/2d/mesh_instance_2d.cpp index b7a00281997..15008390b76 100644 --- a/scene/2d/mesh_instance_2d.cpp +++ b/scene/2d/mesh_instance_2d.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "mesh_instance_2d.h" +#include "scene/scene_string_names.h" void MeshInstance2D::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { @@ -70,7 +71,7 @@ void MeshInstance2D::set_texture(const Ref &p_texture) { } texture = p_texture; update(); - emit_signal("texture_changed"); + emit_signal(SceneStringNames::get_singleton()->texture_changed); } void MeshInstance2D::set_normal_map(const Ref &p_texture) { diff --git a/scene/2d/multimesh_instance_2d.cpp b/scene/2d/multimesh_instance_2d.cpp index 72a899370e2..1bff2f337de 100644 --- a/scene/2d/multimesh_instance_2d.cpp +++ b/scene/2d/multimesh_instance_2d.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "multimesh_instance_2d.h" +#include "scene/scene_string_names.h" void MultiMeshInstance2D::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { @@ -70,7 +71,7 @@ void MultiMeshInstance2D::set_texture(const Ref &p_texture) { } texture = p_texture; update(); - emit_signal("texture_changed"); + emit_signal(SceneStringNames::get_singleton()->texture_changed); } Ref MultiMeshInstance2D::get_texture() const { diff --git a/scene/2d/sprite_2d.cpp b/scene/2d/sprite_2d.cpp index 20169b10751..40e0f4523f0 100644 --- a/scene/2d/sprite_2d.cpp +++ b/scene/2d/sprite_2d.cpp @@ -153,7 +153,7 @@ void Sprite2D::set_texture(const Ref &p_texture) { } update(); - emit_signal("texture_changed"); + emit_signal(SceneStringNames::get_singleton()->texture_changed); item_rect_changed(); } diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp index be474e82e01..9ec461d9737 100644 --- a/scene/3d/sprite_3d.cpp +++ b/scene/3d/sprite_3d.cpp @@ -505,6 +505,7 @@ void Sprite3D::set_texture(const Ref &p_texture) { texture->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &Sprite3D::_texture_changed)); } _queue_update(); + emit_signal(SceneStringNames::get_singleton()->texture_changed); } Ref Sprite3D::get_texture() const { @@ -663,6 +664,7 @@ void Sprite3D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::RECT2, "region_rect"), "set_region_rect", "get_region_rect"); ADD_SIGNAL(MethodInfo("frame_changed")); + ADD_SIGNAL(MethodInfo("texture_changed")); } Sprite3D::Sprite3D() { diff --git a/scene/gui/nine_patch_rect.cpp b/scene/gui/nine_patch_rect.cpp index 29a38ad5e38..8bf25ac9154 100644 --- a/scene/gui/nine_patch_rect.cpp +++ b/scene/gui/nine_patch_rect.cpp @@ -30,6 +30,7 @@ #include "nine_patch_rect.h" +#include "scene/scene_string_names.h" #include "servers/rendering_server.h" void NinePatchRect::_notification(int p_what) { @@ -97,7 +98,7 @@ void NinePatchRect::set_texture(const Ref &p_tex) { texture->set_flags(texture->get_flags()&(~Texture::FLAG_REPEAT)); //remove repeat from texture, it looks bad in sprites */ minimum_size_changed(); - emit_signal("texture_changed"); + emit_signal(SceneStringNames::get_singleton()->texture_changed); } Ref NinePatchRect::get_texture() const { diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp index 2159f1bc972..87371224e07 100644 --- a/scene/resources/style_box.cpp +++ b/scene/resources/style_box.cpp @@ -121,7 +121,6 @@ void StyleBoxTexture::set_texture(Ref p_texture) { } else { region_rect = Rect2(Point2(), texture->get_size()); } - emit_signal("texture_changed"); emit_changed(); } @@ -285,8 +284,6 @@ void StyleBoxTexture::_bind_methods() { ClassDB::bind_method(D_METHOD("set_v_axis_stretch_mode", "mode"), &StyleBoxTexture::set_v_axis_stretch_mode); ClassDB::bind_method(D_METHOD("get_v_axis_stretch_mode"), &StyleBoxTexture::get_v_axis_stretch_mode); - ADD_SIGNAL(MethodInfo("texture_changed")); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture"); ADD_PROPERTY(PropertyInfo(Variant::RECT2, "region_rect"), "set_region_rect", "get_region_rect"); ADD_GROUP("Margin", "margin_"); diff --git a/scene/scene_string_names.cpp b/scene/scene_string_names.cpp index 7575ccd5c3b..b3b1790b956 100644 --- a/scene/scene_string_names.cpp +++ b/scene/scene_string_names.cpp @@ -175,6 +175,7 @@ SceneStringNames::SceneStringNames() { _toggled = StaticCString::create("_toggled"); frame_changed = StaticCString::create("frame_changed"); + texture_changed = StaticCString::create("texture_changed"); playback_speed = StaticCString::create("playback/speed"); playback_active = StaticCString::create("playback/active"); diff --git a/scene/scene_string_names.h b/scene/scene_string_names.h index a5b489eddc6..377b8d7fbb1 100644 --- a/scene/scene_string_names.h +++ b/scene/scene_string_names.h @@ -184,6 +184,7 @@ public: StringName _mouse_exit; StringName frame_changed; + StringName texture_changed; StringName playback_speed; StringName playback_active;