feat: add responsive HUD prompts
This commit is contained in:
@@ -8,6 +8,7 @@ var enemies: Dictionary[StringName, ActorState]
|
||||
var map: GridMapState
|
||||
var visible_cells: Dictionary[Vector2i, bool] = {}
|
||||
var explored_cells: Dictionary[Vector2i, bool] = {}
|
||||
var exit_reached := false
|
||||
|
||||
func _init(new_map: GridMapState, new_player: ActorState, new_enemies: Dictionary[StringName, ActorState]) -> void:
|
||||
map = new_map
|
||||
@@ -15,6 +16,16 @@ func _init(new_map: GridMapState, new_player: ActorState, new_enemies: Dictionar
|
||||
enemies = new_enemies
|
||||
update_exploration()
|
||||
|
||||
func get_context_target() -> StringName:
|
||||
if exit_reached:
|
||||
return &"exit_reached"
|
||||
if map.get_cell(player.cell) == GridMapState.CellKind.STAIRS:
|
||||
return &"stairs"
|
||||
for direction in [Vector2i.UP, Vector2i.RIGHT, Vector2i.DOWN, Vector2i.LEFT, Vector2i(1, -1), Vector2i(1, 1), Vector2i(-1, 1), Vector2i(-1, -1)]:
|
||||
if map.get_cell(player.cell + direction) == GridMapState.CellKind.CLOSED_DOOR:
|
||||
return &"closed_door"
|
||||
return &""
|
||||
|
||||
func try_player_action(direction: Vector2i) -> Array[TurnResult]:
|
||||
var results := TurnResolverType.resolve_player_action(self, direction)
|
||||
update_exploration()
|
||||
|
||||
+10
-1
@@ -39,7 +39,9 @@ func _capture_visual_check() -> void:
|
||||
get_tree().quit(0 if result == OK else 1)
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed(&"move_north"):
|
||||
if event.is_action_pressed(&"interact"):
|
||||
submit_test_interact()
|
||||
elif event.is_action_pressed(&"move_north"):
|
||||
_process_action(Vector2i.UP)
|
||||
elif event.is_action_pressed(&"move_south"):
|
||||
_process_action(Vector2i.DOWN)
|
||||
@@ -59,6 +61,9 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
func submit_test_action(direction: Vector2i) -> Array[TurnResult]:
|
||||
return _process_action(direction)
|
||||
|
||||
func submit_test_interact() -> Array[TurnResult]:
|
||||
return _refresh_hud_for_context()
|
||||
|
||||
func get_game_state() -> GameState:
|
||||
return game_state
|
||||
|
||||
@@ -69,6 +74,10 @@ func get_actor_cell_rect(actor_id: StringName) -> Rect2:
|
||||
return enemy_views[actor_id].get_cell_rect()
|
||||
return Rect2()
|
||||
|
||||
func _refresh_hud_for_context() -> Array[TurnResult]:
|
||||
hud.refresh(game_state)
|
||||
return []
|
||||
|
||||
func _process_action(direction: Vector2i) -> Array[TurnResult]:
|
||||
var results := game_state.try_player_action(direction)
|
||||
_sync_map_renderer_visibility()
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
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"]
|
||||
@@ -17,5 +24,19 @@ func refresh(state: GameState, results: Array[TurnResult] = []) -> void:
|
||||
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 ""
|
||||
|
||||
Reference in New Issue
Block a user