game: add debug stats panel

This commit is contained in:
2025-08-19 04:15:36 +02:00
parent 4682171a2f
commit 10788b01a4
4 changed files with 70 additions and 5 deletions

View File

@@ -1,8 +1,18 @@
class_name DebugUI
extends Control
@onready var stats_container: PanelContainer = $StatsContainer
@onready var panel_container: PanelContainer = $PanelContainer
var debug_stats: Dictionary = {}
func _ready() -> void:
stats_container.visible = false
panel_container.visible = false
GlobalConst.sig_debug_stats_set.connect(set_debug_stat)
func toggle():
visible = !visible
panel_container.visible = !panel_container.visible
func _on_zoom_check_toggled(toggled_on: bool) -> void:
GlobalConst.sig_debug_camera_zoom.emit(toggled_on)
@@ -10,6 +20,45 @@ func _on_zoom_check_toggled(toggled_on: bool) -> void:
func _on_god_mode_check_toggled(toggled_on: bool) -> void:
GlobalConst.sig_debug_god_mode.emit(toggled_on)
func _on_enemy_god_mode_check_toggled(toggled_on: bool) -> void:
GlobalConst.sig_debug_enemy_god_mode.emit(toggled_on)
func _on_stats_check_toggled(toggled_on: bool) -> void:
stats_container.visible = toggled_on
func set_debug_stat(key: String, value: String):
if key == "":
debug_stats.erase(key)
debug_stats[key] = value
update_debug_stats()
func update_debug_stats() -> void:
for child in stats_container.get_children():
child.queue_free()
for stat in debug_stats:
# Create margin container
var mc: MarginContainer = MarginContainer.new()
mc.add_theme_constant_override("margin_top", 10)
mc.add_theme_constant_override("margin_left", 20)
mc.add_theme_constant_override("margin_bottom", 10)
mc.add_theme_constant_override("margin_right", 20)
stats_container.add_child(mc)
# Create the grid container
var gc: GridContainer = GridContainer.new()
gc.columns = 2
mc.add_child(gc)
# Create label for key
var key_label: Label = Label.new()
key_label.text = stat
key_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
key_label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
# Create label for value
var value_label: Label = Label.new()
value_label.text = debug_stats[stat]
value_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
value_label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
gc.add_child(key_label)
gc.add_child(value_label)