extends Control @onready var submenu = $Submenu @onready var save = $Save @onready var load = $Load @onready var settings = $Settings @onready var menu_button = $MenuButton var ui_main # Called when the node enters the scene tree for the first time. func _ready() -> void: #Referencing main node ui_main = get_parent() reset() #Initial state menu_button.hide() #Connecting signals menu_button.pressed.connect(func(): if UI.in_title_screen == false and submenu.is_visible_in_tree() == false: submenu.show() ui_main.masks.mask.show() elif UI.in_title_screen == false and submenu.is_visible_in_tree(): reset() ui_main.masks.mask.hide() ) submenu.resume.pressed.connect(func(): reset() ui_main.masks.mask.hide() ) submenu.save.pressed.connect(func(): save.show()) submenu.load.pressed.connect(func(): load.show()) submenu.settings.pressed.connect(func(): settings.show()) submenu.main_menu.pressed.connect(self._on_main_menu_pressed) submenu.quit.pressed.connect(func(): get_tree().quit()) for i in range(1, Globals.save_slot_count + 1): #From 1 to 4, excludes the autosaveslot save.save_slot[i].pressed.connect(self._on_save_slot_pressed.bind(i)) load.load_slot[i].pressed.connect(self._on_load_slot_pressed.bind(i)) load.load_slot[0].pressed.connect(self._on_load_slot_pressed.bind(0)) #Autosaveslot can be loaded but not saved upon #Opens the submenu when the escape key is pressed func _unhandled_input(event: InputEvent) -> void: if event.is_action_pressed("ui_cancel") and UI.in_title_screen == false and submenu.is_visible_in_tree() == false: submenu.show() ui_main.masks.mask.show() elif event.is_action_pressed("ui_cancel") and UI.in_title_screen == false and submenu.is_visible_in_tree(): reset() ui_main.masks.mask.hide() #Emits save_slot signal func _on_save_slot_pressed(save_slot_number: int): var save_slot = save.save_slot[save_slot_number] #Asking for confirmation if replacing existing save if save_slot.text != "EMPTY": var lambda = func(): ui_main.save_slot_pressed.emit(save_slot_number) var choice_text = "[center]Replace existing save ?[/center]" ui_main.ask_confirmation(lambda, Callable(), choice_text) else: ui_main.save_slot_pressed.emit(save_slot_number) #Emits load_slot signal func _on_load_slot_pressed(load_slot_number: int): var load_slot = load.load_slot[load_slot_number] #Asking for confirmation before loading if load_slot.text != "EMPTY": var lambda = func(): ui_main.load_slot_pressed.emit(load_slot_number) var choice_text = "[center]Load save ? Any unsaved games will be lost.[/center]" ui_main.ask_confirmation(lambda, Callable(), choice_text) else: pass #Going back to main menu func _on_main_menu_pressed(): #Asking for confirmation var lambda = func(): ui_main.main_menu_pressed.emit() var choice_text = "[center]Go back to main menu ? Unsaved changes will be lost.[/center]" ui_main.ask_confirmation(lambda, Callable(), choice_text) #Resets to initial state func reset(): show() #Hiding everything except the menu button for node in [submenu, save, load, settings]: node.hide()