forked from kanium/starcheese
75 lines
2.6 KiB
GDScript
75 lines
2.6 KiB
GDScript
extends CanvasLayer
|
|
|
|
@export var debug_spacing: int = 10 # Spacing between debug labels
|
|
var debug_labels: Dictionary = {}
|
|
var instance_debug_visible: bool = false
|
|
|
|
func _ready():
|
|
# Connect the signal from DebugManager
|
|
var debug_manager = get_node("/root/Main/DebugManager")
|
|
if debug_manager:
|
|
debug_manager.connect("toggle_instance_debug_signal", Callable(self, "_on_toggle_instance_debug"))
|
|
print("Connected to toggle_instance_debug_signal from DebugManager.")
|
|
else:
|
|
print("Error: DebugManager not found!")
|
|
|
|
# Connect existing debuggable nodes
|
|
for node in get_tree().get_nodes_in_group("debuggable"):
|
|
_connect_debuggable_node(node)
|
|
|
|
# Listen for new debuggable nodes
|
|
get_tree().connect("node_added", Callable(self, "_on_node_added"))
|
|
|
|
func _process(delta: float):
|
|
# Update label positions to match their nodes
|
|
for node_path in debug_labels.keys():
|
|
var label = debug_labels[node_path]
|
|
var node = null
|
|
|
|
if get_node_or_null(node_path):
|
|
node = get_node(node_path)
|
|
|
|
# Update the label's position if the node exists
|
|
if label and node:
|
|
label.global_position = node.global_position + Vector2(100, -70) # Position the label
|
|
|
|
|
|
func _on_toggle_instance_debug(debug_visible: bool):
|
|
instance_debug_visible = debug_visible
|
|
print("Received toggle_instance_debug_signal. Setting instance debug visibility to:", instance_debug_visible)
|
|
for label in debug_labels.values():
|
|
if label:
|
|
label.visible = instance_debug_visible
|
|
|
|
func _on_node_added(node: Node):
|
|
if node.is_in_group("debuggable"):
|
|
_connect_debuggable_node(node)
|
|
|
|
func _connect_debuggable_node(node: Node):
|
|
var node_path = str(node.get_path())
|
|
|
|
if not debug_labels.has(node_path):
|
|
var label = Label.new()
|
|
label.visible = instance_debug_visible
|
|
label.autowrap_mode = TextServer.AUTOWRAP_OFF
|
|
label.horizontal_alignment = HorizontalAlignment.HORIZONTAL_ALIGNMENT_LEFT
|
|
label.vertical_alignment = VerticalAlignment.VERTICAL_ALIGNMENT_TOP
|
|
label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
label.custom_minimum_size = Vector2(400, 0)
|
|
add_child(label)
|
|
debug_labels[node_path] = label
|
|
print("Created label for node:", node_path)
|
|
|
|
# Connect the debug update signal
|
|
if not node.is_connected("debug_updated", Callable(self, "_on_debug_updated")):
|
|
node.connect("debug_updated", Callable(self, "_on_debug_updated"))
|
|
print("Connected debug_updated signal for:", node_path)
|
|
|
|
func _on_debug_updated(node: Node, debug_text: String):
|
|
var node_path = str(node.get_path())
|
|
if debug_labels.has(node_path):
|
|
var label = debug_labels[node_path]
|
|
if label:
|
|
label.text = debug_text
|
|
label.visible = instance_debug_visible
|