Skip to content

Commit

Permalink
Only show searched entities (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
VojtaStruhar authored Jan 23, 2024
1 parent a0376f7 commit 49bf896
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions addons/pandora/ui/components/entity_tree/entity_tree.gd
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,22 @@ func _ready():
## filters the existing list to the given search term
## if search term is empty the search gets cleared.
func search(text:String) -> void:
for key in entity_items:
var entity_item = entity_items[key] as TreeItem
if text != "":
var entity = entity_item.get_metadata(0) as PandoraEntity
entity_item.set_collapsed_recursive(entity.get_entity_name().contains(text))
else:
entity_item.set_collapsed_recursive(false)
var root = get_root()
for top_item in root.get_children():
_search_item_recursive(top_item, text)


func _search_item_recursive(item: TreeItem, text: String) -> bool:
var entity = item.get_metadata(0) as PandoraEntity
# always succeed on empty search!
var matches_search = (text == "") or entity.get_entity_name().to_lower().contains(text.to_lower())

for sub in item.get_children():
var submatch = _search_item_recursive(sub, text)
matches_search = matches_search or submatch

item.visible = matches_search
return matches_search


func queue_delete(entity_id:String) -> void:
Expand Down

0 comments on commit 49bf896

Please sign in to comment.