38 lines
1.3 KiB
GDScript
38 lines
1.3 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.name
|
|
var status := "En vie" if _companion.is_alive() else "À terre"
|
|
body.text = "%s — %s\nPV %d/%d\n\nComportement :\n%s\n\n%s\n\n←/→ Changer K ou Échap Fermer" % [_companion.species, status, _companion.actor.hit_points, _companion.actor.effective_max_hit_points(), _stance_lines(), CompanionState.stance_description(_companion.stance)]
|
|
|
|
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, CompanionState.stance_label(stance)])
|
|
return "\n".join(lines)
|