extends Control

var opened : bool = false
var menu_choice : int = 0
@onready var menu_list : Array = [
	%STORY,
	%"VS-COM",
	%"VS-MAN",
	%RECORD,
	%OPTION
]

func _process(delta: float) -> void:
	if Input.is_action_just_pressed("ui_menu"):
		opened = !opened
		%START.visible = !opened
		%Menu.visible = opened
		%SelectSound.play()
		if opened:
			menu_choice = 0
			switch_menu()
	
	if opened:
		if Input.is_action_just_pressed("ui_up"):
			menu_choice -= 1
			if menu_choice < 0:
				menu_choice = len(menu_list) - 1
			%SwitchSound.play()
			switch_menu()
		elif Input.is_action_just_pressed("ui_down"):
			menu_choice += 1
			if menu_choice >= len(menu_list):
				menu_choice = 0
			%SwitchSound.play()
			switch_menu()


func switch_menu() -> void:
	for child in %Menu.get_children():
		child.visible = false
	menu_list[menu_choice].visible = true
