Implement save and loading games (#8)

This commit is contained in:
Julian Murgia
2021-07-02 23:08:43 +02:00
committed by GitHub
parent 58d880101d
commit bd4c33cf77
66 changed files with 1268 additions and 736 deletions

View File

@@ -0,0 +1,26 @@
extends Control
signal back_button_pressed
export(PackedScene) var slot_ui_scene
func _ready():
refresh_savegames()
func _on_slot_pressed(slot_id: int) -> void:
escoria.save_manager.load_game(slot_id)
func _on_back_pressed():
emit_signal("back_button_pressed")
func refresh_savegames():
for slot in $ScrollContainer/slots.get_children():
$ScrollContainer/slots.remove_child(slot)
var saves_list = escoria.save_manager.get_saves_list()
for i in saves_list.size():
var save_data = saves_list[i+1]
var new_slot = slot_ui_scene.instance()
$ScrollContainer/slots.add_child(new_slot)
new_slot.set_slot_name_date(save_data["name"], save_data["date"])
new_slot.connect("pressed", self, "_on_slot_pressed", [i+1])

View File

@@ -0,0 +1,50 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://game/ui/commons/fonts/caslonantique.tres" type="DynamicFont" id=1]
[ext_resource path="res://game/ui/commons/load_save_slot/load_save_slot.tscn" type="PackedScene" id=2]
[ext_resource path="res://game/ui/commons/load/load_game.gd" type="Script" id=3]
[node name="load_game" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 3 )
__meta__ = {
"_edit_use_anchors_": false
}
slot_ui_scene = ExtResource( 2 )
[node name="back" type="Button" parent="."]
margin_left = 130.0
margin_top = 329.0
margin_right = 304.0
margin_bottom = 383.0
custom_fonts/font = ExtResource( 1 )
text = "OPTIONS_BACK"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ScrollContainer" type="ScrollContainer" parent="."]
anchor_left = 0.291
anchor_top = 0.369
anchor_right = 0.709
anchor_bottom = 0.941
margin_left = -0.480011
margin_top = -1.10001
margin_right = 0.479919
margin_bottom = -0.900024
scroll_horizontal_enabled = false
__meta__ = {
"_edit_use_anchors_": false
}
[node name="slots" type="VBoxContainer" parent="ScrollContainer"]
margin_right = 536.0
margin_bottom = 515.0
size_flags_horizontal = 3
size_flags_vertical = 3
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="pressed" from="back" to="." method="_on_back_pressed"]

View File

@@ -0,0 +1,7 @@
extends Button
func set_slot_name_date(p_name: String, p_date: String):
$VBoxContainer/slot_name.text = p_name
$VBoxContainer/date.text = p_date

View File

@@ -0,0 +1,38 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://game/ui/commons/fonts/caslonantique.tres" type="DynamicFont" id=1]
[ext_resource path="res://game/ui/commons/load_save_slot/load_save_slot.gd" type="Script" id=2]
[node name="slot" type="Button"]
margin_right = 665.0
margin_bottom = 86.0
rect_min_size = Vector2( 0, 100 )
size_flags_horizontal = 3
script = ExtResource( 2 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="VBoxContainer" type="VBoxContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
alignment = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="slot_name" type="Label" parent="VBoxContainer"]
margin_top = 27.0
margin_right = 665.0
margin_bottom = 48.0
custom_fonts/font = ExtResource( 1 )
text = "slot_name"
align = 1
[node name="date" type="Label" parent="VBoxContainer"]
margin_top = 52.0
margin_right = 665.0
margin_bottom = 73.0
custom_fonts/font = ExtResource( 1 )
text = "date"
align = 1

View File

@@ -25,24 +25,25 @@ func _on_continue_pressed():
pass
func switch_language(lang : String):
func switch_language(lang: String):
TranslationServer.set_locale(lang)
func _on_new_game_pressed():
escoria.new_game()
func _on_load_game_pressed():
# Show Loading screen
pass
$Panel/main.hide()
$Panel/load_game.refresh_savegames()
$Panel/load_game.show()
func _on_options_pressed():
$Panel/main.hide()
$Panel/options.show()
func _on_quit_pressed():
get_tree().quit()
@@ -50,8 +51,12 @@ func _on_quit_pressed():
###########################################################################
# OPTIONS
func _on_back_pressed():
func _on_options_back_button_pressed():
$Panel/options.hide()
$Panel/main.show()
func _on_load_game_back_button_pressed():
$Panel/load_game.hide()
$Panel/main.show()

