|
|
@ -19,6 +19,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef LIMBOAI_MODULE
|
|
|
|
#ifdef LIMBOAI_MODULE
|
|
|
|
#include "core/math/math_funcs.h"
|
|
|
|
#include "core/math/math_funcs.h"
|
|
|
|
|
|
|
|
#include "core/templates/hash_set.h"
|
|
|
|
#include "editor/editor_interface.h"
|
|
|
|
#include "editor/editor_interface.h"
|
|
|
|
#include "editor/themes/editor_scale.h"
|
|
|
|
#include "editor/themes/editor_scale.h"
|
|
|
|
#include "scene/gui/separator.h"
|
|
|
|
#include "scene/gui/separator.h"
|
|
|
@ -34,6 +35,7 @@
|
|
|
|
#include <godot_cpp/classes/style_box_flat.hpp>
|
|
|
|
#include <godot_cpp/classes/style_box_flat.hpp>
|
|
|
|
#include <godot_cpp/classes/viewport.hpp>
|
|
|
|
#include <godot_cpp/classes/viewport.hpp>
|
|
|
|
#include <godot_cpp/core/math.hpp>
|
|
|
|
#include <godot_cpp/core/math.hpp>
|
|
|
|
|
|
|
|
#include <godot_cpp/templates/hash_set.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
#endif // LIMBOAI_GDEXTENSION
|
|
|
|
#endif // LIMBOAI_GDEXTENSION
|
|
|
|
|
|
|
|
|
|
|
@ -55,20 +57,56 @@ void TreeSearch::_clean_callable_cache() {
|
|
|
|
callable_cache = new_callable_cache;
|
|
|
|
callable_cache = new_callable_cache;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TreeSearch::_filter_tree() {
|
|
|
|
// Makes all tree items invisible that don't match the following criteria:
|
|
|
|
ERR_FAIL_COND(!tree_reference);
|
|
|
|
// 1. is a matching tree_item
|
|
|
|
_filter_tree(tree_reference->get_root(), false);
|
|
|
|
// 2. is a parent of a matching tree_item
|
|
|
|
|
|
|
|
// 3. is any descendant of a matching tree_item
|
|
|
|
|
|
|
|
void TreeSearch::_filter_tree(const String &p_search_mask) {
|
|
|
|
|
|
|
|
if (number_matches.size() == 0){
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
HashSet<TreeItem *> visible_as_parent;
|
|
|
|
|
|
|
|
HashSet<TreeItem *> visible_as_descendant;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Mark matching items and all their ancestors (1, 2)
|
|
|
|
|
|
|
|
for (int i = 0; i < matching_entries.size(); i++) {
|
|
|
|
|
|
|
|
TreeItem *cur_match = matching_entries[i];
|
|
|
|
|
|
|
|
TreeItem *current = cur_match;
|
|
|
|
|
|
|
|
while (current != nullptr && !visible_as_parent.has(current)) {
|
|
|
|
|
|
|
|
visible_as_parent.insert(current);
|
|
|
|
|
|
|
|
current = current->get_parent();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TreeSearch::_filter_tree(TreeItem *p_item, bool p_parent_matching) {
|
|
|
|
// Mark matching items and all their descendants (1, 3)
|
|
|
|
bool visible = number_matches.has(p_item) | p_parent_matching;
|
|
|
|
for (int i = 0; i < matching_entries.size(); i++) {
|
|
|
|
|
|
|
|
TreeItem *cur_match = matching_entries[i];
|
|
|
|
if (!visible) {
|
|
|
|
if (visible_as_descendant.has(cur_match)) {
|
|
|
|
p_item->set_visible(visible);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool is_matching = _vector_has_bsearch(matching_entries, p_item);
|
|
|
|
// Descendents
|
|
|
|
for (int i = 0; i < p_item->get_child_count(); i++) {
|
|
|
|
Vector<TreeItem *> descendent_list = { cur_match };
|
|
|
|
_filter_tree(p_item->get_child(i), is_matching | p_parent_matching);
|
|
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < descendent_list.size(); j++) {
|
|
|
|
|
|
|
|
TreeItem *descendent = descendent_list[j];
|
|
|
|
|
|
|
|
if (visible_as_descendant.has(descendent)) {
|
|
|
|
|
|
|
|
continue; // Skip subtree if already processed
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
visible_as_descendant.insert(descendent);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Collect X-level descendents (bit clunky because godot doesn't return get_children as pointers)
|
|
|
|
|
|
|
|
for (int k = 0; k < descendent->get_child_count(); k++) {
|
|
|
|
|
|
|
|
TreeItem *child = descendent->get_child(k);
|
|
|
|
|
|
|
|
descendent_list.push_back(child);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set visibility based on whether items are in either visibility set
|
|
|
|
|
|
|
|
for (int i = 0; i < ordered_tree_items.size(); i++) {
|
|
|
|
|
|
|
|
TreeItem *item = ordered_tree_items[i];
|
|
|
|
|
|
|
|
bool is_visible = visible_as_parent.has(item) || visible_as_descendant.has(item);
|
|
|
|
|
|
|
|
item->set_visible(is_visible);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -430,7 +468,7 @@ void TreeSearch::update_search(Tree *p_tree) {
|
|
|
|
_clear_filter();
|
|
|
|
_clear_filter();
|
|
|
|
_highlight_tree();
|
|
|
|
_highlight_tree();
|
|
|
|
if (search_mode == TreeSearchMode::FILTER) {
|
|
|
|
if (search_mode == TreeSearchMode::FILTER) {
|
|
|
|
_filter_tree();
|
|
|
|
_filter_tree(search_mask);
|
|
|
|
was_filtered_recently = true;
|
|
|
|
was_filtered_recently = true;
|
|
|
|
} else if (was_filtered_recently) {
|
|
|
|
} else if (was_filtered_recently) {
|
|
|
|
_clear_filter();
|
|
|
|
_clear_filter();
|
|
|
|