64 lines
1.8 KiB
GDScript
64 lines
1.8 KiB
GDScript
class_name RaceClassChoicePanel
|
|
extends PanelContainer
|
|
|
|
signal race_confirmed(race_id: StringName)
|
|
signal class_confirmed(class_id: StringName)
|
|
|
|
@onready var title: Label = $Layout/Title
|
|
@onready var intro: Label = $Layout/Intro
|
|
@onready var options: RichTextLabel = $Layout/Options
|
|
|
|
var _stage: StringName = &"race"
|
|
var _choices: Array[Dictionary] = []
|
|
var _selected_index := 0
|
|
|
|
func present_races(choices: Array[Dictionary]) -> void:
|
|
_stage = &"race"
|
|
_present(choices)
|
|
|
|
func present_classes(choices: Array[Dictionary]) -> void:
|
|
_stage = &"class"
|
|
_present(choices)
|
|
|
|
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
|
|
var choice_id := StringName(_choices[_selected_index].get("id", ""))
|
|
if _stage == &"race":
|
|
race_confirmed.emit(choice_id)
|
|
else:
|
|
class_confirmed.emit(choice_id)
|
|
|
|
func stage() -> StringName:
|
|
return _stage
|
|
|
|
func _present(choices: Array[Dictionary]) -> void:
|
|
_choices = choices.duplicate(true)
|
|
_selected_index = 0
|
|
visible = true
|
|
refresh()
|
|
|
|
func refresh() -> void:
|
|
title.text = "NIVEAU 3 — CHOIX DE %s" % ("RACE" if _stage == &"race" else "CLASSE")
|
|
intro.text = "Choisissez votre race, puis votre classe. Ce choix est permanent."
|
|
var lines := PackedStringArray()
|
|
for index in _choices.size():
|
|
var choice := _choices[index]
|
|
var marker := ">" if index == _selected_index else " "
|
|
lines.append("%s %s" % [marker, String(choice.get("name", choice.get("id", "")))])
|
|
var description := String(choice.get("description", ""))
|
|
if not description.is_empty():
|
|
lines.append(" %s" % description)
|
|
options.text = "\n".join(lines) + "\n\nHaut/Bas : sélectionner Entrée : confirmer"
|