View File

@@ -1,9 +1,10 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=6 format=2]
[ext_resource path="res://game/ui/commons/main_menu/main_menu.gd" type="Script" id=1]
[ext_resource path="res://game/ui/commons/main_menu/main.tscn" type="PackedScene" id=2]
[ext_resource path="res://addons/escoria-core/logo/escoria-logo-small.png" type="Texture" id=3]
[ext_resource path="res://game/ui/commons/main_menu/options.tscn" type="PackedScene" id=4]
[ext_resource path="res://game/ui/commons/options/options.tscn" type="PackedScene" id=4]
[ext_resource path="res://game/ui/commons/load/load_game.tscn" type="PackedScene" id=5]
[node name="main_menu" type="Control"]
anchor_right = 1.0
@@ -38,11 +39,14 @@ __meta__ = {
[node name="options" parent="Panel" instance=ExtResource( 4 )]
visible = false
[node name="load_game" parent="Panel" instance=ExtResource( 5 )]
visible = false
[connection signal="pressed" from="Panel/main/new_game" to="." method="_on_new_game_pressed"]
[connection signal="pressed" from="Panel/main/load_game" to="." method="_on_load_game_pressed"]
[connection signal="pressed" from="Panel/main/options" to="." method="_on_options_pressed"]
[connection signal="pressed" from="Panel/main/quit" to="." method="_on_quit_pressed"]
[connection signal="pressed" from="Panel/options/back" to="." method="_on_back_pressed"]
[connection signal="back_button_pressed" from="Panel/options" to="." method="_on_options_back_button_pressed"]
[connection signal="back_button_pressed" from="Panel/load_game" to="." method="_on_load_game_back_button_pressed"]
[editable path="Panel/main"]
[editable path="Panel/options"]

View File

@@ -1,35 +1,63 @@
extends Control
signal back_button_pressed
onready var settings_changed = false
onready var backup_settings
func _ready():
initialize_options(escoria.settings)
func show():
backup_settings = escoria.settings.duplicate()
initialize_options(backup_settings)
visible = true
func initialize_options(p_settings):
$options/general_volume.value = p_settings["master_volume"]
$options/sound_volume.value = p_settings["sfx_volume"]
$options/music_volume.value = p_settings["music_volume"]
func greyout_other_languages(except_lang : String) -> void:
func greyout_other_languages(except_lang: String) -> void:
pass
func _on_language_input(event : InputEvent, language : String):
func _on_language_input(event: InputEvent, language: String):
if event.is_pressed():
TranslationServer.set_locale(language)
escoria.settings["text_lang"] = language
escoria.save_data.save_settings(escoria.settings, null)
settings_changed = true
func _on_sound_volume_changed(value):
escoria.settings["sfx_volume"] = value
escoria.save_data.save_settings(escoria.settings, null)
escoria._on_settings_loaded(escoria.settings)
settings_changed = true
func _on_music_volume_changed(value):
escoria.settings["music_volume"] = value
escoria.save_data.save_settings(escoria.settings, null)
escoria._on_settings_loaded(escoria.settings)
settings_changed = true
func _on_general_volume_changed(value):
escoria.settings["master_volume"] = value
escoria.save_data.save_settings(escoria.settings, null)
escoria._on_settings_loaded(escoria.settings)
settings_changed = true
func _on_apply_pressed():
escoria.save_manager.save_settings()
settings_changed = false
emit_signal("back_button_pressed")
func _on_back_pressed():
escoria.settings = backup_settings
escoria._on_settings_loaded(escoria.settings)
emit_signal("back_button_pressed")

View File

@@ -3,7 +3,7 @@
[ext_resource path="res://game/ui/commons/fonts/caslonantique.tres" type="DynamicFont" id=1]
[ext_resource path="res://game/ui/commons/main_menu/flags/en_EN_small.png" type="Texture" id=2]
[ext_resource path="res://game/ui/commons/main_menu/flags/fr_FR_small.png" type="Texture" id=3]
[ext_resource path="res://game/ui/commons/main_menu/options.gd" type="Script" id=4]
[ext_resource path="res://game/ui/commons/options/options.gd" type="Script" id=4]
[node name="options" type="Control"]
anchor_right = 1.0
@@ -125,8 +125,21 @@ max_value = 1.0
step = 0.001
value = 0.001
[node name="apply" type="Button" parent="."]
margin_left = 364.0
margin_top = 712.0
margin_right = 544.0
margin_bottom = 767.0
custom_fonts/font = ExtResource( 1 )
text = "APPLY"
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="pressed" from="back" to="." method="_on_back_pressed"]
[connection signal="gui_input" from="options/flags/fr" to="." method="_on_language_input" binds= [ "fr" ]]
[connection signal="gui_input" from="options/flags/en" to="." method="_on_language_input" binds= [ "en" ]]
[connection signal="value_changed" from="options/general_volume" to="." method="_on_general_volume_changed"]
[connection signal="value_changed" from="options/sound_volume" to="." method="_on_sound_volume_changed"]
[connection signal="value_changed" from="options/music_volume" to="." method="_on_music_volume_changed"]
[connection signal="pressed" from="apply" to="." method="_on_apply_pressed"]

