From b650ba820b1385c47916ac9dbc2fc60f48a2a3b7 Mon Sep 17 00:00:00 2001 From: Hakim Date: Fri, 19 May 2023 01:14:11 +0200 Subject: [PATCH] Hide Animation Frames section when there are no animations and show message (cherry picked from commit 9cf2d0f058c526f1e49129e1b656de36c58c15e7) --- .../plugins/sprite_frames_editor_plugin.cpp | 26 +++++++++++++++---- editor/plugins/sprite_frames_editor_plugin.h | 3 +++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp index 86e5b238fbc..da487c34a86 100644 --- a/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/editor/plugins/sprite_frames_editor_plugin.cpp @@ -1067,7 +1067,13 @@ void SpriteFramesEditor::_update_library(bool p_skip_selector) { List anim_names; frames->get_animation_list(&anim_names); anim_names.sort_custom(); - + if (!anim_names.size()) { + missing_anim_label->show(); + anim_frames_vb->hide(); + return; + } + missing_anim_label->hide(); + anim_frames_vb->show(); bool searching = anim_search_box->get_text().size(); String searched_string = searching ? anim_search_box->get_text().to_lower() : String(); @@ -1574,12 +1580,22 @@ SpriteFramesEditor::SpriteFramesEditor() { delete_anim->set_shortcut_context(animations); delete_anim->set_shortcut(ED_SHORTCUT("sprite_frames/delete_animation", TTR("Delete Animation"), Key::KEY_DELETE)); - VBoxContainer *vbc = memnew(VBoxContainer); - add_child(vbc); - vbc->set_h_size_flags(SIZE_EXPAND_FILL); + missing_anim_label = memnew(Label); + missing_anim_label->set_text(TTR("This resource does not have any animations.")); + missing_anim_label->set_h_size_flags(SIZE_EXPAND_FILL); + missing_anim_label->set_v_size_flags(SIZE_EXPAND_FILL); + missing_anim_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER); + missing_anim_label->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER); + missing_anim_label->hide(); + add_child(missing_anim_label); + + anim_frames_vb = memnew(VBoxContainer); + add_child(anim_frames_vb); + anim_frames_vb->set_h_size_flags(SIZE_EXPAND_FILL); + anim_frames_vb->hide(); sub_vb = memnew(VBoxContainer); - vbc->add_margin_child(TTR("Animation Frames:"), sub_vb, true); + anim_frames_vb->add_margin_child(TTR("Animation Frames:"), sub_vb, true); HFlowContainer *hfc = memnew(HFlowContainer); sub_vb->add_child(hfc); diff --git a/editor/plugins/sprite_frames_editor_plugin.h b/editor/plugins/sprite_frames_editor_plugin.h index 1dfb9093880..2b24c024fbd 100644 --- a/editor/plugins/sprite_frames_editor_plugin.h +++ b/editor/plugins/sprite_frames_editor_plugin.h @@ -110,6 +110,9 @@ class SpriteFramesEditor : public HSplitContainer { LineEdit *anim_search_box = nullptr; Tree *animations = nullptr; + Label *missing_anim_label = nullptr; + VBoxContainer *anim_frames_vb = nullptr; + EditorFileDialog *file = nullptr; AcceptDialog *dialog = nullptr;