Files
DungeonCrawlerWorld/scripts/presentation/hud.gd
T

86 lines
3.3 KiB
GDScript
Raw 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 CHEST_PROMPT := "Espace — Ouvrir le coffre"
const STAIRS_PROMPT := "Espace — Descendre l’escalier"
const STAIRS_UP_PROMPT := "Espace — Monter l’escalier"
const BED_PROMPT := "H — Se reposer (coûte 1 jour)"
const EXIT_REACHED_PROMPT := "Sortie atteinte — prochain étage bientôt disponible"
const TRAP_PROMPT := "Espace — Désamorcer le piège"
const SHRINE_PROMPT := "Espace — Prier au sanctuaire"
const QUEST_BOARD_PROMPT := "Espace — Lire le tableau des quêtes"
@onready var player_health_label: Label = $PlayerHealthLabel
@onready var player_focus_label: Label = $PlayerFocusLabel
@onready var spell_label: Label = $SpellLabel
@onready var deadline_label: Label = $DeadlineLabel
@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
var _run_state: RunState
func refresh(state: GameState, events: Array[GameEvent] = [], run_state: RunState = null) -> void:
_state = state
if run_state != null:
_run_state = run_state
player_health_label.text = "Player HP: %d/%d" % [state.player.hit_points, state.player.max_hit_points]
player_focus_label.text = "Focus: %d/%d" % [state.player.focus, state.player.max_focus]
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
deadline_label.text = _deadline_status()
context_prompt_label.text = get_context_prompt()
# The supplied RunState journal events are the only source for journal text.
event_log.clear()
for event in events:
event_log.append_text(event.message + "\n")
func get_context_prompt() -> String:
if _state == null:
return ""
match _state.get_context_target():
&"trap":
return TRAP_PROMPT
&"shrine":
return SHRINE_PROMPT
&"quest_board":
return QUEST_BOARD_PROMPT
&"chest":
return CHEST_PROMPT
&"closed_door":
return DOOR_PROMPT
&"stairs":
if _state.floor_state.floor_number > 0 and _state.player.cell == _state.floor_state.entrance:
return STAIRS_UP_PROMPT
if _run_state != null:
var deadline := _run_state.current_floor_deadline()
if not deadline.can_descend():
return "Escaliers verrouillés — encore %d jour(s) avant l’ouverture" % deadline.days_until_stairs_open()
return STAIRS_PROMPT
&"bed":
return BED_PROMPT
&"exit_reached":
return EXIT_REACHED_PROMPT
_:
return ""
func _deadline_status() -> String:
if _run_state == null:
return ""
var deadline := _run_state.current_floor_deadline()
var status := "Étage %d — %d jour(s) avant l’effondrement" % [_run_state.current_floor, deadline.remaining_days()]
if deadline.collapsing:
return status + " — EFFONDREMENT"
if deadline.can_descend():
return status + " — escaliers ouverts"
return status + " — escaliers dans %d jour(s)" % deadline.days_until_stairs_open()