From b648d3e1109bb029e60e05a4f924797c27b0681f Mon Sep 17 00:00:00 2001 From: Bojidar Marinov Date: Sat, 13 Jul 2019 21:55:32 +0300 Subject: [PATCH] Fix TextureRegionEditorPlugin popping up even when explicitly hidden Fixes #27468 --- .../plugins/texture_region_editor_plugin.cpp | 20 +++++++++++++++---- editor/plugins/texture_region_editor_plugin.h | 6 ++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index 8f58fbd6aba..cb48b5eaa50 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -1021,15 +1021,21 @@ bool TextureRegionEditorPlugin::handles(Object *p_object) const { return p_object->is_class("Sprite") || p_object->is_class("Sprite3D") || p_object->is_class("NinePatchRect") || p_object->is_class("StyleBoxTexture") || p_object->is_class("AtlasTexture"); } +void TextureRegionEditorPlugin::_editor_visiblity_changed() { + manually_hidden = !region_editor->is_visible_in_tree(); +} + void TextureRegionEditorPlugin::make_visible(bool p_visible) { if (p_visible) { texture_region_button->show(); - if (region_editor->is_stylebox() || region_editor->is_atlas_texture() || region_editor->is_ninepatch() || (region_editor->get_sprite() && region_editor->get_sprite()->is_region()) || (region_editor->get_sprite_3d() && region_editor->get_sprite_3d()->is_region()) || texture_region_button->is_pressed()) { + bool is_node_configured = region_editor->is_stylebox() || region_editor->is_atlas_texture() || region_editor->is_ninepatch() || (region_editor->get_sprite() && region_editor->get_sprite()->is_region()) || (region_editor->get_sprite_3d() && region_editor->get_sprite_3d()->is_region()); + if ((is_node_configured && !manually_hidden) || texture_region_button->is_pressed()) { editor->make_bottom_panel_item_visible(region_editor); } } else { if (region_editor->is_visible_in_tree()) { editor->hide_bottom_panel(); + manually_hidden = false; } texture_region_button->hide(); region_editor->edit(NULL); @@ -1076,12 +1082,18 @@ void TextureRegionEditorPlugin::set_state(const Dictionary &p_state) { } } -TextureRegionEditorPlugin::TextureRegionEditorPlugin(EditorNode *p_node) { - editor = p_node; - region_editor = memnew(TextureRegionEditor(p_node)); +void TextureRegionEditorPlugin::_bind_methods() { + ClassDB::bind_method(D_METHOD("_editor_visiblity_changed"), &TextureRegionEditorPlugin::_editor_visiblity_changed); +} +TextureRegionEditorPlugin::TextureRegionEditorPlugin(EditorNode *p_node) { + manually_hidden = false; + editor = p_node; + + region_editor = memnew(TextureRegionEditor(p_node)); region_editor->set_custom_minimum_size(Size2(0, 200) * EDSCALE); region_editor->hide(); + region_editor->connect("visibility_changed", this, "_editor_visiblity_changed"); texture_region_button = p_node->add_bottom_panel_item(TTR("TextureRegion"), region_editor); texture_region_button->hide(); diff --git a/editor/plugins/texture_region_editor_plugin.h b/editor/plugins/texture_region_editor_plugin.h index a49e0fb96cd..4eb84ae1762 100644 --- a/editor/plugins/texture_region_editor_plugin.h +++ b/editor/plugins/texture_region_editor_plugin.h @@ -145,10 +145,16 @@ public: class TextureRegionEditorPlugin : public EditorPlugin { GDCLASS(TextureRegionEditorPlugin, EditorPlugin); + bool manually_hidden; Button *texture_region_button; TextureRegionEditor *region_editor; EditorNode *editor; +protected: + static void _bind_methods(); + + void _editor_visiblity_changed(); + public: virtual String get_name() const { return "TextureRegion"; } bool has_main_screen() const { return false; }