View File

@@ -6,12 +6,25 @@ func _on_continue_pressed():
func _on_save_game_pressed():
pass
$Panel/VBoxContainer.hide()
$save_game.show()
func _on_load_game_pressed():
pass
$Panel/VBoxContainer.hide()
$load_game.refresh_savegames()
$load_game.show()
func _on_quit_pressed():
get_tree().quit()
func _on_save_game_back_button_pressed():
$Panel/VBoxContainer.show()
$save_game.hide()
func _on_load_game_back_button_pressed():
$Panel/VBoxContainer.show()
$load_game.hide()

View File

@@ -1,8 +1,10 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=6 format=2]
[ext_resource path="res://game/ui/commons/pause_menu/pause_menu.gd" type="Script" id=1]
[ext_resource path="res://game/ui/commons/fonts/caslonantique.tres" type="DynamicFont" id=2]
[ext_resource path="res://addons/escoria-core/logo/escoria-logo-small.png" type="Texture" id=3]
[ext_resource path="res://game/ui/commons/save/save_game.tscn" type="PackedScene" id=4]
[ext_resource path="res://game/ui/commons/load/load_game.tscn" type="PackedScene" id=5]
[node name="pause_menu" type="Control"]
anchor_right = 1.0
@@ -87,7 +89,15 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="save_game" parent="." instance=ExtResource( 4 )]
visible = false
[node name="load_game" parent="." instance=ExtResource( 5 )]
visible = false
[connection signal="pressed" from="Panel/VBoxContainer/continue" to="." method="_on_continue_pressed"]
[connection signal="pressed" from="Panel/VBoxContainer/save_game" to="." method="_on_save_game_pressed"]
[connection signal="pressed" from="Panel/VBoxContainer/load_game" to="." method="_on_load_game_pressed"]
[connection signal="pressed" from="Panel/VBoxContainer/quit" to="." method="_on_quit_pressed"]
[connection signal="back_button_pressed" from="save_game" to="." method="_on_save_game_back_button_pressed"]
[connection signal="back_button_pressed" from="load_game" to="." method="_on_load_game_back_button_pressed"]

View File

@@ -0,0 +1,59 @@
extends Control
signal back_button_pressed
export(PackedScene) var slot_ui_scene
var slot_pressed
func _ready():
refresh_savegames()
func _on_slot_pressed(p_slot_n: int):
slot_pressed = p_slot_n
if escoria.save_manager.save_game_exists(p_slot_n):
# TODO Manage save override, ask for confirmation
pass
else:
$save_name_popup.popup()
func refresh_savegames():
for slot in $ScrollContainer/slots.get_children():
$ScrollContainer/slots.remove_child(slot)
var saves_list = escoria.save_manager.get_saves_list()
for i in saves_list.size():
var save_data = saves_list[i+1]
var new_slot = slot_ui_scene.instance()
$ScrollContainer/slots.add_child(new_slot)
new_slot.set_slot_name_date(save_data["name"], save_data["date"])
new_slot.connect("pressed", self, "_on_slot_pressed", [i+1])
var datetime = OS.get_datetime()
var datetime_string = "%02d/%02d/%02d %02d:%02d" % [
datetime["day"],
datetime["month"],
datetime["year"],
datetime["hour"],
datetime["minute"],
]
var new_slot = slot_ui_scene.instance()
$ScrollContainer/slots.add_child(new_slot)
new_slot.set_slot_name_date(tr("New save"), datetime_string)
new_slot.connect("pressed", self, "_on_slot_pressed", [saves_list.size()+1])
func _on_back_pressed():
emit_signal("back_button_pressed")
func _on_save_name_popup_savegame_name_ok(p_savename: String):
escoria.save_manager.save_game(slot_pressed, p_savename)
refresh_savegames()
slot_pressed = null
func _on_save_name_popup_savegame_cancel():
pass

