diff options
-rw-r--r-- | editor/plugins/sprite_frames_editor_plugin.cpp | 28 | ||||
-rw-r--r-- | editor/plugins/sprite_frames_editor_plugin.h | 3 |
2 files changed, 27 insertions, 4 deletions
diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp index edd900f7d8..e7c2e455e6 100644 --- a/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/editor/plugins/sprite_frames_editor_plugin.cpp @@ -423,6 +423,7 @@ void SpriteFramesEditor::_notification(int p_what) { zoom_in->set_icon(get_theme_icon(SNAME("ZoomMore"), SNAME("EditorIcons"))); new_anim->set_icon(get_theme_icon(SNAME("New"), SNAME("EditorIcons"))); remove_anim->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))); + anim_search_box->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); split_sheet_zoom_out->set_icon(get_theme_icon(SNAME("ZoomLess"), SNAME("EditorIcons"))); split_sheet_zoom_reset->set_icon(get_theme_icon(SNAME("ZoomReset"), SNAME("EditorIcons"))); split_sheet_zoom_in->set_icon(get_theme_icon(SNAME("ZoomMore"), SNAME("EditorIcons"))); @@ -750,7 +751,7 @@ void SpriteFramesEditor::_animation_name_edited() { undo_redo->add_do_method(this, "_update_library"); undo_redo->add_undo_method(this, "_update_library"); - edited_anim = new_name; + edited_anim = name; undo_redo->commit_action(); } @@ -816,6 +817,10 @@ void SpriteFramesEditor::_animation_remove_confirmed() { undo_redo->commit_action(); } +void SpriteFramesEditor::_animation_search_text_changed(const String &p_text) { + _update_library(); +} + void SpriteFramesEditor::_animation_loop_changed() { if (updating) { return; @@ -900,14 +905,19 @@ void SpriteFramesEditor::_update_library(bool p_skip_selector) { TreeItem *anim_root = animations->create_item(); List<StringName> anim_names; - frames->get_animation_list(&anim_names); - anim_names.sort_custom<StringName::AlphCompare>(); + bool searching = anim_search_box->get_text().size(); + String searched_string = searching ? anim_search_box->get_text().to_lower() : String(); + for (const StringName &E : anim_names) { String name = E; + if (searching && name.to_lower().find(searched_string) < 0) { + continue; + } + TreeItem *it = animations->create_item(anim_root); it->set_metadata(0, name); @@ -970,7 +980,6 @@ void SpriteFramesEditor::_update_library(bool p_skip_selector) { anim_loop->set_pressed(frames->get_animation_loop(edited_anim)); updating = false; - //player->add_resource("default",resource); } void SpriteFramesEditor::edit(SpriteFrames *p_frames) { @@ -1157,6 +1166,13 @@ SpriteFramesEditor::SpriteFramesEditor() { hbc_animlist->add_child(remove_anim); remove_anim->connect("pressed", callable_mp(this, &SpriteFramesEditor::_animation_remove)); + anim_search_box = memnew(LineEdit); + hbc_animlist->add_child(anim_search_box); + anim_search_box->set_h_size_flags(SIZE_EXPAND_FILL); + anim_search_box->set_placeholder(TTR("Filter animations")); + anim_search_box->set_clear_button_enabled(true); + anim_search_box->connect("text_changed", callable_mp(this, &SpriteFramesEditor::_animation_search_text_changed)); + animations = memnew(Tree); sub_vb->add_child(animations); animations->set_v_size_flags(SIZE_EXPAND_FILL); @@ -1448,6 +1464,10 @@ SpriteFramesEditor::SpriteFramesEditor() { max_sheet_zoom = 16.0f * MAX(1.0f, EDSCALE); min_sheet_zoom = 0.01f * MAX(1.0f, EDSCALE); _zoom_reset(); + + // Ensure the anim search box is wide enough by default. + // Not by setting its minimum size so it can still be shrinked if desired. + set_split_offset(56 * EDSCALE); } void SpriteFramesEditorPlugin::edit(Object *p_object) { diff --git a/editor/plugins/sprite_frames_editor_plugin.h b/editor/plugins/sprite_frames_editor_plugin.h index 3c8c5ef19d..6352259b73 100644 --- a/editor/plugins/sprite_frames_editor_plugin.h +++ b/editor/plugins/sprite_frames_editor_plugin.h @@ -37,6 +37,7 @@ #include "scene/gui/check_button.h" #include "scene/gui/dialogs.h" #include "scene/gui/item_list.h" +#include "scene/gui/line_edit.h" #include "scene/gui/scroll_container.h" #include "scene/gui/spin_box.h" #include "scene/gui/split_container.h" @@ -73,6 +74,7 @@ class SpriteFramesEditor : public HSplitContainer { Button *new_anim = nullptr; Button *remove_anim = nullptr; + LineEdit *anim_search_box = nullptr; Tree *animations = nullptr; SpinBox *anim_speed = nullptr; @@ -137,6 +139,7 @@ class SpriteFramesEditor : public HSplitContainer { void _animation_add(); void _animation_remove(); void _animation_remove_confirmed(); + void _animation_search_text_changed(const String &p_text); void _animation_loop_changed(); void _animation_fps_changed(double p_value); |