Files
DungeonCrawlerWorld/scripts/presentation/hud.gd

43 lines
1.5 KiB
GDScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
class_name GameHud
extends CanvasLayer
const DOOR_PROMPT := "Espace — Ouvrir la porte"
const STAIRS_PROMPT := "Espace — Descendre l’escalier"
const EXIT_REACHED_PROMPT := "Sortie atteinte — prochain étage bientôt disponible"
@onready var player_health_label: Label = $PlayerHealthLabel
@onready var enemy_health_label: Label = $EnemyHealthLabel
@onready var combat_summary_label: Label = $CombatSummaryLabel
@onready var event_log: RichTextLabel = $EventLog
@onready var context_prompt_label: Label = $ContextPromptLabel
var combat_summary := ""
var _state: GameState
func refresh(state: GameState, results: Array[TurnResult] = []) -> void:
_state = state
player_health_label.text = "Player HP: %d/%d" % [state.player.hit_points, state.player.max_hit_points]
if state.enemies.has(&"goblin"):
var goblin: ActorState = state.enemies[&"goblin"]
enemy_health_label.text = "Goblin HP: %d/%d" % [goblin.hit_points, goblin.max_hit_points]
combat_summary = "Target: Goblin HP: %d/%d" % [goblin.hit_points, goblin.max_hit_points]
else:
enemy_health_label.text = "No active target"
combat_summary = "No active target"
combat_summary_label.text = combat_summary
context_prompt_label.text = get_context_prompt()
for result in results:
event_log.append_text(result.message + "\n")
func get_context_prompt() -> String:
if _state == null:
return ""
match _state.get_context_target():
&"closed_door":
return DOOR_PROMPT
&"stairs":
return STAIRS_PROMPT
&"exit_reached":
return EXIT_REACHED_PROMPT
_:
return ""