View File

@@ -0,0 +1,54 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://game/ui/commons/load_save_slot/load_save_slot.tscn" type="PackedScene" id=1]
[ext_resource path="res://game/ui/commons/save/save_game.gd" type="Script" id=2]
[ext_resource path="res://game/ui/commons/fonts/caslonantique.tres" type="DynamicFont" id=3]
[ext_resource path="res://game/ui/commons/save/save_name_popup.tscn" type="PackedScene" id=4]
[node name="save_game" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 2 )
__meta__ = {
"_edit_use_anchors_": false
}
slot_ui_scene = ExtResource( 1 )
[node name="back" type="Button" parent="."]
margin_left = 130.0
margin_top = 329.0
margin_right = 304.0
margin_bottom = 383.0
custom_fonts/font = ExtResource( 3 )
text = "OPTIONS_BACK"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ScrollContainer" type="ScrollContainer" parent="."]
anchor_left = 0.284
anchor_top = 0.367
anchor_right = 0.709
anchor_bottom = 0.94
margin_left = 8.47998
margin_top = 0.699982
margin_right = 0.479919
margin_bottom = -6.10352e-05
__meta__ = {
"_edit_use_anchors_": false
}
[node name="slots" type="VBoxContainer" parent="ScrollContainer"]
margin_right = 536.0
margin_bottom = 515.0
size_flags_horizontal = 3
size_flags_vertical = 3
__meta__ = {
"_edit_use_anchors_": false
}
[node name="save_name_popup" parent="." instance=ExtResource( 4 )]
[connection signal="pressed" from="back" to="." method="_on_back_pressed"]
[connection signal="savegame_cancel" from="save_name_popup" to="." method="_on_save_name_popup_savegame_cancel"]
[connection signal="savegame_name_ok" from="save_name_popup" to="." method="_on_save_name_popup_savegame_name_ok"]

View File

@@ -0,0 +1,14 @@
extends PopupDialog
signal savegame_name_ok(savegame_name)
signal savegame_cancel
func _on_cancel_pressed():
emit_signal("savegame_cancel")
hide()
func _on_ok_pressed():
if not $MarginContainer/VBoxContainer/LineEdit.text.empty():
emit_signal("savegame_name_ok", $MarginContainer/VBoxContainer/LineEdit.text)
$MarginContainer/VBoxContainer/LineEdit.clear()
hide()

View File

@@ -0,0 +1,81 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://game/ui/commons/fonts/caslonantique.tres" type="DynamicFont" id=1]
[ext_resource path="res://game/ui/commons/save/save_name_popup.gd" type="Script" id=2]
[node name="save_name_popup" type="PopupDialog"]
margin_left = 429.0
margin_top = 281.0
margin_right = 863.0
margin_bottom = 442.0
script = ExtResource( 2 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="MarginContainer" type="MarginContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
custom_constants/margin_right = 30
custom_constants/margin_top = 30
custom_constants/margin_left = 30
custom_constants/margin_bottom = 30
__meta__ = {
"_edit_use_anchors_": false
}
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
margin_left = 30.0
margin_top = 30.0
margin_right = 404.0
margin_bottom = 131.0
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer"]
margin_right = 374.0
margin_bottom = 21.0
custom_fonts/font = ExtResource( 1 )
text = "ENTER_SAVE_NAME"
[node name="LineEdit" type="LineEdit" parent="MarginContainer/VBoxContainer"]
margin_top = 25.0
margin_right = 374.0
margin_bottom = 56.0
custom_fonts/font = ExtResource( 1 )
[node name="HBoxContainer" type="HBoxContainer" parent="."]
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = -224.0
margin_top = -56.0
margin_right = -30.0
margin_bottom = -20.0
custom_constants/separation = 10
__meta__ = {
"_edit_use_anchors_": false
}
[node name="cancel" type="Button" parent="HBoxContainer"]
margin_right = 96.0
margin_bottom = 36.0
size_flags_horizontal = 3
custom_fonts/font = ExtResource( 1 )
text = "CANCEL"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ok" type="Button" parent="HBoxContainer"]
margin_left = 106.0
margin_right = 194.0
margin_bottom = 36.0
size_flags_horizontal = 3
custom_fonts/font = ExtResource( 1 )
text = "OK"
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="pressed" from="HBoxContainer/cancel" to="." method="_on_cancel_pressed"]
[connection signal="pressed" from="HBoxContainer/ok" to="." method="_on_ok_pressed"]