From 45a1c98332b46a18bb084e04951f52f962b8c3e6 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 29 Jul 2022 22:45:57 +0200 Subject: [PATCH] Ported: SpriteFramesEditor Add animation searchbox - kleonc https://github.com/godotengine/godot/commit/728a725b7badb1c39afe791d7fa35af8a78d3852 --- .../plugins/sprite_frames_editor_plugin.cpp | 27 +++++++++++++++++-- editor/plugins/sprite_frames_editor_plugin.h | 3 +++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp index 63a41206f..67dbf69a1 100644 --- a/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/editor/plugins/sprite_frames_editor_plugin.cpp @@ -446,6 +446,7 @@ void SpriteFramesEditor::_notification(int p_what) { zoom_in->set_icon(get_icon("ZoomMore", "EditorIcons")); new_anim->set_icon(get_icon("New", "EditorIcons")); remove_anim->set_icon(get_icon("Remove", "EditorIcons")); + anim_search_box->set_right_icon(get_icon("Search", "EditorIcons")); split_sheet_zoom_out->set_icon(get_icon("ZoomLess", "EditorIcons")); split_sheet_zoom_reset->set_icon(get_icon("ZoomReset", "EditorIcons")); split_sheet_zoom_in->set_icon(get_icon("ZoomMore", "EditorIcons")); @@ -776,7 +777,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(); } @@ -842,6 +843,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; @@ -931,9 +936,16 @@ void SpriteFramesEditor::_update_library(bool p_skip_selector) { anim_names.sort_custom(); + bool searching = anim_search_box->get_text().size(); + String searched_string = searching ? anim_search_box->get_text().to_lower() : String(); + for (List::Element *E = anim_names.front(); E; E = E->next()) { String name = E->get(); + if (searching && name.to_lower().find(searched_string) < 0) { + continue; + } + TreeItem *it = animations->create_item(anim_root); it->set_metadata(0, name); @@ -996,7 +1008,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) { @@ -1168,6 +1179,7 @@ void SpriteFramesEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("_animation_add"), &SpriteFramesEditor::_animation_add); ClassDB::bind_method(D_METHOD("_animation_remove"), &SpriteFramesEditor::_animation_remove); ClassDB::bind_method(D_METHOD("_animation_remove_confirmed"), &SpriteFramesEditor::_animation_remove_confirmed); + ClassDB::bind_method(D_METHOD("_animation_search_text_changed"), &SpriteFramesEditor::_animation_search_text_changed); ClassDB::bind_method(D_METHOD("_animation_loop_changed"), &SpriteFramesEditor::_animation_loop_changed); ClassDB::bind_method(D_METHOD("_animation_fps_changed"), &SpriteFramesEditor::_animation_fps_changed); ClassDB::bind_method(D_METHOD("_tree_input"), &SpriteFramesEditor::_tree_input); @@ -1212,6 +1224,13 @@ SpriteFramesEditor::SpriteFramesEditor() { hbc_animlist->add_child(remove_anim); remove_anim->connect("pressed", this, "_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", this, "_animation_search_text_changed"); + animations = memnew(Tree); sub_vb->add_child(animations); animations->set_v_size_flags(SIZE_EXPAND_FILL); @@ -1493,6 +1512,10 @@ SpriteFramesEditor::SpriteFramesEditor() { updating_split_settings = false; _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 2307e7508..0214053b9 100644 --- a/editor/plugins/sprite_frames_editor_plugin.h +++ b/editor/plugins/sprite_frames_editor_plugin.h @@ -58,6 +58,7 @@ class TextureRect; class ToolButton; class Tree; class UndoRedo; +class LineEdit; class SpriteFramesEditor : public HSplitContainer { GDCLASS(SpriteFramesEditor, HSplitContainer); @@ -87,6 +88,7 @@ class SpriteFramesEditor : public HSplitContainer { ToolButton *new_anim; ToolButton *remove_anim; + LineEdit *anim_search_box; Tree *animations; SpinBox *anim_speed; @@ -151,6 +153,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);