promiscuity/game/scenes/UI/pause_menu.gd

52 lines
1.4 KiB
GDScript

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()