From afe25937e4ff1938447ea8f7c6b2c3ce9bf38e2e Mon Sep 17 00:00:00 2001 From: "Silc Lizard (Tokage) Renew" <61938263+TokageItLab@users.noreply.github.com> Date: Mon, 1 May 2023 03:20:23 +0900 Subject: [PATCH] Add useful functions to FilterEdit in AnimationBlendTreeEditor --- .../animation_blend_tree_editor_plugin.cpp | 125 +++++++++++++++++- .../animation_blend_tree_editor_plugin.h | 9 ++ 2 files changed, 133 insertions(+), 1 deletion(-) diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index dc3729393f0..cffd1811b94 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -610,6 +610,111 @@ void AnimationNodeBlendTreeEditor::_filter_edited() { updating = false; } +void AnimationNodeBlendTreeEditor::_filter_fill_selection() { + TreeItem *ti = filters->get_root(); + if (!ti) { + return; + } + + updating = true; + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); + undo_redo->create_action(TTR("Fill Selected Filter Children")); + + _filter_fill_selection_recursive(undo_redo, ti, false); + + undo_redo->add_do_method(this, "_update_filters", _filter_edit); + undo_redo->add_undo_method(this, "_update_filters", _filter_edit); + undo_redo->commit_action(); + updating = false; + + _update_filters(_filter_edit); +} + +void AnimationNodeBlendTreeEditor::_filter_invert_selection() { + TreeItem *ti = filters->get_root(); + if (!ti) { + return; + } + + updating = true; + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); + undo_redo->create_action(TTR("Invert Filter Selection")); + + _filter_invert_selection_recursive(undo_redo, ti); + + undo_redo->add_do_method(this, "_update_filters", _filter_edit); + undo_redo->add_undo_method(this, "_update_filters", _filter_edit); + undo_redo->commit_action(); + updating = false; + + _update_filters(_filter_edit); +} + +void AnimationNodeBlendTreeEditor::_filter_clear_selection() { + TreeItem *ti = filters->get_root(); + if (!ti) { + return; + } + + updating = true; + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); + undo_redo->create_action(TTR("Clear Filter Selection")); + + _filter_clear_selection_recursive(undo_redo, ti); + + undo_redo->add_do_method(this, "_update_filters", _filter_edit); + undo_redo->add_undo_method(this, "_update_filters", _filter_edit); + undo_redo->commit_action(); + updating = false; + + _update_filters(_filter_edit); +} + +void AnimationNodeBlendTreeEditor::_filter_fill_selection_recursive(EditorUndoRedoManager *p_undo_redo, TreeItem *p_item, bool p_parent_filtered) { + TreeItem *ti = p_item->get_first_child(); + bool parent_filtered = p_parent_filtered; + while (ti) { + NodePath item_path = ti->get_metadata(0); + bool filtered = _filter_edit->is_path_filtered(item_path); + parent_filtered |= filtered; + + p_undo_redo->add_do_method(_filter_edit.ptr(), "set_filter_path", item_path, parent_filtered); + p_undo_redo->add_undo_method(_filter_edit.ptr(), "set_filter_path", item_path, filtered); + + _filter_fill_selection_recursive(p_undo_redo, ti, parent_filtered); + ti = ti->get_next(); + parent_filtered = p_parent_filtered; + } +} + +void AnimationNodeBlendTreeEditor::_filter_invert_selection_recursive(EditorUndoRedoManager *p_undo_redo, TreeItem *p_item) { + TreeItem *ti = p_item->get_first_child(); + while (ti) { + NodePath item_path = ti->get_metadata(0); + bool filtered = _filter_edit->is_path_filtered(item_path); + + p_undo_redo->add_do_method(_filter_edit.ptr(), "set_filter_path", item_path, !filtered); + p_undo_redo->add_undo_method(_filter_edit.ptr(), "set_filter_path", item_path, filtered); + + _filter_invert_selection_recursive(p_undo_redo, ti); + ti = ti->get_next(); + } +} + +void AnimationNodeBlendTreeEditor::_filter_clear_selection_recursive(EditorUndoRedoManager *p_undo_redo, TreeItem *p_item) { + TreeItem *ti = p_item->get_first_child(); + while (ti) { + NodePath item_path = ti->get_metadata(0); + bool filtered = _filter_edit->is_path_filtered(item_path); + + p_undo_redo->add_do_method(_filter_edit.ptr(), "set_filter_path", item_path, false); + p_undo_redo->add_undo_method(_filter_edit.ptr(), "set_filter_path", item_path, filtered); + + _filter_clear_selection_recursive(p_undo_redo, ti); + ti = ti->get_next(); + } +} + bool AnimationNodeBlendTreeEditor::_update_filters(const Ref &anode) { if (updating || _filter_edit != anode) { return false; @@ -1108,10 +1213,28 @@ AnimationNodeBlendTreeEditor::AnimationNodeBlendTreeEditor() { VBoxContainer *filter_vbox = memnew(VBoxContainer); filter_dialog->add_child(filter_vbox); + HBoxContainer *filter_hbox = memnew(HBoxContainer); + filter_vbox->add_child(filter_hbox); + filter_enabled = memnew(CheckBox); filter_enabled->set_text(TTR("Enable Filtering")); filter_enabled->connect("pressed", callable_mp(this, &AnimationNodeBlendTreeEditor::_filter_toggled)); - filter_vbox->add_child(filter_enabled); + filter_hbox->add_child(filter_enabled); + + filter_fill_selection = memnew(Button); + filter_fill_selection->set_text(TTR("Fill Selected Children")); + filter_fill_selection->connect("pressed", callable_mp(this, &AnimationNodeBlendTreeEditor::_filter_fill_selection)); + filter_hbox->add_child(filter_fill_selection); + + filter_invert_selection = memnew(Button); + filter_invert_selection->set_text(TTR("Invert")); + filter_invert_selection->connect("pressed", callable_mp(this, &AnimationNodeBlendTreeEditor::_filter_invert_selection)); + filter_hbox->add_child(filter_invert_selection); + + filter_clear_selection = memnew(Button); + filter_clear_selection->set_text(TTR("Clear")); + filter_clear_selection->connect("pressed", callable_mp(this, &AnimationNodeBlendTreeEditor::_filter_clear_selection)); + filter_hbox->add_child(filter_clear_selection); filters = memnew(Tree); filter_vbox->add_child(filters); diff --git a/editor/plugins/animation_blend_tree_editor_plugin.h b/editor/plugins/animation_blend_tree_editor_plugin.h index 12b709515f6..e54a98cda85 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.h +++ b/editor/plugins/animation_blend_tree_editor_plugin.h @@ -66,6 +66,9 @@ class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin { AcceptDialog *filter_dialog = nullptr; Tree *filters = nullptr; CheckBox *filter_enabled = nullptr; + Button *filter_fill_selection = nullptr; + Button *filter_invert_selection = nullptr; + Button *filter_clear_selection = nullptr; HashMap animations; Vector visible_properties; @@ -116,6 +119,12 @@ class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin { void _inspect_filters(const String &p_which); void _filter_edited(); void _filter_toggled(); + void _filter_fill_selection(); + void _filter_invert_selection(); + void _filter_clear_selection(); + void _filter_fill_selection_recursive(EditorUndoRedoManager *p_undo_redo, TreeItem *p_item, bool p_parent_filtered); + void _filter_invert_selection_recursive(EditorUndoRedoManager *p_undo_redo, TreeItem *p_item); + void _filter_clear_selection_recursive(EditorUndoRedoManager *p_undo_redo, TreeItem *p_item); Ref _filter_edit; void _popup(bool p_has_input_ports, const Vector2 &p_node_position);