extends Control

@onready var btn_new: Button = $Center/V/BtnNew
@onready var btn_continue: Button = $Center/V/BtnContinue
@onready var btn_settings: Button = $Center/V/BtnSettings
@onready var btn_quit: Button = $Center/V/BtnQuit


func _ready() -> void:
	Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
	DialogManager.set_crosshair_visible(false)
	DialogManager.set_controls_hint("")
	DialogManager.set_date_time("", "")
	DialogManager.set_objective("")

	btn_new.pressed.connect(_on_new_game)
	btn_continue.pressed.connect(_on_continue)
	btn_quit.pressed.connect(_on_quit)
	btn_continue.disabled = not GameState.has_save()
	if not btn_continue.disabled:
		btn_continue.text = "Продолжить"
	btn_new.grab_focus()


func _on_new_game() -> void:
	GameState.reset()
	GameState.delete_save()
	SceneManager.go_room()


func _on_continue() -> void:
	if not GameState.load_game():
		return
	var target: String = GameState.last_scene_path
	if target == "" or not ResourceLoader.exists(target):
		target = SceneManager.SCENE_ACT1_ROOM
	SceneManager.change_scene(target)


func _on_quit() -> void:
	get_tree().quit()


func _input(event: InputEvent) -> void:
	if event is InputEventKey and event.pressed and event.keycode == KEY_ESCAPE:
		get_tree().quit()
