extends Control

@onready var root = get_tree().get_root().get_child(0)
var queue_unpause = false

func _input(input: InputEvent):
    if input.is_action_pressed("pause") or input.is_action_pressed("rmb"):
        queue_unpause = true

func _process(_delta: float):
    if queue_unpause:
        unpause()
        queue_unpause = false

func unpause():
    if root.main_menu_beaten:
        get_tree().paused = false
    hide()

func _on_visibility_changed():
    if Input.get_connected_joypads().size() > 0:
        $"CenterContainer/Buttons/WindowMode/CenterContainer/OptionButton".grab_focus()
