extends Control

var main_menu_beaten: bool = false
var disable_wheat: bool = false
var disable_ai: bool = false

func _ready():
    $UILayer/MainMenu.find_child("Start", true, false).connect("pressed", beat_main_menu)
    $UILayer/MainMenu.find_child("Settings", true, false).connect("pressed", $PauseMenuLayer/PauseMenu.show)
    begin(false)

func begin(restart: bool):
    if restart:
        $MainLayer.remove_child($MainLayer.get_child(0))
        $MainLayer.add_child(preload("res://scene/core/main.tscn").instantiate())
    
    find_child("VictoryScreen", true, false).hide()
    find_child("DefeatScreen", true, false).hide()
    find_child("SpeedrunTimer", true, false).reset()
    main_menu_beaten = false
    get_tree().paused = true
    $"UILayer/UI".hide()
    $UILayer/MainMenu.show()

func _input(input: InputEvent):
    if input.is_action_pressed("pause") and !get_tree().paused:
        get_tree().paused = true
        $PauseMenuLayer/PauseMenu.show()

func beat_main_menu():
    get_tree().paused = false
    main_menu_beaten = true
    $"UILayer/UI".show()
    $UILayer/MainMenu.hide()
    $PauseMenuLayer/PauseMenu.set_process_input(true)
