game: move ui stuff to own folder
This commit is contained in:
76
scenes/managers/ui/debug_ui.gd
Normal file
76
scenes/managers/ui/debug_ui.gd
Normal file
@@ -0,0 +1,76 @@
|
||||
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():
|
||||
panel_container.visible = !panel_container.visible
|
||||
|
||||
|
||||
func _on_zoom_check_toggled(toggled_on: bool) -> void:
|
||||
GlobalConst.sig_debug_camera_zoom.emit(toggled_on)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
func _on_time_scale_slider_value_changed(value: float) -> void:
|
||||
Engine.time_scale = value
|
Reference in New Issue
Block a user