Fix TextureRegionEditorPlugin popping up even when explicitly hidden

Fixes #27468
This commit is contained in:
Bojidar Marinov 2019-07-13 21:55:32 +03:00
parent 3bfffcc568
commit b648d3e110
No known key found for this signature in database
GPG Key ID: 4D546A8F1E091856
2 changed files with 22 additions and 4 deletions

View File

@ -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"); 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) { void TextureRegionEditorPlugin::make_visible(bool p_visible) {
if (p_visible) { if (p_visible) {
texture_region_button->show(); 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); editor->make_bottom_panel_item_visible(region_editor);
} }
} else { } else {
if (region_editor->is_visible_in_tree()) { if (region_editor->is_visible_in_tree()) {
editor->hide_bottom_panel(); editor->hide_bottom_panel();
manually_hidden = false;
} }
texture_region_button->hide(); texture_region_button->hide();
region_editor->edit(NULL); region_editor->edit(NULL);
@ -1076,12 +1082,18 @@ void TextureRegionEditorPlugin::set_state(const Dictionary &p_state) {
} }
} }
TextureRegionEditorPlugin::TextureRegionEditorPlugin(EditorNode *p_node) { void TextureRegionEditorPlugin::_bind_methods() {
editor = p_node; ClassDB::bind_method(D_METHOD("_editor_visiblity_changed"), &TextureRegionEditorPlugin::_editor_visiblity_changed);
region_editor = memnew(TextureRegionEditor(p_node)); }
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->set_custom_minimum_size(Size2(0, 200) * EDSCALE);
region_editor->hide(); 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 = p_node->add_bottom_panel_item(TTR("TextureRegion"), region_editor);
texture_region_button->hide(); texture_region_button->hide();

View File

@ -145,10 +145,16 @@ public:
class TextureRegionEditorPlugin : public EditorPlugin { class TextureRegionEditorPlugin : public EditorPlugin {
GDCLASS(TextureRegionEditorPlugin, EditorPlugin); GDCLASS(TextureRegionEditorPlugin, EditorPlugin);
bool manually_hidden;
Button *texture_region_button; Button *texture_region_button;
TextureRegionEditor *region_editor; TextureRegionEditor *region_editor;
EditorNode *editor; EditorNode *editor;
protected:
static void _bind_methods();
void _editor_visiblity_changed();
public: public:
virtual String get_name() const { return "TextureRegion"; } virtual String get_name() const { return "TextureRegion"; }
bool has_main_screen() const { return false; } bool has_main_screen() const { return false; }