38 lines
1.1 KiB
GDScript
38 lines
1.1 KiB
GDScript
class_name CompanionPanel
|
|
extends PanelContainer
|
|
|
|
@onready var title: Label = $Title
|
|
@onready var body: RichTextLabel = $Body
|
|
|
|
var _companion: CompanionState
|
|
|
|
func present(companion: CompanionState) -> void:
|
|
_companion = companion
|
|
visible = true
|
|
refresh()
|
|
|
|
func dismiss() -> void:
|
|
visible = false
|
|
_companion = null
|
|
|
|
func select_next(delta: int) -> bool:
|
|
if _companion == null or not _companion.is_alive():
|
|
return false
|
|
var stances := CompanionState.VALID_STANCES
|
|
var index := stances.find(_companion.stance)
|
|
return _companion.set_stance(stances[posmod(index + delta, stances.size())])
|
|
|
|
func refresh() -> void:
|
|
if _companion == null:
|
|
return
|
|
title.text = "Companion command"
|
|
var status := "Alive" if _companion.is_alive() else "Fallen"
|
|
body.text = "%s — %s\n\n%s\n\n←/→ Change stance Esc Close" % [String(_companion.choice_id).capitalize(), status, _stance_lines()]
|
|
|
|
func _stance_lines() -> String:
|
|
var lines: PackedStringArray = []
|
|
for stance: StringName in CompanionState.VALID_STANCES:
|
|
var cursor := "> " if stance == _companion.stance else " "
|
|
lines.append("%s%s" % [cursor, String(stance).capitalize()])
|
|
return "\n".join(lines)
|