MultiplayerFighter
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.0 KiB

extends Control
class_name EscapeMenu
## Escape menu that opens when Escape is pressed
## Allows player to exit the game or resume playing
# Visibility
var is_visible: bool = false
# Player reference (to control mouse mode)
var player: Character = null
func _ready():
# Start hidden
hide()
is_visible = false
func _input(event):
# Toggle on Escape press
if event.is_action_pressed("quit"):
toggle_menu()
get_viewport().set_input_as_handled()
## Set the player reference
func set_player(p: Character):
player = p
## Toggle menu visibility
func toggle_menu():
is_visible = !is_visible
if is_visible:
show()
# Release mouse when opening menu
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
else:
hide()
# Recapture mouse when closing menu
if player and player.is_multiplayer_authority():
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
## Called when Resume button is clicked
func _on_resume_pressed():
toggle_menu()
## Called when Exit button is clicked
func _on_exit_pressed():
get_tree().quit()