Save/Load System done

This commit is contained in:
2025-06-15 20:53:10 +02:00
parent 2e4bf232b8
commit fb74a1cd10
11 changed files with 653 additions and 149 deletions
+1
View File
@@ -0,0 +1 @@
{"day_count":1,"patient_count":1,"patient_id":"564","save_date":"06/15/2025, 20:48"}
+1
View File
@@ -0,0 +1 @@
{"day_count":2,"patient_count":2,"patient_id":"564","save_date":"06/15/2025, 18:28"}
+1
View File
@@ -0,0 +1 @@
{"day_count":3,"patient_count":1,"patient_id":"564","save_date":"06/15/2025, 18:28"}
+1
View File
@@ -0,0 +1 @@
{"day_count":4,"patient_count":1,"patient_id":"564","save_date":"06/15/2025, 18:29"}
+71 -6
View File
@@ -1,8 +1,73 @@
[gd_scene load_steps=2 format=3 uid="uid://c0kyheol06kes"] [gd_scene load_steps=3 format=3 uid="uid://c0kyheol06kes"]
[ext_resource type="Theme" uid="uid://dn1n15xwt8ucv" path="res://Art/DialogTheme.tres" id="1_pvdac"] [ext_resource type="FontFile" uid="uid://ckg5x0oonnjtn" path="res://Art/XanhMono-Regular.ttf" id="1_6let0"]
[node name="ConfirmationDialog" type="ConfirmationDialog"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jjq8m"]
initial_position = 1 border_width_left = 2
size = Vector2i(300, 100) border_width_top = 2
theme = ExtResource("1_pvdac") border_width_right = 2
border_width_bottom = 2
border_color = Color(0.629675, 0.629675, 0.629674, 1)
[node name="ConfirmationDialog" type="CanvasLayer"]
layer = 128
[node name="ConfirmationDialog" type="PanelContainer" parent="."]
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -200.0
offset_top = -75.0
offset_right = 300.0
offset_bottom = 85.0
grow_horizontal = 2
grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_jjq8m")
[node name="Background" type="ColorRect" parent="ConfirmationDialog"]
layout_mode = 2
color = Color(0, 0, 0, 1)
[node name="MarginContainer" type="MarginContainer" parent="ConfirmationDialog"]
layout_mode = 2
theme_override_constants/margin_left = 10
theme_override_constants/margin_top = 20
theme_override_constants/margin_right = 10
theme_override_constants/margin_bottom = 10
[node name="VBoxContainer" type="VBoxContainer" parent="ConfirmationDialog/MarginContainer"]
layout_mode = 2
[node name="ConfirmationText" type="RichTextLabel" parent="ConfirmationDialog/MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
size_flags_stretch_ratio = 3.0
theme_override_fonts/normal_font = ExtResource("1_6let0")
theme_override_font_sizes/normal_font_size = 25
bbcode_enabled = true
[node name="MarginContainer" type="MarginContainer" parent="ConfirmationDialog/MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
theme_override_constants/margin_left = 70
theme_override_constants/margin_right = 70
[node name="HBoxContainer" type="HBoxContainer" parent="ConfirmationDialog/MarginContainer/VBoxContainer/MarginContainer"]
layout_mode = 2
theme_override_constants/separation = 70
[node name="YesButton" type="Button" parent="ConfirmationDialog/MarginContainer/VBoxContainer/MarginContainer/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
theme_override_fonts/font = ExtResource("1_6let0")
theme_override_font_sizes/font_size = 20
text = "YES"
[node name="NoButton" type="Button" parent="ConfirmationDialog/MarginContainer/VBoxContainer/MarginContainer/HBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
theme_override_fonts/font = ExtResource("1_6let0")
theme_override_font_sizes/font_size = 20
text = "NO"
+11 -2
View File
@@ -2,8 +2,8 @@ extends Node
var is_transitioning = false var is_transitioning = false
var day_count = 1 var day_count = 1
var patient_count = 0 var patient_count = 1
var daily_patient_limit = 2 var daily_patient_limit = 3
var patient_id = "564" var patient_id = "564"
var dialogue_intro = load("res://Dialogues/intro.dialogue") var dialogue_intro = load("res://Dialogues/intro.dialogue")
var dialogue_recovery = load("res://Dialogues/recovery.dialogue") var dialogue_recovery = load("res://Dialogues/recovery.dialogue")
@@ -15,6 +15,15 @@ func _ready() -> void:
func get_save_date() -> String:
var dt = Time.get_datetime_dict_from_system()
return "%02d/%02d/%04d, %02d:%02d" % [
dt.month, dt.day, dt.year,
dt.hour, dt.minute
]
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void: func _process(delta: float) -> void:
pass pass
+118 -59
View File
@@ -35,11 +35,13 @@ func _ready() -> void:
#Connecting Signals #Connecting Signals
title_screen.connect("new_game_pressed", self._on_new_game_pressed) title_screen.connect("new_game_pressed", self._on_new_game_pressed)
title_screen.connect("load_pressed", self._on_load_pressed) UI.connect("save_slot_pressed", self._on_save_slot_pressed)
title_screen.connect("settings_pressed", self._on_settings_pressed) UI.connect("load_slot_pressed", self._on_load_slot_pressed)
UI.connect("main_menu_pressed", self._on_main_menu_pressed)
screening_desk.connect("recovery_pressed", self._on_recovery_pressed) screening_desk.connect("recovery_pressed", self._on_recovery_pressed)
pass #Updating Save/Load Slots Information based on Existing Saves
update_slots()
@@ -51,35 +53,17 @@ func _process(delta: float) -> void:
# Starts a new game # Starts a new game
func _on_new_game_pressed(): func _on_new_game_pressed():
Globals.day_count = 1
#Offering to skip Introduction #Offering to skip the introduction
UI.confirmation_text.text = "[center]Do you wish to skip the introduction ?[/center]" var choice_text = "[center]Do you wish to skip the introduction ?[/center]"
UI.confirmation_yes.pressed.connect(skip_intro, CONNECT_ONE_SHOT) UI.ask_confirmation(start_day, play_intro, choice_text)
UI.confirmation_no.pressed.connect(play_intro, CONNECT_ONE_SHOT)
UI.confirmation_dialog.show()
TransitionScreen.mask.visible = true
#Skips the introduction
func skip_intro():
#Disconnecting the other Signal from the Confirmation Dialogue
UI.confirmation_no.disconnect("pressed", play_intro)
#Starting Day Loop
start_day_loop()
#Plays the entire introduction #Plays the entire introduction
func play_intro(): func play_intro():
#Disconnecting the other Signal from the Confirmation Dialogue #Text Slides
UI.confirmation_yes.disconnect("pressed", skip_intro)
#Playing the Intro
#Text Slides
var text_container = $TextScreens/MarginContainer/IntroBoxContainer/TextContainer var text_container = $TextScreens/MarginContainer/IntroBoxContainer/TextContainer
TransitionScreen.transition("big", [$TitleScreen], [$TextScreens, $TextScreens/MarginContainer/IntroBoxContainer/Header, text_container.get_child(0), UI, UI.get_node("UI/SkipContainer")]) TransitionScreen.transition("big", [$TitleScreen], [$TextScreens, $TextScreens/MarginContainer/IntroBoxContainer/Header, text_container.get_child(0), UI, UI.get_node("UI/SkipContainer")])
@@ -88,74 +72,71 @@ func play_intro():
TransitionScreen.transition("small", [text_container.get_child(i)], [text_container.get_child(i+1)]) TransitionScreen.transition("small", [text_container.get_child(i)], [text_container.get_child(i+1)])
await UI.next_slide await UI.next_slide
#Meeting Room Dialogue #Meeting room dialogue
TransitionScreen.transition("big", [$TextScreens, $TextScreens/MarginContainer, text_container.get_child(4), UI, UI.get_node("UI/SkipContainer")], [$DialogueScreens]) TransitionScreen.transition("big", [$TextScreens, $TextScreens/MarginContainer, text_container.get_child(4), UI, UI.get_node("UI/SkipContainer")], [$DialogueScreens])
await TransitionScreen.transition_finished await TransitionScreen.transition_finished
DialogueManager.show_dialogue_balloon(Globals.dialogue_intro, "start") DialogueManager.show_dialogue_balloon(Globals.dialogue_intro, "start")
await DialogueManager.dialogue_ended await DialogueManager.dialogue_ended
#Starting Day Loop #Starting the day
start_day_loop() start_day()
#Starts the Day Loop #Starts the day
func start_day_loop(): func start_day():
#Transitioning to Day Screen #Transitioning to day screen
$TextScreens/Day.text = "[center]DAY " + str(Globals.day_count) + "[/center]" $TextScreens/Day.text = "[center]DAY " + str(Globals.day_count) + "[/center]"
TransitionScreen.transition("big", [$DialogueScreens, $TitleScreen], [$TextScreens, $TextScreens/Day])
var scenes_to_hide: Array[Node] = [$DialogueScreens, $TitleScreen, $Bedroom]
var scenes_to_show: Array[Node] = [$TextScreens, $TextScreens/Day]
TransitionScreen.transition("big", scenes_to_hide, scenes_to_show)
await TransitionScreen.transition_finished await TransitionScreen.transition_finished
await get_tree().create_timer(3.0).timeout await get_tree().create_timer(3.0).timeout
#Transitioning to the Screening Desk #Transitioning to the screening desk
TransitionScreen.transition("big", [$TextScreens, $TextScreens/Day], [$ScreeningDesk, $ScreeningDesk.alone_controls, UI, UI.get_node("UI/UpperContainer")]) TransitionScreen.transition("big", [$TextScreens, $TextScreens/Day], [$ScreeningDesk, $ScreeningDesk.alone_controls, UI, UI.get_node("UI/UpperContainer")])
await TransitionScreen.transition_finished await TransitionScreen.transition_finished
#Finally starting the Game Loop #Setting up new patient
$ScreeningDesk.new_patient(Globals.patient_id) $ScreeningDesk.new_patient(Globals.patient_id)
#Ends the day and starts the next one
func _on_recovery_pressed(): func _on_recovery_pressed():
var scenes_to_hide = [$ScreeningDesk.end_of_day_controls, $ScreeningDesk] #Transitioning to the bedroom
var scenes_to_show:Array[Node] = [$Bedroom] var scenes_to_hide: Array[Node] = [$ScreeningDesk.end_of_day_controls, $ScreeningDesk]
var scenes_to_show: Array[Node] = [$Bedroom]
TransitionScreen.transition("big", scenes_to_hide, scenes_to_show) TransitionScreen.transition("big", scenes_to_hide, scenes_to_show)
await TransitionScreen.transition_finished await TransitionScreen.transition_finished
#End of day dialogue
DialogueManager.show_dialogue_balloon(Globals.dialogue_recovery, "end_of_day_" + str(Globals.day_count)) DialogueManager.show_dialogue_balloon(Globals.dialogue_recovery, "end_of_day_" + str(Globals.day_count))
await DialogueManager.dialogue_ended await DialogueManager.dialogue_ended
#Start of the next day
Globals.day_count += 1 Globals.day_count += 1
start_day()
#Transitioning to Day Screen
$TextScreens/Day.text = "[center]DAY " + str(Globals.day_count) + "[/center]"
scenes_to_hide = [$Bedroom]
scenes_to_show = [$TextScreens, $TextScreens/Day]
TransitionScreen.transition("big", scenes_to_hide, scenes_to_show)
await TransitionScreen.transition_finished
await get_tree().create_timer(3.0).timeout
#Transitioning to Screening Desk
scenes_to_hide = scenes_to_show
scenes_to_show = [$ScreeningDesk, $ScreeningDesk.alone_controls]
TransitionScreen.transition("big", scenes_to_hide, scenes_to_show)
await TransitionScreen.transition_finished
$ScreeningDesk.new_patient(Globals.patient_id)
func save_game(save_slot:String): #Saves game state on the selected save slot
func save_game(save_slot_number:int):
#Setting up save data
var save_data = { var save_data = {
"day_count": Globals.day_count, "day_count": Globals.day_count,
"patient_count": Globals.patient_count, "patient_count": Globals.patient_count,
"patient_id": Globals.patient_id "patient_id": Globals.patient_id,
"save_date": Globals.get_save_date()
} }
var file = FileAccess.open("res://Saves/save_" + save_slot + ".json", FileAccess.WRITE) #Creating save file
var file = FileAccess.open("res://Saves/save_" + str(save_slot_number) + ".json", FileAccess.WRITE)
if file: if file:
var json_string = JSON.stringify(save_data) var json_string = JSON.stringify(save_data)
print(json_string) print(json_string)
@@ -165,17 +146,34 @@ func save_game(save_slot:String):
else: else:
print("Failed to open file for saving.") print("Failed to open file for saving.")
#Updating save/load slots information
var save_slot_path = "UI/Save/MarginContainer/VBoxContainer/SaveSlot" + str(save_slot_number)
var load_slot_path = "UI/Load/MarginContainer/VBoxContainer/LoadSlot" + str(save_slot_number)
var save_slot = UI.get_node(save_slot_path)
var load_slot = UI.get_node(load_slot_path)
save_slot.text = "DAY " + str(save_data["day_count"]) + ", PATIENT " + str(save_data["patient_count"]) + "\nSAVE DATE : " + str(save_data["save_date"])
load_slot.text = save_slot.text
func load_game(save_slot:String):
var file = FileAccess.open("res://Saves/save_" + save_slot + ".json", FileAccess.READ) #Loads save file from the selected load slot
func load_game(load_slot_number:int):
#Hiding loading menus and masks
TransitionScreen.mask.visible = false
UI.get_node("UI/Load").hide()
UI.get_node("UI/LoadTitle").hide()
UI.get_node("UI/Menu").hide()
#Opening save file
var file = FileAccess.open("res://Saves/save_" + str(load_slot_number) + ".json", FileAccess.READ)
if file: if file:
var json_string = file.get_as_text() var json_string = file.get_as_text()
file.close() file.close()
var load_data = JSON.parse_string(json_string) var load_data = JSON.parse_string(json_string)
if load_data == OK: if typeof(load_data) == 27: #Checks if loaded data is a Dictionary
print(load_data) print(load_data)
Globals.day_count = load_data["day_count"] Globals.day_count = load_data["day_count"]
Globals.patient_count = load_data["patient_count"] Globals.patient_count = load_data["patient_count"]
@@ -183,7 +181,68 @@ func load_game(save_slot:String):
else: else:
print("Failed to parse Loading Data.") print("Failed to parse Loading Data.")
#Transitioning to loaded Save
var scenes_to_hide = [$TitleScreen, $Bedroom, $TextScreens, $TextScreens/Day, $ScreeningDesk.patient_controls, $ScreeningDesk.end_of_day_controls, $ScreeningDesk.patient_texture, $ScreeningDesk.panel_container, $ScreeningDesk.face_zoom] + $ScreeningDesk.margin_container.get_children()
var scenes_to_show = [$ScreeningDesk, $ScreeningDesk.alone_controls, UI.get_node("UI/UpperContainer")]
TransitionScreen.transition("big", scenes_to_hide, scenes_to_show)
await TransitionScreen.transition_finished
$ScreeningDesk.new_patient(Globals.patient_id)
func _on_save_pressed():
func _on_save_slot_pressed(save_slot):
save_game(save_slot)
func _on_load_slot_pressed(load_slot):
load_game(load_slot)
func _on_main_menu_pressed():
#Hiding menu
UI.get_node("UI/Menu").hide()
UI.get_node("UI/UpperContainer").hide()
TransitionScreen.mask.visible = false
#Going back to main menu
var scenes_to_hide = [$ScreeningDesk, $Bedroom, $TextScreens, $TextScreens/Day, $ScreeningDesk.patient_controls, $ScreeningDesk.end_of_day_controls, $ScreeningDesk.patient_texture, $ScreeningDesk.panel_container, $ScreeningDesk.face_zoom] + $ScreeningDesk.margin_container.get_children()
var scenes_to_show = [$TitleScreen]
TransitionScreen.transition("big", scenes_to_hide, scenes_to_show)
await TransitionScreen.transition_finished
#Updates Save/Load Slots based on Existing Saves
func update_slots():
#Loops over the 4 save/load slots
for save_number in range(1, 5):
#Retrieves save and load slots
var save_slot_path = "UI/Save/MarginContainer/VBoxContainer/SaveSlot" + str(save_number)
var load_slot_path = "UI/Load/MarginContainer/VBoxContainer/LoadSlot" + str(save_number)
var load_title_slot_path = "UI/LoadTitle/MarginContainer/VBoxContainer/LoadSlot" + str(save_number)
var save_slot = UI.get_node(save_slot_path)
var load_slot = UI.get_node(load_slot_path)
var load_title_slot = UI.get_node(load_title_slot_path)
#Retrieves save path
var save_path = "res://Saves/save_" + str(save_number) + ".json"
if FileAccess.file_exists(save_path):
var file = FileAccess.open(save_path, FileAccess.READ) #Loads the save if it exists
var json_string = file.get_as_text()
file.close()
var load_data = JSON.parse_string(json_string)
if typeof(load_data) == 27: #Checks if loaded data is a Dictionary
#Updates save and load slots texts
print(load_data)
save_slot.text = "DAY " + str(load_data["day_count"]) + ", PATIENT " + str(load_data["patient_count"]) + "\nSAVE DATE : " + str(load_data["save_date"])
load_slot.text = save_slot.text
load_title_slot.text = save_slot.text
else:
print("Failed to parse Loading Data.")
+8 -13
View File
@@ -178,24 +178,19 @@ func _change_emotion(dialogue_line) -> void:
func _on_containment_pressed(): func _on_containment_pressed():
#Asking for Confirmation
var lambda = func(): clear_patient("containment") var lambda = func(): clear_patient("containment")
UI.confirmation_text.text = "[center]Do you really want to send this patient to [color=darkred]Containment[/color] ?[/center]" var choice_text = "[center]Do you really want to send this patient to [color=darkred]Containment[/color] ?[/center]"
UI.confirmation_yes.pressed.connect(lambda, CONNECT_ONE_SHOT)
UI.confirmation_no.pressed.connect(func(): UI.confirmation_yes.disconnect("pressed", lambda)) UI.ask_confirmation(lambda, Callable(), choice_text)
UI.confirmation_dialog.show()
TransitionScreen.mask.visible = true
func _on_psych_ward_pressed(): func _on_psych_ward_pressed():
#Asking for Confirmation
var lambda = func(): clear_patient("psych_ward") var lambda = func(): clear_patient("psych_ward")
UI.confirmation_text.text = "[center]Do you really want to send this patient to the [color=darkgreen]Psych Ward[/color] ?[/center]" var choice_text = "[center]Do you really want to send this patient to the [color=darkgreen]Psych Ward[/color] ?[/center]"
UI.confirmation_yes.pressed.connect(lambda, CONNECT_ONE_SHOT)
UI.confirmation_no.pressed.connect(func(): UI.confirmation_yes.disconnect("pressed", lambda)) UI.ask_confirmation(lambda, Callable(), choice_text)
UI.confirmation_dialog.show()
TransitionScreen.mask.visible = true
@@ -244,7 +239,7 @@ func clear_patient(choice:String):
#Setting Up Next Patient #Setting Up Next Patient
new_patient("564") new_patient("564")
else: else:
Globals.patient_count = 0 Globals.patient_count = 1
#Starting End of Day Dialogue #Starting End of Day Dialogue
var start_title = "end_of_day_" + str(Globals.day_count) var start_title = "end_of_day_" + str(Globals.day_count)
+3 -4
View File
@@ -28,10 +28,9 @@ func _on_new_game_pressed() -> void:
func _on_load_pressed() -> void: func _on_load_pressed():
load_pressed.emit() UI.get_node("UI/LoadTitle").show()
pass TransitionScreen.mask.visible = true
func _on_settings_pressed() -> void: func _on_settings_pressed() -> void:
+169 -13
View File
@@ -1,36 +1,91 @@
extends CanvasLayer extends CanvasLayer
@onready var next = $UI/SkipContainer/NextButton @onready var next = $UI/SkipContainer/NextButton
@onready var confirmation_dialog = $UI/ConfirmationDialog @onready var confirmation_mask = $ConfirmationMask
@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
signal next_request signal next_request
signal next_slide 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. # Called when the node enters the scene tree for the first time.
func _ready() -> void: func _ready() -> void:
#Connecting signals #Connecting signals
#Next Signals
next.pressed.connect(_on_next_pressed) next.pressed.connect(_on_next_pressed)
self.connect("next_request", _on_next_request) self.connect("next_request", _on_next_request)
#Setting up the Confirmation Dialog #Menu Signals
confirmation_yes.text = ("YES") $UI/UpperContainer/Menu.pressed.connect(_on_menu_pressed)
confirmation_no.text = ("NO")
UI.confirmation_yes.pressed.connect(func(): UI.confirmation_dialog.hide()) $UI/Menu/MarginContainer/VBoxContainer/Resume.pressed.connect(_on_resume_pressed)
UI.confirmation_yes.pressed.connect(func(): TransitionScreen.mask.visible = false) $UI/Menu/MarginContainer/VBoxContainer/Save.pressed.connect(_on_save_pressed)
UI.confirmation_no.pressed.connect(func(): UI.confirmation_dialog.hide()) $UI/Menu/MarginContainer/VBoxContainer/Load.pressed.connect(_on_load_pressed)
UI.confirmation_no.pressed.connect(func(): TransitionScreen.mask.visible = false) $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 #Hiding everything at start
#self.hide() #self.hide()
confirmation_dialog.hide()
self.get_node("UI/UpperContainer").hide() self.get_node("UI/UpperContainer").hide()
self.get_node("UI/SkipContainer").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. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void: func _process(delta: float) -> void:
pass pass
+262 -45
View File
@@ -1,4 +1,4 @@
[gd_scene load_steps=6 format=3 uid="uid://dy40jygog8t3k"] [gd_scene load_steps=5 format=3 uid="uid://dy40jygog8t3k"]
[ext_resource type="Script" path="res://ui.gd" id="1_mg12k"] [ext_resource type="Script" path="res://ui.gd" id="1_mg12k"]
[ext_resource type="FontFile" uid="uid://ckg5x0oonnjtn" path="res://Art/XanhMono-Regular.ttf" id="2_cohu5"] [ext_resource type="FontFile" uid="uid://ckg5x0oonnjtn" path="res://Art/XanhMono-Regular.ttf" id="2_cohu5"]
@@ -10,15 +10,8 @@ border_width_top = 2
border_width_right = 2 border_width_right = 2
border_width_bottom = 2 border_width_bottom = 2
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_0joc6"]
border_width_left = 2
border_width_top = 2
border_width_right = 2
border_width_bottom = 2
border_color = Color(0.629675, 0.629675, 0.629674, 1)
[node name="UILayer" type="CanvasLayer"] [node name="UILayer" type="CanvasLayer"]
layer = 128 layer = 127
script = ExtResource("1_mg12k") script = ExtResource("1_mg12k")
[node name="UI" type="Control" parent="."] [node name="UI" type="Control" parent="."]
@@ -32,6 +25,7 @@ grow_vertical = 2
mouse_filter = 2 mouse_filter = 2
[node name="Menu" type="PanelContainer" parent="UI"] [node name="Menu" type="PanelContainer" parent="UI"]
visible = false
layout_mode = 1 layout_mode = 1
anchors_preset = 8 anchors_preset = 8
anchor_left = 0.5 anchor_left = 0.5
@@ -52,20 +46,20 @@ color = Color(0, 0, 0, 1)
[node name="MarginContainer" type="MarginContainer" parent="UI/Menu"] [node name="MarginContainer" type="MarginContainer" parent="UI/Menu"]
layout_mode = 2 layout_mode = 2
theme_override_constants/margin_left = 40 theme_override_constants/margin_left = 25
theme_override_constants/margin_top = 40 theme_override_constants/margin_top = 25
theme_override_constants/margin_right = 40 theme_override_constants/margin_right = 25
theme_override_constants/margin_bottom = 40 theme_override_constants/margin_bottom = 25
[node name="VBoxContainer" type="VBoxContainer" parent="UI/Menu/MarginContainer"] [node name="VBoxContainer" type="VBoxContainer" parent="UI/Menu/MarginContainer"]
layout_mode = 2 layout_mode = 2
[node name="Continue" type="Button" parent="UI/Menu/MarginContainer/VBoxContainer"] [node name="Resume" type="Button" parent="UI/Menu/MarginContainer/VBoxContainer"]
layout_mode = 2 layout_mode = 2
size_flags_vertical = 3 size_flags_vertical = 3
theme_override_fonts/font = ExtResource("2_cohu5") theme_override_fonts/font = ExtResource("2_cohu5")
theme_override_font_sizes/font_size = 27 theme_override_font_sizes/font_size = 27
text = "CONTINUE" text = "RESUME"
[node name="Save" type="Button" parent="UI/Menu/MarginContainer/VBoxContainer"] [node name="Save" type="Button" parent="UI/Menu/MarginContainer/VBoxContainer"]
layout_mode = 2 layout_mode = 2
@@ -81,12 +75,12 @@ theme_override_fonts/font = ExtResource("2_cohu5")
theme_override_font_sizes/font_size = 27 theme_override_font_sizes/font_size = 27
text = "LOAD" text = "LOAD"
[node name="Options" type="Button" parent="UI/Menu/MarginContainer/VBoxContainer"] [node name="Settings" type="Button" parent="UI/Menu/MarginContainer/VBoxContainer"]
layout_mode = 2 layout_mode = 2
size_flags_vertical = 3 size_flags_vertical = 3
theme_override_fonts/font = ExtResource("2_cohu5") theme_override_fonts/font = ExtResource("2_cohu5")
theme_override_font_sizes/font_size = 27 theme_override_font_sizes/font_size = 27
text = "OPTIONS" text = "SETTINGS"
[node name="MainMenu" type="Button" parent="UI/Menu/MarginContainer/VBoxContainer"] [node name="MainMenu" type="Button" parent="UI/Menu/MarginContainer/VBoxContainer"]
layout_mode = 2 layout_mode = 2
@@ -95,14 +89,14 @@ theme_override_fonts/font = ExtResource("2_cohu5")
theme_override_font_sizes/font_size = 27 theme_override_font_sizes/font_size = 27
text = "MAIN MENU" text = "MAIN MENU"
[node name="Exit" type="Button" parent="UI/Menu/MarginContainer/VBoxContainer"] [node name="Quit" type="Button" parent="UI/Menu/MarginContainer/VBoxContainer"]
layout_mode = 2 layout_mode = 2
size_flags_vertical = 3 size_flags_vertical = 3
theme_override_fonts/font = ExtResource("2_cohu5") theme_override_fonts/font = ExtResource("2_cohu5")
theme_override_font_sizes/font_size = 27 theme_override_font_sizes/font_size = 27
text = "EXIT GAME" text = "QUIT GAME"
[node name="ConfirmationDialog" type="PanelContainer" parent="UI"] [node name="Save" type="PanelContainer" parent="UI"]
visible = false visible = false
layout_mode = 1 layout_mode = 1
anchors_preset = 8 anchors_preset = 8
@@ -111,58 +105,272 @@ anchor_top = 0.5
anchor_right = 0.5 anchor_right = 0.5
anchor_bottom = 0.5 anchor_bottom = 0.5
offset_left = -200.0 offset_left = -200.0
offset_top = -75.0 offset_top = -300.0
offset_right = 300.0 offset_right = 200.0
offset_bottom = 85.0 offset_bottom = 300.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_0joc6") theme_override_styles/panel = SubResource("StyleBoxFlat_fo2i3")
[node name="Background" type="ColorRect" parent="UI/ConfirmationDialog"] [node name="Background" type="ColorRect" parent="UI/Save"]
layout_mode = 2 layout_mode = 2
color = Color(0, 0, 0, 1) color = Color(0, 0, 0, 1)
[node name="MarginContainer" type="MarginContainer" parent="UI/ConfirmationDialog"] [node name="MarginContainer" type="MarginContainer" parent="UI/Save"]
layout_mode = 2 layout_mode = 2
theme_override_constants/margin_left = 10 theme_override_constants/margin_left = 25
theme_override_constants/margin_top = 20 theme_override_constants/margin_top = 10
theme_override_constants/margin_right = 10 theme_override_constants/margin_right = 25
theme_override_constants/margin_bottom = 10 theme_override_constants/margin_bottom = 0
[node name="VBoxContainer" type="VBoxContainer" parent="UI/ConfirmationDialog/MarginContainer"] [node name="VBoxContainer" type="VBoxContainer" parent="UI/Save/MarginContainer"]
layout_mode = 2 layout_mode = 2
[node name="ConfirmationText" type="RichTextLabel" parent="UI/ConfirmationDialog/MarginContainer/VBoxContainer"] [node name="RichTextLabel" type="RichTextLabel" parent="UI/Save/MarginContainer/VBoxContainer"]
layout_mode = 2 layout_mode = 2
size_flags_vertical = 3 size_flags_vertical = 3
size_flags_stretch_ratio = 3.0
theme_override_fonts/normal_font = ExtResource("2_cohu5") theme_override_fonts/normal_font = ExtResource("2_cohu5")
theme_override_font_sizes/normal_font_size = 25 theme_override_font_sizes/normal_font_size = 30
bbcode_enabled = true bbcode_enabled = true
text = "
[center]SAVE GAME[/center]"
[node name="MarginContainer" type="MarginContainer" parent="UI/ConfirmationDialog/MarginContainer/VBoxContainer"] [node name="SaveSlot1" type="Button" parent="UI/Save/MarginContainer/VBoxContainer"]
layout_mode = 2 layout_mode = 2
size_flags_vertical = 3 size_flags_vertical = 3
theme_override_constants/margin_left = 70 theme_override_fonts/font = ExtResource("2_cohu5")
theme_override_constants/margin_right = 70 theme_override_font_sizes/font_size = 27
text = "EMPTY"
[node name="HBoxContainer" type="HBoxContainer" parent="UI/ConfirmationDialog/MarginContainer/VBoxContainer/MarginContainer"] [node name="SaveSlot2" type="Button" parent="UI/Save/MarginContainer/VBoxContainer"]
layout_mode = 2 layout_mode = 2
theme_override_constants/separation = 70 size_flags_vertical = 3
theme_override_fonts/font = ExtResource("2_cohu5")
theme_override_font_sizes/font_size = 27
text = "EMPTY"
[node name="YesButton" type="Button" parent="UI/ConfirmationDialog/MarginContainer/VBoxContainer/MarginContainer/HBoxContainer"] [node name="SaveSlot3" type="Button" parent="UI/Save/MarginContainer/VBoxContainer"]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_vertical = 3
theme_override_fonts/font = ExtResource("2_cohu5")
theme_override_font_sizes/font_size = 27
text = "EMPTY"
[node name="SaveSlot4" type="Button" parent="UI/Save/MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
theme_override_fonts/font = ExtResource("2_cohu5")
theme_override_font_sizes/font_size = 27
text = "EMPTY"
[node name="Back" type="Button" parent="UI/Save/MarginContainer/VBoxContainer"]
custom_minimum_size = Vector2(80, 40)
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 6
theme_override_fonts/font = ExtResource("2_cohu5") theme_override_fonts/font = ExtResource("2_cohu5")
theme_override_font_sizes/font_size = 20 theme_override_font_sizes/font_size = 20
text = "YES" text = "BACK"
[node name="NoButton" type="Button" parent="UI/ConfirmationDialog/MarginContainer/VBoxContainer/MarginContainer/HBoxContainer"] [node name="Load" type="PanelContainer" parent="UI"]
visible = false
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -200.0
offset_top = -300.0
offset_right = 200.0
offset_bottom = 300.0
grow_horizontal = 2
grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_fo2i3")
[node name="Background" type="ColorRect" parent="UI/Load"]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 color = Color(0, 0, 0, 1)
[node name="MarginContainer" type="MarginContainer" parent="UI/Load"]
layout_mode = 2
theme_override_constants/margin_left = 25
theme_override_constants/margin_top = 10
theme_override_constants/margin_right = 25
theme_override_constants/margin_bottom = 0
[node name="VBoxContainer" type="VBoxContainer" parent="UI/Load/MarginContainer"]
layout_mode = 2
[node name="RichTextLabel" type="RichTextLabel" parent="UI/Load/MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
theme_override_fonts/normal_font = ExtResource("2_cohu5")
theme_override_font_sizes/normal_font_size = 30
bbcode_enabled = true
text = "
[center]LOAD GAME[/center]"
[node name="LoadSlot1" type="Button" parent="UI/Load/MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
theme_override_fonts/font = ExtResource("2_cohu5")
theme_override_font_sizes/font_size = 27
text = "EMPTY"
[node name="LoadSlot2" type="Button" parent="UI/Load/MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
theme_override_fonts/font = ExtResource("2_cohu5")
theme_override_font_sizes/font_size = 27
text = "EMPTY"
[node name="LoadSlot3" type="Button" parent="UI/Load/MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
theme_override_fonts/font = ExtResource("2_cohu5")
theme_override_font_sizes/font_size = 27
text = "EMPTY"
[node name="LoadSlot4" type="Button" parent="UI/Load/MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
theme_override_fonts/font = ExtResource("2_cohu5")
theme_override_font_sizes/font_size = 27
text = "EMPTY"
[node name="Back" type="Button" parent="UI/Load/MarginContainer/VBoxContainer"]
custom_minimum_size = Vector2(80, 40)
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 6
theme_override_fonts/font = ExtResource("2_cohu5") theme_override_fonts/font = ExtResource("2_cohu5")
theme_override_font_sizes/font_size = 20 theme_override_font_sizes/font_size = 20
text = "NO" text = "BACK"
[node name="LoadTitle" type="PanelContainer" parent="UI"]
visible = false
layout_mode = 2
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -200.0
offset_top = -300.0
offset_right = 200.0
offset_bottom = 300.0
grow_horizontal = 2
grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_fo2i3")
[node name="Background" type="ColorRect" parent="UI/LoadTitle"]
layout_mode = 2
color = Color(0, 0, 0, 1)
[node name="MarginContainer" type="MarginContainer" parent="UI/LoadTitle"]
layout_mode = 2
theme_override_constants/margin_left = 25
theme_override_constants/margin_top = 10
theme_override_constants/margin_right = 25
theme_override_constants/margin_bottom = 0
[node name="VBoxContainer" type="VBoxContainer" parent="UI/LoadTitle/MarginContainer"]
layout_mode = 2
[node name="RichTextLabel" type="RichTextLabel" parent="UI/LoadTitle/MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
theme_override_fonts/normal_font = ExtResource("2_cohu5")
theme_override_font_sizes/normal_font_size = 30
bbcode_enabled = true
text = "
[center]LOAD GAME[/center]"
[node name="LoadSlot1" type="Button" parent="UI/LoadTitle/MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
theme_override_fonts/font = ExtResource("2_cohu5")
theme_override_font_sizes/font_size = 27
text = "EMPTY"
[node name="LoadSlot2" type="Button" parent="UI/LoadTitle/MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
theme_override_fonts/font = ExtResource("2_cohu5")
theme_override_font_sizes/font_size = 27
text = "EMPTY"
[node name="LoadSlot3" type="Button" parent="UI/LoadTitle/MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
theme_override_fonts/font = ExtResource("2_cohu5")
theme_override_font_sizes/font_size = 27
text = "EMPTY"
[node name="LoadSlot4" type="Button" parent="UI/LoadTitle/MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
theme_override_fonts/font = ExtResource("2_cohu5")
theme_override_font_sizes/font_size = 27
text = "EMPTY"
[node name="Back" type="Button" parent="UI/LoadTitle/MarginContainer/VBoxContainer"]
custom_minimum_size = Vector2(80, 40)
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 6
theme_override_fonts/font = ExtResource("2_cohu5")
theme_override_font_sizes/font_size = 20
text = "BACK"
[node name="Settings" type="PanelContainer" parent="UI"]
visible = false
custom_minimum_size = Vector2(800, 800)
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -200.0
offset_top = -300.0
offset_right = 200.0
offset_bottom = 300.0
grow_horizontal = 2
grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_fo2i3")
[node name="Background" type="ColorRect" parent="UI/Settings"]
layout_mode = 2
color = Color(0, 0, 0, 1)
[node name="MarginContainer" type="MarginContainer" parent="UI/Settings"]
layout_mode = 2
theme_override_constants/margin_left = 25
theme_override_constants/margin_top = 10
theme_override_constants/margin_right = 25
theme_override_constants/margin_bottom = 0
[node name="VBoxContainer" type="VBoxContainer" parent="UI/Settings/MarginContainer"]
layout_mode = 2
[node name="RichTextLabel" type="RichTextLabel" parent="UI/Settings/MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 3
theme_override_fonts/normal_font = ExtResource("2_cohu5")
theme_override_font_sizes/normal_font_size = 30
bbcode_enabled = true
text = "
[center]SETTINGS[/center]"
[node name="Back" type="Button" parent="UI/Settings/MarginContainer/VBoxContainer"]
custom_minimum_size = Vector2(80, 40)
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 6
theme_override_fonts/font = ExtResource("2_cohu5")
theme_override_font_sizes/font_size = 20
text = "BACK"
[node name="UpperContainer" type="HBoxContainer" parent="UI"] [node name="UpperContainer" type="HBoxContainer" parent="UI"]
visible = false visible = false
@@ -191,3 +399,12 @@ layout_mode = 2
theme_override_fonts/font = ExtResource("3_e3v1e") theme_override_fonts/font = ExtResource("3_e3v1e")
theme_override_font_sizes/font_size = 20 theme_override_font_sizes/font_size = 20
text = " Press Space to Next " text = " Press Space to Next "
[node name="ConfirmationMask" type="ColorRect" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_force_pass_scroll_events = false
color = Color(0, 0, 0, 0.470588)