extends CanvasLayer #UI Elements @onready var next = $UI/SkipContainer/NextButton @onready var confirmation_mask = $ConfirmationMask @onready var masks = $Masks #GameOver Scenes @onready var its_game_over = $ITSGameOverControl #Signals for progressing through slides signal next_slide #Signals for saving and loading signal save_slot_pressed(save_slot_number: int) signal load_slot_pressed(load_slot_number: int) #Signal for going back to main menu signal main_menu_pressed #Preloading Confirmation dialog var confirmation_dialog = preload("res://Scenes/UI/confirmation_dialog.tscn") #Text settings UI nodes @export var text_slider: Node @export var auto_slider: Node @export var text_counter: Node @export var auto_counter: Node @export var autoplay: Node @export var auto_mask: ColorRect #Vars and signals for handling text settings var text_speed: float var auto_speed: float var is_auto = false signal text_value_changed signal auto_value_changed #Screen settings UI nodes @export var display_button: Node @export var resolution_button: Node var screen_size = DisplayServer.screen_get_size(DisplayServer.window_get_current_screen()) #Computer screen size var resolution_size = DisplayServer.screen_get_size(DisplayServer.window_get_current_screen()) #Used for changing screen resolution var resolution_list: Dictionary = { 0: Vector2i(800,600), 1: Vector2i(1024,768), 2: Vector2i(1280,720), 3: Vector2i(1366,768), 4: Vector2i(1440,900), 5: Vector2i(1600,900), 6: Vector2i(1680,1050), 7: Vector2i(1920,1080) } # Called when the node enters the scene tree for the first time. func _ready() -> void: #Connecting signals #GameOver Signals #Menu Signals $UI/UpperContainer/Menu.pressed.connect(_on_menu_pressed) $UI/Menu/MarginContainer/VBoxContainer/Resume.pressed.connect(_on_resume_pressed) $UI/Menu/MarginContainer/VBoxContainer/Save.pressed.connect(_on_save_pressed) $UI/Menu/MarginContainer/VBoxContainer/Load.pressed.connect(_on_load_pressed) $UI/Menu/MarginContainer/VBoxContainer/Settings.pressed.connect(_on_settings_pressed) $UI/Menu/MarginContainer/VBoxContainer/MainMenu.pressed.connect(_on_main_menu_pressed) $UI/Menu/MarginContainer/VBoxContainer/Quit.pressed.connect(_on_quit_game_pressed) $UI/Save/MarginContainer/VBoxContainer/Back.pressed.connect(_on_back_pressed) $UI/Load/MarginContainer/VBoxContainer/Control/Back.pressed.connect(_on_back_pressed) $UI/Load/MarginContainer/VBoxContainer/Control/BackTitle.pressed.connect(_on_back_title_pressed) $UI/Settings/MarginContainer/VBoxContainer/Control/Back.pressed.connect(_on_back_pressed) $UI/Settings/MarginContainer/VBoxContainer/Control/BackTitle.pressed.connect(_on_back_title_pressed) #Save Slots Signals $UI/Save/MarginContainer/VBoxContainer/SaveSlot1.pressed.connect(func(): _on_save_slot_pressed(1)) $UI/Save/MarginContainer/VBoxContainer/SaveSlot2.pressed.connect(func(): _on_save_slot_pressed(2)) $UI/Save/MarginContainer/VBoxContainer/SaveSlot3.pressed.connect(func(): _on_save_slot_pressed(3)) $UI/Save/MarginContainer/VBoxContainer/SaveSlot4.pressed.connect(func(): _on_save_slot_pressed(4)) #Load Slots Signals $UI/Load/MarginContainer/VBoxContainer/LoadSlot1.pressed.connect(func(): _on_load_slot_pressed(1)) $UI/Load/MarginContainer/VBoxContainer/LoadSlot2.pressed.connect(func(): _on_load_slot_pressed(2)) $UI/Load/MarginContainer/VBoxContainer/LoadSlot3.pressed.connect(func(): _on_load_slot_pressed(3)) $UI/Load/MarginContainer/VBoxContainer/LoadSlot4.pressed.connect(func(): _on_load_slot_pressed(4)) #Text settings signals text_slider.value_changed.connect(_on_text_value_changed) auto_slider.value_changed.connect(_on_auto_value_changed) autoplay.pressed.connect(_on_autoplay_pressed) text_speed = 0.1 / text_slider.value auto_speed = 0.4 * auto_slider.value text_counter.text = "[center]" + str(snapped((text_speed * 1000), 1)) + " ms/letter[/center]" auto_counter.text = "[center]" + str(snapped(auto_speed, 0.01)) + " s delay[/center]" #Initializes the auto-advance to false autoplay.button_pressed = false auto_mask.visible = true #Screen settings signals and initialization display_button.item_selected.connect(_on_display_selected) resolution_button.item_selected.connect(_on_resolution_selected) for index in resolution_list: var item_text = str(resolution_list[index].x) + "x" + str(resolution_list[index].y) resolution_button.add_item(item_text, index) resolution_button.select(resolution_list.find_key(screen_size)) #Selects the computer resolution as initial screen resolution #Hiding everything at start for node in $UI.get_children(): node.hide() confirmation_mask.visible = false #Brings up a Confirmation Dialog func ask_confirmation(function_yes: Callable, function_no: Callable, choice_text: String): var choice_dialog = confirmation_dialog.instantiate() add_child(choice_dialog) var choice_text_label = choice_dialog.get_node("ConfirmationDialog/MarginContainer/VBoxContainer/ConfirmationText") var choice_yes = choice_dialog.get_node("ConfirmationDialog/MarginContainer/VBoxContainer/MarginContainer/HBoxContainer/YesButton") var choice_no = choice_dialog.get_node("ConfirmationDialog/MarginContainer/VBoxContainer/MarginContainer/HBoxContainer/NoButton") #Clears the Confirmation Dialog and Remove the Mask no matter what choice is made choice_yes.pressed.connect(func(): confirmation_mask.visible = false) choice_yes.pressed.connect(func(): choice_dialog.queue_free()) choice_no.pressed.connect(func(): confirmation_mask.visible = false) choice_no.pressed.connect(func(): choice_dialog.queue_free()) choice_yes.text = ("YES") choice_no.text = ("NO") choice_text_label.text = choice_text #Connects Choices to their Functions choice_yes.pressed.connect(function_yes, CONNECT_ONE_SHOT) if function_no.is_valid(): choice_no.pressed.connect(function_no, CONNECT_ONE_SHOT) choice_dialog.show() confirmation_mask.visible = true func _on_menu_pressed(): UI.masks.mask.visible = true $UI/Menu.show() #Back to the game func _on_resume_pressed(): UI.masks.mask.visible = false $UI/Menu.hide() #Shows Save Slots func _on_save_pressed(): $UI/Menu.hide() $UI/Save.show() #Shows Load Slots func _on_load_pressed(): $UI/Menu.hide() $UI/Load.show() $UI/Load/MarginContainer/VBoxContainer/Control/BackTitle.hide() $UI/Load/MarginContainer/VBoxContainer/Control/Back.show() #Goes back to Menu func _on_back_pressed(): $UI/Save.hide() $UI/Load.hide() $UI/Settings.hide() $UI/Menu.show() #Goes back to title screen func _on_back_title_pressed(): $UI/Load.hide() $UI/Settings.hide() UI.masks.mask.visible = false #Shows Settings Menu func _on_settings_pressed(): $UI/Menu.hide() $UI/Settings.show() $UI/Settings/MarginContainer/VBoxContainer/Control/BackTitle.hide() $UI/Settings/MarginContainer/VBoxContainer/Control/Back.show() #Goes back to the main menu func _on_main_menu_pressed(): #Asking for confirmation var lambda = func(): main_menu_pressed.emit() var choice_text = "[center]Go back to main menu ? Unsaved changes will be lost.[/center]" ask_confirmation(lambda, Callable(), choice_text) #Quits the game func _on_quit_game_pressed(): get_tree().quit() #Emits save_slot signal func _on_save_slot_pressed(save_slot_number: int): var save_slot_path = "UI/Save/MarginContainer/VBoxContainer/SaveSlot" + str(save_slot_number) var save_slot = UI.get_node(save_slot_path) #Asking for confirmation if replacing existing save if save_slot.text != "EMPTY": var lambda = func(): save_slot_pressed.emit(save_slot_number) var choice_text = "[center]Replace existing save ?[/center]" ask_confirmation(lambda, Callable(), choice_text) else: save_slot_pressed.emit(save_slot_number) #Emits load_slot signal func _on_load_slot_pressed(load_slot_number: int): var load_slot_path = "UI/Load/MarginContainer/VBoxContainer/LoadSlot" + str(load_slot_number) var load_slot = UI.get_node(load_slot_path) #Asking for confirmation before loading if load_slot.text != "EMPTY": var lambda = func(): load_slot_pressed.emit(load_slot_number) var choice_text = "[center]Load save ? Any unsaved games will be lost.[/center]" ask_confirmation(lambda, Callable(), choice_text) else: pass #Changes text_speed value func _on_text_value_changed(new_value: float): text_speed = 0.1 / new_value text_counter.text = "[center]" + str(snapped((text_speed * 1000), 1)) + " ms/letter[/center]" text_value_changed.emit() #Changes auto_speed value func _on_auto_value_changed(new_value: float): auto_speed = 0.4 * new_value auto_counter.text = "[center]" + str(snapped(auto_speed, 0.01)) + " s delay[/center]" auto_value_changed.emit() #Toggles auto-advance func _on_autoplay_pressed(): if autoplay.button_pressed: is_auto = true auto_mask.visible = false else: is_auto = false auto_mask.visible = true #Shows selected display func _on_display_selected(index: int): match index: 0: DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_BORDERLESS, false) #Puts the windowed screen in the center of the computer's screen var screen_center = screen_size / 2 var top_left = screen_center - (resolution_size / 2) DisplayServer.window_set_size(resolution_size) await get_tree().process_frame #Waits process_frame to avoid bugs DisplayServer.window_set_position(top_left) 1: DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_MAXIMIZED) DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_BORDERLESS, true) 2: DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN) print("window setting changed") #Shows selected resolution func _on_resolution_selected(index: int): resolution_size = resolution_list.get(index) DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_BORDERLESS, false) #Puts the windowed screen in the center of the computer's screen var screen_center = screen_size / 2 var top_left = screen_center - (resolution_size / 2) DisplayServer.window_set_size(resolution_size) await get_tree().process_frame #Waits process_frame to avoid bugs DisplayServer.window_set_position(top_left)