godot-control-tree/ControlTree.gd
2022-10-24 19:00:50 +03:00

30 lines
666 B
GDScript

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