You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
3.1 KiB
GDScript

2 years ago
@tool
extends PanelContainer
signal make_floating()
2 years ago
const BeehaveGraphEdit := preload("graph_edit.gd")
const TREE_ICON := preload("../icons/tree.svg")
2 years ago
var container: HSplitContainer
var item_list: ItemList
var graph: BeehaveGraphEdit
var message: Label
2 years ago
var active_trees: Dictionary
var active_tree_id: int = -1
var session: EditorDebuggerSession
func _ready() -> void:
container = HSplitContainer.new()
add_child(container)
item_list = ItemList.new()
item_list.custom_minimum_size = Vector2(200, 0)
item_list.item_selected.connect(_on_item_selected)
container.add_child(item_list)
graph = BeehaveGraphEdit.new()
container.add_child(graph)
message = Label.new()
message.text = "Run Project for debugging"
message.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
message.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
message.set_anchors_preset(Control.PRESET_CENTER)
add_child(message)
var button := Button.new()
button.flat = true
button.icon = get_theme_icon(&"ExternalLink", &"EditorIcons")
button.pressed.connect(func(): make_floating.emit())
button.tooltip_text = "Make floating"
button.focus_mode = Control.FOCUS_NONE
graph.get_menu_hbox().add_child(button)
var toggle_button := Button.new()
toggle_button.flat = true
toggle_button.icon = get_theme_icon(&"Back", &"EditorIcons")
toggle_button.pressed.connect(_on_toggle_button_pressed.bind(toggle_button))
toggle_button.tooltip_text = "Toggle Panel"
toggle_button.focus_mode = Control.FOCUS_NONE
graph.get_menu_hbox().add_child(toggle_button)
graph.get_menu_hbox().move_child(toggle_button, 0)
stop()
visibility_changed.connect(_on_visibility_changed)
2 years ago
func start() -> void:
container.visible = true
message.visible = false
2 years ago
func stop() -> void:
container.visible = false
message.visible = true
2 years ago
active_trees.clear()
item_list.clear()
graph.beehave_tree = {}
2 years ago
func register_tree(data: Dictionary) -> void:
var idx := item_list.add_item(data.name, TREE_ICON)
item_list.set_item_tooltip(idx, data.path)
item_list.set_item_metadata(idx, data.id)
active_trees[data.id] = data
2 years ago
func unregister_tree(instance_id: int) -> void:
var id := str(instance_id)
for i in item_list.item_count:
if item_list.get_item_metadata(i) == id:
item_list.remove_item(i)
break
2 years ago
active_trees.erase(id)
2 years ago
if graph.beehave_tree.get("id", "") == id:
graph.beehave_tree = {}
2 years ago
func _on_toggle_button_pressed(toggle_button: Button) -> void:
item_list.visible = !item_list.visible
toggle_button.icon = get_theme_icon(&"Back" if item_list.visible else &"Forward", &"EditorIcons")
2 years ago
func _on_item_selected(idx: int) -> void:
var id: StringName = item_list.get_item_metadata(idx)
graph.beehave_tree = active_trees.get(id, {})
2 years ago
active_tree_id = id.to_int()
session.send_message("beehave:activate_tree", [active_tree_id])
2 years ago
func _on_visibility_changed() -> void:
session.send_message("beehave:visibility_changed", [visible and is_visible_in_tree()])