UI code reorganizing

This commit is contained in:
2026-03-04 00:24:25 +01:00
parent 75d130fc88
commit 150fffadb9
17 changed files with 349 additions and 416 deletions
+6 -142
View File
@@ -1,16 +1,13 @@
extends CanvasLayer
#UI Elements
@onready var next = $UI/SkipContainer/NextButton
@onready var confirmation_mask = $ConfirmationMask
@onready var masks = $Masks
@onready var pause_menu = $PauseMenu
#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)
@@ -56,35 +53,6 @@ var resolution_list: Dictionary = {
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)
@@ -97,7 +65,7 @@ func _ready() -> void:
#Initializes the auto-advance to false
autoplay.button_pressed = false
auto_mask.visible = true
auto_mask.hide()
#Screen settings signals and initialization
display_button.item_selected.connect(_on_display_selected)
@@ -108,9 +76,7 @@ func _ready() -> void:
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
confirmation_mask.hide()
#Brings up a Confirmation Dialog
@@ -124,9 +90,9 @@ func ask_confirmation(function_yes: Callable, function_no: Callable, choice_text
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(): confirmation_mask.hide())
choice_yes.pressed.connect(func(): choice_dialog.queue_free())
choice_no.pressed.connect(func(): confirmation_mask.visible = false)
choice_no.pressed.connect(func(): confirmation_mask.hide())
choice_no.pressed.connect(func(): choice_dialog.queue_free())
choice_yes.text = ("YES")
@@ -139,109 +105,7 @@ func ask_confirmation(function_yes: Callable, function_no: Callable, choice_text
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
confirmation_mask.show()
#Changes text_speed value