Save/Load System done
This commit is contained in:
@@ -1,36 +1,91 @@
|
||||
extends CanvasLayer
|
||||
|
||||
@onready var next = $UI/SkipContainer/NextButton
|
||||
@onready var confirmation_dialog = $UI/ConfirmationDialog
|
||||
@onready var confirmation_text = $UI/ConfirmationDialog/MarginContainer/VBoxContainer/ConfirmationText
|
||||
@onready var confirmation_yes = $UI/ConfirmationDialog/MarginContainer/VBoxContainer/MarginContainer/HBoxContainer/YesButton
|
||||
@onready var confirmation_no = $UI/ConfirmationDialog/MarginContainer/VBoxContainer/MarginContainer/HBoxContainer/NoButton
|
||||
@onready var confirmation_mask = $ConfirmationMask
|
||||
|
||||
signal next_request
|
||||
signal next_slide
|
||||
signal save_slot_pressed(save_slot_number: int)
|
||||
signal load_slot_pressed(load_slot_number: int)
|
||||
signal main_menu_pressed
|
||||
|
||||
|
||||
var confirmation_dialog = preload("res://confirmation_dialog.tscn")
|
||||
|
||||
# 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)
|
||||
|
||||
#Setting up the Confirmation Dialog
|
||||
confirmation_yes.text = ("YES")
|
||||
confirmation_no.text = ("NO")
|
||||
UI.confirmation_yes.pressed.connect(func(): UI.confirmation_dialog.hide())
|
||||
UI.confirmation_yes.pressed.connect(func(): TransitionScreen.mask.visible = false)
|
||||
UI.confirmation_no.pressed.connect(func(): UI.confirmation_dialog.hide())
|
||||
UI.confirmation_no.pressed.connect(func(): TransitionScreen.mask.visible = false)
|
||||
#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/Back.pressed.connect(_on_back_pressed)
|
||||
$UI/LoadTitle/MarginContainer/VBoxContainer/Back.pressed.connect(_on_back_title_pressed)
|
||||
$UI/Settings/MarginContainer/VBoxContainer/Back.pressed.connect(_on_back_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))
|
||||
|
||||
#Load Title Slots Signals
|
||||
$UI/LoadTitle/MarginContainer/VBoxContainer/LoadSlot1.pressed.connect(func(): _on_load_slot_pressed(1))
|
||||
$UI/LoadTitle/MarginContainer/VBoxContainer/LoadSlot2.pressed.connect(func(): _on_load_slot_pressed(2))
|
||||
$UI/LoadTitle/MarginContainer/VBoxContainer/LoadSlot3.pressed.connect(func(): _on_load_slot_pressed(3))
|
||||
$UI/LoadTitle/MarginContainer/VBoxContainer/LoadSlot4.pressed.connect(func(): _on_load_slot_pressed(4))
|
||||
|
||||
#Hiding everything at start
|
||||
#self.hide()
|
||||
confirmation_dialog.hide()
|
||||
self.get_node("UI/UpperContainer").hide()
|
||||
self.get_node("UI/SkipContainer").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
|
||||
|
||||
|
||||
|
||||
@@ -54,6 +109,107 @@ func _on_next_request():
|
||||
|
||||
|
||||
|
||||
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()
|
||||
|
||||
|
||||
|
||||
#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/LoadTitle.hide()
|
||||
TransitionScreen.mask.visible = false
|
||||
|
||||
|
||||
|
||||
#Shows Settings Menu
|
||||
func _on_settings_pressed():
|
||||
$UI/Menu.hide()
|
||||
$UI/Settings.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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user