2025-11-16 23:11:51 +00:00
|
|
|
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
|
|
|
|
|
|
2026-07-01 23:47:03 +01:00
|
|
|
var _retire_button: Button = null
|
|
|
|
|
|
2025-11-16 23:11:51 +00:00
|
|
|
func _ready():
|
|
|
|
|
# Start hidden
|
|
|
|
|
hide()
|
|
|
|
|
is_visible = false
|
|
|
|
|
|
2026-07-01 23:47:03 +01:00
|
|
|
# Insert "Retire to Camp" between Resume and Exit - leave alive, bank everything
|
|
|
|
|
var vbox = get_node_or_null("Panel/MarginContainer/VBoxContainer")
|
|
|
|
|
var exit_button = get_node_or_null("Panel/MarginContainer/VBoxContainer/ExitButton")
|
|
|
|
|
if vbox and exit_button:
|
|
|
|
|
_retire_button = Button.new()
|
|
|
|
|
_retire_button.name = "RetireButton"
|
|
|
|
|
_retire_button.custom_minimum_size = Vector2(0, 50)
|
|
|
|
|
_retire_button.add_theme_color_override("font_color", Color.WHITE)
|
|
|
|
|
_retire_button.add_theme_color_override("font_hover_color", Color(1, 0.8, 0))
|
|
|
|
|
_retire_button.add_theme_font_size_override("font_size", 20)
|
|
|
|
|
_retire_button.pressed.connect(_on_retire_pressed)
|
|
|
|
|
vbox.add_child(_retire_button)
|
|
|
|
|
vbox.move_child(_retire_button, exit_button.get_index())
|
|
|
|
|
|
2025-11-16 23:11:51 +00:00
|
|
|
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()
|
2026-07-01 23:47:03 +01:00
|
|
|
_update_retire_button()
|
2025-11-16 23:11:51 +00:00
|
|
|
# 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
|
|
|
|
|
|
2026-07-01 23:57:38 +01:00
|
|
|
## Alive with an active run: retire (bank winnings).
|
|
|
|
|
## Dead but spectating a live session: plain trip home (settlement already done).
|
2026-07-01 23:47:03 +01:00
|
|
|
func _update_retire_button():
|
|
|
|
|
if not _retire_button:
|
|
|
|
|
return
|
2026-07-01 23:57:38 +01:00
|
|
|
if GameState.run_active and player and not player.is_dead:
|
|
|
|
|
_retire_button.visible = true
|
2026-07-01 23:47:03 +01:00
|
|
|
_retire_button.text = "Retire to Camp (+%dg)" % GameState.run_gold
|
2026-07-01 23:57:38 +01:00
|
|
|
elif multiplayer.multiplayer_peer != null and player and player.is_dead:
|
|
|
|
|
_retire_button.visible = true
|
|
|
|
|
_retire_button.text = "Back to Camp"
|
|
|
|
|
else:
|
|
|
|
|
_retire_button.visible = false
|
2026-07-01 23:47:03 +01:00
|
|
|
|
2025-11-16 23:11:51 +00:00
|
|
|
## Called when Resume button is clicked
|
|
|
|
|
func _on_resume_pressed():
|
|
|
|
|
toggle_menu()
|
|
|
|
|
|
2026-07-01 23:47:03 +01:00
|
|
|
## Walk out alive: bank all run gold, keep gear, return to the menu
|
|
|
|
|
func _on_retire_pressed():
|
|
|
|
|
GameState.retire_run()
|
|
|
|
|
|
|
|
|
|
multiplayer.multiplayer_peer = null
|
|
|
|
|
Network.players.clear()
|
|
|
|
|
|
|
|
|
|
if has_node("/root/HUD"):
|
|
|
|
|
get_node("/root/HUD").reset()
|
|
|
|
|
|
|
|
|
|
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
|
|
|
|
get_tree().reload_current_scene()
|
|
|
|
|
|
2025-11-16 23:11:51 +00:00
|
|
|
## Called when Exit button is clicked
|
|
|
|
|
func _on_exit_pressed():
|
2026-07-01 23:47:03 +01:00
|
|
|
# Leaving alive still banks your winnings (GameState also catches window close)
|
|
|
|
|
if GameState.run_active and player and not player.is_dead:
|
|
|
|
|
GameState.retire_run()
|
2025-11-16 23:11:51 +00:00
|
|
|
get_tree().quit()
|