267 lines
8.1 KiB
GDScript
267 lines
8.1 KiB
GDScript
extends CanvasLayer
|
|
|
|
@onready var next = $UI/SkipContainer/NextButton
|
|
@onready var confirmation_mask = $ConfirmationMask
|
|
|
|
#Signals for progressing through slides
|
|
signal next_request
|
|
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://confirmation_dialog.tscn")
|
|
|
|
#Text settings sliders
|
|
@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
|
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
|
|
#Connecting signals
|
|
#Next Signals
|
|
next.pressed.connect(_on_next_pressed)
|
|
self.connect("next_request", _on_next_request)
|
|
|
|
#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
|
|
|
|
#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
|
|
|
|
|
|
|
|
#Requests next when the Next Button is pressed
|
|
func _on_next_pressed():
|
|
next_request.emit()
|
|
|
|
|
|
|
|
#Requests next when the space key is pressed
|
|
func _input(event):
|
|
if event is InputEventKey and event.is_action_released("ui_accept"):
|
|
next_request.emit()
|
|
|
|
|
|
|
|
#Makes sure fading transitions are done before approving a next request
|
|
func _on_next_request():
|
|
if Globals.is_transitioning == false:
|
|
next_slide.emit()
|
|
|
|
|
|
|
|
func _on_menu_pressed():
|
|
TransitionScreen.mask.visible = true
|
|
$UI/Menu.show()
|
|
|
|
|
|
|
|
#Back to the game
|
|
func _on_resume_pressed():
|
|
TransitionScreen.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()
|
|
TransitionScreen.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
|
|
|