44 lines
1.5 KiB
GDScript
44 lines
1.5 KiB
GDScript
class_name SaveLoadPanel
|
|
extends Control
|
|
|
|
signal slot_requested(slot: int)
|
|
signal cancelled
|
|
|
|
@onready var title_label: Label = $Panel/Layout/Title
|
|
@onready var slots: VBoxContainer = $Panel/Layout/Slots
|
|
@onready var status_label: Label = $Panel/Layout/Status
|
|
|
|
var _mode := "load"
|
|
|
|
func _ready() -> void:
|
|
$Panel/Layout/CancelButton.pressed.connect(func() -> void: cancelled.emit())
|
|
for index in range(slots.get_child_count()):
|
|
(slots.get_child(index) as Button).pressed.connect(_request_slot.bind(index + 1))
|
|
|
|
func present(mode: String, slot_metas: Array[Dictionary], message: String = "") -> void:
|
|
_mode = mode
|
|
visible = true
|
|
title_label.text = "SAVE RUN" if mode == "save" else "LOAD RUN"
|
|
status_label.text = message
|
|
for index in range(slots.get_child_count()):
|
|
var button := slots.get_child(index) as Button
|
|
var meta: Dictionary = slot_metas[index] if index < slot_metas.size() else {"slot": index + 1, "exists": false}
|
|
button.set_meta("slot", int(meta.get("slot", index + 1)))
|
|
button.text = _label_for(meta)
|
|
button.disabled = mode == "load" and not bool(meta.get("exists", false))
|
|
|
|
func dismiss() -> void:
|
|
visible = false
|
|
|
|
func set_status(message: String) -> void:
|
|
status_label.text = message
|
|
|
|
func _request_slot(slot: int) -> void:
|
|
slot_requested.emit(slot)
|
|
|
|
func _label_for(meta: Dictionary) -> String:
|
|
var slot := int(meta.get("slot", 0))
|
|
if not bool(meta.get("exists", false)):
|
|
return "SLOT %d — EMPTY" % slot
|
|
return "SLOT %d — %s — FLOOR %d" % [slot, String(meta.get("character_name", "?")), int(meta.get("floor", 0))]
|