Implement save and loading games (#8)
This commit is contained in:
59
game/ui/commons/save/save_game.gd
Normal file
59
game/ui/commons/save/save_game.gd
Normal 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
|
||||
54
game/ui/commons/save/save_game.tscn
Normal file
54
game/ui/commons/save/save_game.tscn
Normal 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"]
|
||||
14
game/ui/commons/save/save_name_popup.gd
Normal file
14
game/ui/commons/save/save_name_popup.gd
Normal 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()
|
||||
81
game/ui/commons/save/save_name_popup.tscn
Normal file
81
game/ui/commons/save/save_name_popup.tscn
Normal 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"]
|
||||
Reference in New Issue
Block a user