Refactored the pause menu to make it more consistent.

This commit is contained in:
2026-04-18 18:31:05 -05:00
parent 020ede82b6
commit 753a34abd5
7 changed files with 112 additions and 88 deletions
+51
View File
@@ -0,0 +1,51 @@
extends CanvasLayer
const START_SCREEN_SCENE := "res://scenes/UI/start_screen.tscn"
@onready var buttons_container = $CenterContainer/PanelContainer/MarginContainer/VBoxContainer
func _ready() -> void:
_register_focus_sounds()
func _input(event):
if event.is_action_pressed("ui_cancel"):
if get_tree().paused:
resume_game()
else:
pause_game()
func pause_game():
get_tree().paused = true
visible = true
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
func resume_game():
get_tree().paused = false
visible = false
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _on_quit_button_pressed():
get_tree().quit()
func _on_continue_button_pressed():
resume_game()
func _on_main_menu_button_pressed():
resume_game()
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
get_tree().change_scene_to_file(START_SCREEN_SCENE)
func _register_focus_sounds() -> void:
if buttons_container == null:
return
for child in buttons_container.get_children():
if child is BaseButton:
var button: BaseButton = child
if not button.is_connected("focus_entered", Callable(self, "_on_menu_item_focus")):
button.focus_entered.connect(_on_menu_item_focus)
if not button.is_connected("mouse_entered", Callable(self, "_on_menu_item_focus")):
button.mouse_entered.connect(_on_menu_item_focus)
func _on_menu_item_focus() -> void:
if MenuSfx:
MenuSfx.play_hover()
+1
View File
@@ -0,0 +1 @@
uid://ckh861smjghqc
+64
View File
@@ -0,0 +1,64 @@
[gd_scene format=3 uid="uid://dp6jk0k3o4v1u"]
[ext_resource type="Script" path="res://scenes/UI/pause_menu.gd" id="1_script"]
[ext_resource type="Theme" uid="uid://wpxmub0n2dr3" path="res://themes/button_theme.tres" id="2_theme"]
[node name="PauseMenu" type="CanvasLayer"]
process_mode = 3
visible = false
script = ExtResource("1_script")
[node name="Overlay" type="ColorRect" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0, 0, 0, 0.45098)
[node name="CenterContainer" type="CenterContainer" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="PanelContainer" type="PanelContainer" parent="CenterContainer"]
custom_minimum_size = Vector2(250, 0)
layout_mode = 2
[node name="MarginContainer" type="MarginContainer" parent="CenterContainer/PanelContainer"]
layout_mode = 2
theme_override_constants/margin_left = 20
theme_override_constants/margin_top = 20
theme_override_constants/margin_right = 20
theme_override_constants/margin_bottom = 20
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer/PanelContainer/MarginContainer"]
layout_mode = 2
theme_override_constants/separation = 10
[node name="TitleLabel" type="Label" parent="CenterContainer/PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 24
text = "Paused"
horizontal_alignment = 1
[node name="ContinueButton" type="Button" parent="CenterContainer/PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
theme = ExtResource("2_theme")
text = "Continue"
[node name="MainMenuButton" type="Button" parent="CenterContainer/PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
theme = ExtResource("2_theme")
text = "Main Menu"
[node name="QuitButton" type="Button" parent="CenterContainer/PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
theme = ExtResource("2_theme")
text = "Quit"
[connection signal="pressed" from="CenterContainer/PanelContainer/MarginContainer/VBoxContainer/ContinueButton" to="." method="_on_continue_button_pressed"]
[connection signal="pressed" from="CenterContainer/PanelContainer/MarginContainer/VBoxContainer/MainMenuButton" to="." method="_on_main_menu_button_pressed"]
[connection signal="pressed" from="CenterContainer/PanelContainer/MarginContainer/VBoxContainer/QuitButton" to="." method="_on_quit_button_pressed"]