godot-control-tree/ControlTree.gd

39 lines
797 B
GDScript3
Raw Permalink Normal View History

2022-10-24 16:00:50 +00:00
extends Control
class_name ControlTree
export(PackedScene) var item_scene: PackedScene
export(bool) var allow_multi_select: bool = false
onready var items_container: VBoxContainer = $"%Items"
var items: Array = []
var item_select_btn_group: ButtonGroup = ButtonGroup.new()
func add_item(text: String, parent_item: ControlTreeItem = null) -> ControlTreeItem:
var new_item: ControlTreeItem = item_scene.instance()
if !parent_item:
items_container.add_child(new_item)
items.append(new_item)
else:
parent_item.add_subitem(new_item)
new_item.set_text(text)
if !allow_multi_select:
new_item.set_button_group(item_select_btn_group)
return new_item
func get_items_by_name(s: String) -> Array:
var res = []
for i in items:
if i.get_text() == s:
res.append(i)
return res