42 lines
1.2 KiB
GDScript
42 lines
1.2 KiB
GDScript
class_name ProgressionChoicePanel
|
|
extends PanelContainer
|
|
|
|
signal choice_confirmed(perk_id: StringName)
|
|
|
|
@onready var title: Label = $Title
|
|
@onready var body: RichTextLabel = $Body
|
|
|
|
var _choices: Array[Dictionary] = []
|
|
var _selected_index := 0
|
|
|
|
func present(choices: Array[Dictionary]) -> void:
|
|
_choices = choices.duplicate(true)
|
|
_selected_index = 0
|
|
visible = true
|
|
refresh()
|
|
|
|
func dismiss() -> void:
|
|
visible = false
|
|
_choices.clear()
|
|
_selected_index = 0
|
|
|
|
func select_next(delta: int) -> void:
|
|
if _choices.is_empty():
|
|
return
|
|
_selected_index = posmod(_selected_index + delta, _choices.size())
|
|
refresh()
|
|
|
|
func confirm() -> void:
|
|
if _choices.is_empty():
|
|
return
|
|
choice_confirmed.emit(StringName(_choices[_selected_index].get("id", "")))
|
|
|
|
func refresh() -> void:
|
|
title.text = "LEVEL 3 — CHOOSE A PERK"
|
|
var lines := PackedStringArray(["A perk is required before continuing.", ""])
|
|
for index in _choices.size():
|
|
var choice := _choices[index]
|
|
var marker := ">" if index == _selected_index else " "
|
|
lines.append("%s %s — %s" % [marker, String(choice.get("name", choice.get("id", ""))), String(choice.get("description", ""))])
|
|
body.text = "\n".join(lines) + "\n\nUp/Down Select Enter Confirm"
|