game: move ui stuff to own folder

This commit is contained in:
2025-08-19 19:52:39 +02:00
parent 5e16c877d1
commit eec0e6a50f
10 changed files with 5 additions and 5 deletions

View 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

View File

@@ -0,0 +1 @@
uid://d2o6tqnqg2o25

View File

@@ -0,0 +1,11 @@
class_name MainUI
extends Control
@onready var pause_ui: PauseUI = $CanvasLayer/PauseUI
@onready var player_ui: PlayerUI = $CanvasLayer/PlayerUI
@onready var debug_ui: DebugUI = $CanvasLayer/DebugUI
func _ready() -> void:
pause_ui.visible = false
player_ui.visible = true

View File

@@ -0,0 +1 @@
uid://dcxc70fvu7kl2

View File

@@ -0,0 +1,172 @@
[gd_scene load_steps=5 format=3 uid="uid://b18uib08hvdpq"]
[ext_resource type="Script" uid="uid://dcxc70fvu7kl2" path="res://scenes/managers/ui/main_ui.gd" id="1_3a826"]
[ext_resource type="Script" uid="uid://sjnxf0hj3egp" path="res://scenes/managers/ui/pause_ui.gd" id="1_lke1m"]
[ext_resource type="Script" uid="uid://dbq74tvxtpfjc" path="res://scenes/managers/ui/player_ui.gd" id="3_gaipe"]
[ext_resource type="Script" uid="uid://d2o6tqnqg2o25" path="res://scenes/managers/ui/debug_ui.gd" id="4_217l8"]
[node name="MainUI" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_3a826")
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="PauseUI" type="Control" parent="CanvasLayer"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_lke1m")
[node name="CenterContainer" type="CenterContainer" parent="CanvasLayer/PauseUI"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="MarginContainer" type="MarginContainer" parent="CanvasLayer/PauseUI/CenterContainer"]
layout_mode = 2
[node name="PanelContainer" type="PanelContainer" parent="CanvasLayer/PauseUI/CenterContainer/MarginContainer"]
layout_mode = 2
[node name="MarginContainer" type="MarginContainer" parent="CanvasLayer/PauseUI/CenterContainer/MarginContainer/PanelContainer"]
layout_mode = 2
theme_override_constants/margin_left = 60
theme_override_constants/margin_top = 20
theme_override_constants/margin_right = 60
theme_override_constants/margin_bottom = 20
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/PauseUI/CenterContainer/MarginContainer/PanelContainer/MarginContainer"]
layout_mode = 2
[node name="ResumeButton" type="Button" parent="CanvasLayer/PauseUI/CenterContainer/MarginContainer/PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
text = "Resume"
[node name="NewGameBtuton" type="Button" parent="CanvasLayer/PauseUI/CenterContainer/MarginContainer/PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
text = "New Game"
[node name="OptionsButton" type="Button" parent="CanvasLayer/PauseUI/CenterContainer/MarginContainer/PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
text = "Options"
[node name="ExitButton" type="Button" parent="CanvasLayer/PauseUI/CenterContainer/MarginContainer/PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
text = "Exit"
[node name="PlayerUI" type="Control" parent="CanvasLayer"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
script = ExtResource("3_gaipe")
[node name="CenterContainer" type="CenterContainer" parent="CanvasLayer/PlayerUI"]
layout_mode = 0
offset_right = 1280.0
offset_bottom = 100.0
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/PlayerUI/CenterContainer"]
layout_mode = 2
[node name="ProgressBar" type="ProgressBar" parent="CanvasLayer/PlayerUI/CenterContainer/VBoxContainer"]
custom_minimum_size = Vector2(400, 0)
layout_mode = 2
[node name="ElapsedLabel" type="Label" parent="CanvasLayer/PlayerUI/CenterContainer/VBoxContainer"]
layout_mode = 2
text = "10:00:00"
horizontal_alignment = 2
[node name="DebugUI" type="Control" parent="CanvasLayer"]
layout_mode = 3
anchors_preset = 15
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"]
layout_mode = 0
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
[node name="ZoomCheck" type="CheckButton" parent="CanvasLayer/DebugUI/PanelContainer/VBoxContainer"]
layout_mode = 2
text = "Zoom out"
[node name="GodModeCheck" type="CheckButton" parent="CanvasLayer/DebugUI/PanelContainer/VBoxContainer"]
layout_mode = 2
text = "God mode"
[node name="EnemyGodModeCheck" type="CheckButton" parent="CanvasLayer/DebugUI/PanelContainer/VBoxContainer"]
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="MarginContainer" type="MarginContainer" parent="CanvasLayer/DebugUI/PanelContainer/VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
theme_override_constants/margin_left = 6
theme_override_constants/margin_right = 6
[node name="HBoxContainer" type="HBoxContainer" parent="CanvasLayer/DebugUI/PanelContainer/VBoxContainer/MarginContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="CanvasLayer/DebugUI/PanelContainer/VBoxContainer/MarginContainer/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
text = "Time scale"
[node name="TimeScaleSlider" type="HSlider" parent="CanvasLayer/DebugUI/PanelContainer/VBoxContainer/MarginContainer/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
max_value = 1.0
step = 0.1
value = 1.0
[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"]
[connection signal="pressed" from="CanvasLayer/PauseUI/CenterContainer/MarginContainer/PanelContainer/MarginContainer/VBoxContainer/ExitButton" to="CanvasLayer/PauseUI" method="_on_exit_button_pressed"]
[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"]
[connection signal="value_changed" from="CanvasLayer/DebugUI/PanelContainer/VBoxContainer/MarginContainer/HBoxContainer/TimeScaleSlider" to="CanvasLayer/DebugUI" method="_on_time_scale_slider_value_changed"]

View File

@@ -0,0 +1,32 @@
class_name PauseUI
extends Control
func _ready() -> void:
pass
func toggle_pause_ui() -> void:
if visible:
visible = false
Engine.time_scale = 1.0
return
visible = true
Engine.time_scale = 0
func _on_resume_button_pressed() -> void:
toggle_pause_ui()
func _on_options_button_pressed() -> void:
pass # Replace with function body.
func _on_exit_button_pressed() -> void:
get_tree().quit(0)
func _on_new_game_btuton_pressed() -> void:
var new_scene = load("res://scenes/main.tscn")
get_tree().change_scene_to_packed(new_scene)

View File

@@ -0,0 +1 @@
uid://sjnxf0hj3egp

View File

@@ -0,0 +1,18 @@
class_name PlayerUI
extends Control
@onready var hp_bar: ProgressBar = $CenterContainer/VBoxContainer/ProgressBar
@onready var elapsed_label: Label = $CenterContainer/VBoxContainer/ElapsedLabel
func set_hp(value: float):
hp_bar.value = value
func set_elapsed_time(value: float):
elapsed_label.text = format_time(value)
func format_time(seconds: float) -> String:
var total_ms = int(seconds * 1000.0)
var s = (total_ms / 1000) % 60
var m = (total_ms / 60000)
return "%02d:%02d" % [m, s]

View File

@@ -0,0 +1 @@
uid://dbq74tvxtpfjc