game: add debug stats panel
This commit is contained in:
@@ -3,6 +3,7 @@ extends Node
|
||||
signal sig_debug_camera_zoom(value: bool)
|
||||
signal sig_debug_god_mode(value: bool)
|
||||
signal sig_debug_enemy_god_mode(value: bool)
|
||||
signal sig_debug_stats_set(key: String, value: String)
|
||||
|
||||
const GROUP_ENEMY = "enemy"
|
||||
const GROUP_DAMAGEABLE = "damagable"
|
||||
|
@@ -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)
|
||||
|
@@ -8,4 +8,3 @@ extends Control
|
||||
func _ready() -> void:
|
||||
pause_ui.visible = false
|
||||
player_ui.visible = true
|
||||
debug_ui.visible = false
|
||||
|
@@ -17,7 +17,6 @@ script = ExtResource("1_3a826")
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="PauseUI" type="Control" parent="CanvasLayer"]
|
||||
visible = false
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
@@ -67,7 +66,6 @@ layout_mode = 2
|
||||
text = "Exit"
|
||||
|
||||
[node name="PlayerUI" type="Control" parent="CanvasLayer"]
|
||||
visible = false
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
@@ -93,6 +91,7 @@ anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
script = ExtResource("4_217l8")
|
||||
|
||||
[node name="PanelContainer" type="PanelContainer" parent="CanvasLayer/DebugUI"]
|
||||
@@ -101,6 +100,7 @@ offset_left = 37.0
|
||||
offset_top = 117.0
|
||||
offset_right = 317.0
|
||||
offset_bottom = 542.0
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/DebugUI/PanelContainer"]
|
||||
layout_mode = 2
|
||||
@@ -117,6 +117,21 @@ text = "God mode"
|
||||
layout_mode = 2
|
||||
text = "Enemy god mode"
|
||||
|
||||
[node name="StatsCheck" type="CheckButton" parent="CanvasLayer/DebugUI/PanelContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Show debug stats"
|
||||
|
||||
[node name="StatsContainer" type="PanelContainer" parent="CanvasLayer/DebugUI"]
|
||||
layout_mode = 0
|
||||
offset_left = 938.0
|
||||
offset_top = 142.0
|
||||
offset_right = 1236.0
|
||||
offset_bottom = 552.0
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/DebugUI/StatsContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[connection signal="pressed" from="CanvasLayer/PauseUI/CenterContainer/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/ResumeButton" to="CanvasLayer/PauseUI" method="_on_resume_button_pressed"]
|
||||
[connection signal="pressed" from="CanvasLayer/PauseUI/CenterContainer/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/NewGameBtuton" to="CanvasLayer/PauseUI" method="_on_new_game_btuton_pressed"]
|
||||
[connection signal="pressed" from="CanvasLayer/PauseUI/CenterContainer/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/OptionsButton" to="CanvasLayer/PauseUI" method="_on_options_button_pressed"]
|
||||
@@ -124,3 +139,4 @@ text = "Enemy god mode"
|
||||
[connection signal="toggled" from="CanvasLayer/DebugUI/PanelContainer/VBoxContainer/ZoomCheck" to="CanvasLayer/DebugUI" method="_on_zoom_check_toggled"]
|
||||
[connection signal="toggled" from="CanvasLayer/DebugUI/PanelContainer/VBoxContainer/GodModeCheck" to="CanvasLayer/DebugUI" method="_on_god_mode_check_toggled"]
|
||||
[connection signal="toggled" from="CanvasLayer/DebugUI/PanelContainer/VBoxContainer/EnemyGodModeCheck" to="CanvasLayer/DebugUI" method="_on_enemy_god_mode_check_toggled"]
|
||||
[connection signal="toggled" from="CanvasLayer/DebugUI/PanelContainer/VBoxContainer/StatsCheck" to="CanvasLayer/DebugUI" method="_on_stats_check_toggled"]
|
||||
|
Reference in New Issue
Block a user