Skip to content

Commit

Permalink
SpriteFramesEditor Add animation searchbox
Browse files Browse the repository at this point in the history
Co-authored-by: Hugo Locurcio <[email protected]>
  • Loading branch information
2 people authored and toasterofbread committed Aug 12, 2021
1 parent 9828217 commit 9951d21
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
50 changes: 46 additions & 4 deletions editor/plugins/sprite_frames_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ void SpriteFramesEditor::_sheet_preview_draw() {
split_sheet_dialog->get_ok()->set_disabled(false);
split_sheet_dialog->get_ok()->set_text(vformat(TTR("Add %d Frame(s)"), frames_selected.size()));
}

void SpriteFramesEditor::_sheet_preview_input(const Ref<InputEvent> &p_event) {

Ref<InputEventMouseButton> mb = p_event;
Expand Down Expand Up @@ -243,6 +244,11 @@ void SpriteFramesEditor::_notification(int p_what) {
_delete->set_icon(get_icon("Remove", "EditorIcons"));
new_anim->set_icon(get_icon("New", "EditorIcons"));
remove_anim->set_icon(get_icon("Remove", "EditorIcons"));
toggle_anim_search_box->set_icon(get_icon("Search", "EditorIcons"));
anim_search_box->set_clear_button_enabled(true);
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"));
FALLTHROUGH;
}
case NOTIFICATION_THEME_CHANGED: {
Expand Down Expand Up @@ -555,7 +561,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();
}
Expand Down Expand Up @@ -623,6 +629,22 @@ void SpriteFramesEditor::_animation_remove_confirmed() {
undo_redo->commit_action();
}

void SpriteFramesEditor::_animation_toggle_search_box_visibility() {
if (toggle_anim_search_box->is_pressed()) {
toggle_anim_search_box->set_tooltip(TTR("Hide animations filter box"));
anim_search_box->show();
} else {
toggle_anim_search_box->set_tooltip(TTR("Show animations filter box"));
anim_search_box->hide();
}

_update_library();
}

void SpriteFramesEditor::_animation_search_text_changed(const String &p_text) {
_update_library();
}

void SpriteFramesEditor::_animation_loop_changed() {

if (updating)
Expand Down Expand Up @@ -660,15 +682,20 @@ 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->is_visible() && anim_search_box->get_text().size();
String searched_string = searching ? anim_search_box->get_text().to_lower() : String();

for (List<StringName>::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);
Expand Down Expand Up @@ -719,7 +746,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) {
Expand Down Expand Up @@ -888,6 +914,8 @@ 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_toggle_search_box_visibility"), &SpriteFramesEditor::_animation_toggle_search_box_visibility);
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("get_drag_data_fw"), &SpriteFramesEditor::get_drag_data_fw);
Expand Down Expand Up @@ -925,6 +953,20 @@ SpriteFramesEditor::SpriteFramesEditor() {
hbc_animlist->add_child(remove_anim);
remove_anim->connect("pressed", this, "_animation_remove");

toggle_anim_search_box = memnew(ToolButton);
toggle_anim_search_box->set_toggle_mode(true);
toggle_anim_search_box->set_tooltip(TTR("Show animations filter box"));
toggle_anim_search_box->set_h_size_flags(SIZE_EXPAND | SIZE_SHRINK_END);
hbc_animlist->add_child(toggle_anim_search_box);
toggle_anim_search_box->connect("pressed", this, "_animation_toggle_search_box_visibility");

anim_search_box = memnew(LineEdit);
sub_vb->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->connect("text_changed", this, "_animation_search_text_changed");
anim_search_box->hide();

animations = memnew(Tree);
sub_vb->add_child(animations);
animations->set_v_size_flags(SIZE_EXPAND_FILL);
Expand Down
5 changes: 5 additions & 0 deletions editor/plugins/sprite_frames_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "scene/2d/animated_sprite.h"
#include "scene/gui/dialogs.h"
#include "scene/gui/file_dialog.h"
#include "scene/gui/line_edit.h"
#include "scene/gui/split_container.h"
#include "scene/gui/texture_rect.h"
#include "scene/gui/tree.h"
Expand All @@ -60,7 +61,9 @@ class SpriteFramesEditor : public HSplitContainer {
HSplitContainer *split;
ToolButton *new_anim;
ToolButton *remove_anim;
ToolButton *toggle_anim_search_box;

LineEdit *anim_search_box;
Tree *animations;
SpinBox *anim_speed;
CheckButton *anim_loop;
Expand Down Expand Up @@ -101,6 +104,8 @@ class SpriteFramesEditor : public HSplitContainer {
void _animation_add();
void _animation_remove();
void _animation_remove_confirmed();
void _animation_toggle_search_box_visibility();
void _animation_search_text_changed(const String &p_text);
void _animation_loop_changed();
void _animation_fps_changed(double p_value);

Expand Down

0 comments on commit 9951d21

Please sign in to comment.