Make TreeSearch independent, remove unnecessary draw bind
This commit is contained in:
parent
9a1641e8ab
commit
ffe344d166
|
@ -13,7 +13,6 @@
|
|||
|
||||
#include "tree_search.h"
|
||||
|
||||
#include "../bt/behavior_tree.h"
|
||||
#include "../util/limbo_compat.h" // for edscale
|
||||
#include "../util/limbo_string_names.h"
|
||||
#include "../util/limbo_utility.h"
|
||||
|
@ -179,7 +178,7 @@ void TreeSearch::_highlight_tree(const String &p_search_mask) {
|
|||
parent_draw_method = entry->get_custom_draw_callback(0);
|
||||
}
|
||||
|
||||
Callable draw_callback = callable_mp(this, &TreeSearch::_draw_highlight_item).bind(p_search_mask, parent_draw_method);
|
||||
Callable draw_callback = callable_mp(this, &TreeSearch::_draw_highlight_item).bind(parent_draw_method);
|
||||
|
||||
// -- this is necessary because of the modularity of this implementation
|
||||
// cache render properties of entry
|
||||
|
@ -199,10 +198,11 @@ void TreeSearch::_highlight_tree(const String &p_search_mask) {
|
|||
}
|
||||
}
|
||||
|
||||
// custom draw callback for highlighting (bind 2)
|
||||
void TreeSearch::_draw_highlight_item(TreeItem *p_tree_item, Rect2 p_rect, String p_search_mask, Callable p_parent_draw_method) {
|
||||
if (!p_tree_item)
|
||||
// custom draw callback for highlighting (bind the parent_drw_method to this)
|
||||
void TreeSearch::_draw_highlight_item(TreeItem *p_tree_item, Rect2 p_rect, Callable p_parent_draw_method) {
|
||||
if (!p_tree_item){
|
||||
return;
|
||||
}
|
||||
// call any parent draw methods such as for probability FIRST.
|
||||
p_parent_draw_method.call(p_tree_item, p_rect);
|
||||
|
||||
|
@ -221,7 +221,7 @@ void TreeSearch::_draw_highlight_item(TreeItem *p_tree_item, Rect2 p_rect, Strin
|
|||
|
||||
// substring size
|
||||
String string_full = p_tree_item->get_text(0);
|
||||
StringSearchIndices substring_idx = _substring_bounds(string_full, p_search_mask);
|
||||
StringSearchIndices substring_idx = _substring_bounds(string_full, _get_search_mask());
|
||||
|
||||
String substring_match = string_full.substr(substring_idx.lower, substring_idx.upper - substring_idx.lower);
|
||||
Vector2 substring_match_size = font->get_string_size(substring_match, HORIZONTAL_ALIGNMENT_LEFT, -1.f, font_size);
|
||||
|
@ -310,6 +310,11 @@ void TreeSearch::_update_number_matches() {
|
|||
}
|
||||
}
|
||||
|
||||
String TreeSearch::_get_search_mask() {
|
||||
ERR_FAIL_COND_V(!search_panel, "");
|
||||
return search_panel->get_text();
|
||||
}
|
||||
|
||||
Vector<TreeItem *> TreeSearch::_find_matching_entries(TreeItem *p_tree_item, const String &p_search_mask, Vector<TreeItem *> &p_accum) {
|
||||
if (!p_tree_item)
|
||||
return p_accum;
|
||||
|
|
|
@ -14,15 +14,13 @@
|
|||
#ifndef TREE_SEARCH_H
|
||||
#define TREE_SEARCH_H
|
||||
|
||||
#include "../bt/tasks/bt_task.h" // for tree item parsing
|
||||
|
||||
#ifdef LIMBOAI_GDEXTENSION
|
||||
#include <godot_cpp/classes/check_box.hpp>
|
||||
#include <godot_cpp/classes/h_flow_container.hpp>
|
||||
#include <godot_cpp/classes/label.hpp>
|
||||
#include <godot_cpp/classes/line_edit.hpp>
|
||||
#include <godot_cpp/classes/tree.hpp>
|
||||
|
||||
#include <godot_cpp/templates/hash_map.hpp>
|
||||
#endif // LIMBOAI_GDEXTENSION
|
||||
|
||||
#ifdef LIMBOAI_MODULE
|
||||
|
@ -31,6 +29,7 @@
|
|||
#include "scene/gui/label.h"
|
||||
#include "scene/gui/line_edit.h"
|
||||
#include "scene/gui/tree.h"
|
||||
#include "core/templates/hash_map.h"
|
||||
#endif // LIMBOAI_MODULE
|
||||
|
||||
using namespace godot;
|
||||
|
@ -83,21 +82,26 @@ private:
|
|||
|
||||
TreeSearchPanel *search_panel;
|
||||
|
||||
// These variables are updated every time the update_search method is called.
|
||||
// For TaskTree: These are updated when the tree is updated through TaskTree::_create_tree.
|
||||
Tree *tree_reference;
|
||||
Vector<TreeItem *> ordered_tree_items;
|
||||
Vector<TreeItem *> matching_entries;
|
||||
HashMap<TreeItem *, int> number_matches;
|
||||
HashMap<TreeItem *, Callable> callable_cache;
|
||||
|
||||
// Update_search() calls these
|
||||
void _filter_tree(const String &p_search_mask);
|
||||
void _highlight_tree(const String &p_search_mask);
|
||||
void _draw_highlight_item(TreeItem *p_tree_item, Rect2 p_rect, String p_search_mask, Callable p_parent_draw_method);
|
||||
|
||||
// Custom draw-Callback (bind inherited Callable).
|
||||
void _draw_highlight_item(TreeItem *p_tree_item, Rect2 p_rect, Callable p_parent_draw_method);
|
||||
|
||||
void _update_matching_entries(const String &p_search_mask);
|
||||
void _update_ordered_tree_items(TreeItem *p_tree_item);
|
||||
void _update_number_matches();
|
||||
|
||||
Vector<TreeItem *> _find_matching_entries(TreeItem *p_tree_item, const String &p_search_mask, Vector<TreeItem *> &p_buffer);
|
||||
String _get_search_mask();
|
||||
StringSearchIndices _substring_bounds(const String &p_searchable, const String &p_search_mask) const;
|
||||
|
||||
void _select_item(TreeItem *p_item);
|
||||
|
@ -111,7 +115,6 @@ protected:
|
|||
static void _bind_methods() {}
|
||||
|
||||
public:
|
||||
// we will add everything from TaskTree.h
|
||||
void update_search(Tree *p_tree);
|
||||
void on_item_edited(TreeItem *p_item);
|
||||
|
||||
|
|
Loading…
Reference in New Issue