171 lines
5.8 KiB
GDScript
171 lines
5.8 KiB
GDScript
extends CanvasLayer
|
|
|
|
#UI Elements
|
|
@onready var confirmation_mask = $ConfirmationMask
|
|
@onready var masks = $Masks
|
|
@onready var pause_menu = $PauseMenu
|
|
|
|
#GameOver Scenes
|
|
@onready var its_game_over = $ITSGameOverControl
|
|
|
|
#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
|
|
#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.hide()
|
|
|
|
#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
|
|
confirmation_mask.hide()
|
|
|
|
|
|
#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.hide())
|
|
choice_yes.pressed.connect(func(): choice_dialog.queue_free())
|
|
choice_no.pressed.connect(func(): confirmation_mask.hide())
|
|
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.show()
|
|
|
|
|
|
#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)
|
|
|