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