S5.2: Responsive HUD and contextual prompts #6
@@ -10,7 +10,7 @@ Godot 4.2+ is required (verified with Godot 4.5). GUT **9.5.0** is vendored and
|
||||
"${GODOT_BIN:-$(command -v godot4 || command -v godot)}" --path .
|
||||
```
|
||||
|
||||
Use WASD / arrow keys (and QEZC diagonals). `Game.submit_test_action(Vector2i)` is the deterministic public E2E seam and follows the same action processor as keyboard input.
|
||||
Use WASD / arrow keys (and QZC diagonals). The HUD help band uses the French labels `Déplacer : ZQSD / Flèches` and `Interagir : Espace ou E`; both **Space** and **E** are bound to `interact`. `Game.submit_test_action(Vector2i)` is the deterministic public E2E seam and follows the same action processor as keyboard input.
|
||||
|
||||
## Display, grid, and camera
|
||||
|
||||
@@ -72,7 +72,8 @@ GODOT_BIN=/snap/bin/godot4 timeout 3s /snap/bin/godot4 --headless --path .
|
||||
|
||||
- `GameState.visible_cells` render at full brightness; cells retained in `explored_cells` render dimly; unknown cells are black.
|
||||
- FOV is map-aware: walls and closed doors are visible but block cells behind them.
|
||||
- `HUD/PlayerHealthLabel`, `HUD/EnemyHealthLabel`, `HUD/CombatSummaryLabel`, and `HUD/EventLog` expose the current combat state.
|
||||
- `HUD/PlayerHealthLabel`, `HUD/EnemyHealthLabel`, `HUD/CombatSummaryLabel`, and `HUD/EventLog` expose the current combat state. Their historical public paths are retained while viewport-anchored HUD panels separate stats, journal, contextual prompt, and help.
|
||||
- `HUD/ContextPromptLabel` mirrors `GameHud.get_context_prompt()`: a closed door adjacent to the player reads `Espace — Ouvrir la porte`; stairs under the player read `Espace — Descendre l’escalier`; a reached exit reads `Sortie atteinte — prochain étage bientôt disponible`; otherwise it is empty. S5.2 only presents these affordances—neither doors nor stairs are modified.
|
||||
- Every `melee` and `enemy_melee` result is routed to its actor view; the sprite's persistent red tint makes received damage visible.
|
||||
|
||||
## Exports
|
||||
|
||||
@@ -24,6 +24,7 @@ textures/canvas_textures/default_texture_filter=0
|
||||
enabled=PackedStringArray("res://addons/gut/plugin.cfg")
|
||||
|
||||
[input]
|
||||
interact={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":32),Object(InputEventKey,"physical_keycode":69)]}
|
||||
move_north={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":87),Object(InputEventKey,"physical_keycode":4194320)]}
|
||||
move_south={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":83),Object(InputEventKey,"physical_keycode":4194322)]}
|
||||
move_west={"deadzone":0.5,"events":[Object(InputEventKey,"physical_keycode":65),Object(InputEventKey,"physical_keycode":4194319)]}
|
||||
|
||||
+157
-17
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=6 format=3]
|
||||
[gd_scene load_steps=8 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/game/game.gd" id="1_game"]
|
||||
[ext_resource type="Script" path="res://scripts/presentation/map_renderer.gd" id="2_map"]
|
||||
@@ -7,6 +7,34 @@
|
||||
[ext_resource type="Texture2D" path="res://assets/dcss/player.png" id="5_player"]
|
||||
[ext_resource type="Script" path="res://scripts/infrastructure/audio_library.gd" id="6_audio"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBox_hud_panel"]
|
||||
bg_color = Color(0.035, 0.055, 0.09, 0.9)
|
||||
border_width_left = 2
|
||||
border_width_top = 2
|
||||
border_width_right = 2
|
||||
border_width_bottom = 2
|
||||
border_color = Color(0.25, 0.48, 0.62, 0.9)
|
||||
corner_radius_top_left = 6
|
||||
corner_radius_top_right = 6
|
||||
corner_radius_bottom_right = 6
|
||||
corner_radius_bottom_left = 6
|
||||
content_margin_left = 12.0
|
||||
content_margin_top = 8.0
|
||||
content_margin_right = 12.0
|
||||
content_margin_bottom = 8.0
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBox_prompt_panel"]
|
||||
bg_color = Color(0.08, 0.12, 0.16, 0.94)
|
||||
border_width_left = 2
|
||||
border_width_top = 2
|
||||
border_width_right = 2
|
||||
border_width_bottom = 2
|
||||
border_color = Color(0.82, 0.66, 0.25, 0.95)
|
||||
corner_radius_top_left = 6
|
||||
corner_radius_top_right = 6
|
||||
corner_radius_bottom_right = 6
|
||||
corner_radius_bottom_left = 6
|
||||
|
||||
[node name="Game" type="Node2D"]
|
||||
script = ExtResource("1_game")
|
||||
|
||||
@@ -32,36 +60,148 @@ position_smoothing_enabled = false
|
||||
layer = 1
|
||||
script = ExtResource("4_hud")
|
||||
|
||||
[node name="PlayerHealthLabel" type="Label" parent="HUD"]
|
||||
[node name="ResponsiveLayout" type="Control" parent="HUD"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="StatsPanel" type="PanelContainer" parent="HUD/ResponsiveLayout"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 0
|
||||
offset_left = 12.0
|
||||
offset_top = 10.0
|
||||
offset_right = 220.0
|
||||
offset_bottom = 35.0
|
||||
offset_top = 12.0
|
||||
offset_right = 326.0
|
||||
offset_bottom = 116.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
theme_override_styles/panel = SubResource("StyleBox_hud_panel")
|
||||
|
||||
[node name="LogPanel" type="PanelContainer" parent="HUD/ResponsiveLayout"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 1
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
offset_left = -344.0
|
||||
offset_top = 12.0
|
||||
offset_right = -12.0
|
||||
offset_bottom = 278.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
theme_override_styles/panel = SubResource("StyleBox_hud_panel")
|
||||
|
||||
[node name="PromptPanel" type="PanelContainer" parent="HUD/ResponsiveLayout"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 10
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 332.0
|
||||
offset_top = -110.0
|
||||
offset_right = -332.0
|
||||
offset_bottom = -62.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
theme_override_styles/panel = SubResource("StyleBox_prompt_panel")
|
||||
|
||||
[node name="HelpPanel" type="PanelContainer" parent="HUD/ResponsiveLayout"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 12
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 12.0
|
||||
offset_top = -50.0
|
||||
offset_right = -12.0
|
||||
offset_bottom = -12.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
theme_override_styles/panel = SubResource("StyleBox_hud_panel")
|
||||
|
||||
[node name="PlayerHealthLabel" type="Label" parent="HUD"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 0
|
||||
offset_left = 26.0
|
||||
offset_top = 20.0
|
||||
offset_right = 312.0
|
||||
offset_bottom = 44.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
theme_override_colors/font_color = Color(1, 1, 1, 1)
|
||||
theme_override_font_sizes/font_size = 18
|
||||
|
||||
[node name="EnemyHealthLabel" type="Label" parent="HUD"]
|
||||
offset_left = 12.0
|
||||
offset_top = 35.0
|
||||
offset_right = 240.0
|
||||
offset_bottom = 60.0
|
||||
layout_mode = 1
|
||||
anchors_preset = 0
|
||||
offset_left = 26.0
|
||||
offset_top = 48.0
|
||||
offset_right = 312.0
|
||||
offset_bottom = 72.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
theme_override_colors/font_color = Color(1, 0.8, 0.7, 1)
|
||||
theme_override_font_sizes/font_size = 18
|
||||
|
||||
[node name="CombatSummaryLabel" type="Label" parent="HUD"]
|
||||
offset_left = 12.0
|
||||
offset_top = 60.0
|
||||
offset_right = 300.0
|
||||
offset_bottom = 85.0
|
||||
layout_mode = 1
|
||||
anchors_preset = 0
|
||||
offset_left = 26.0
|
||||
offset_top = 78.0
|
||||
offset_right = 312.0
|
||||
offset_bottom = 100.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
theme_override_colors/font_color = Color(1, 0.9, 0.5, 1)
|
||||
theme_override_font_sizes/font_size = 16
|
||||
|
||||
[node name="EventLog" type="RichTextLabel" parent="HUD"]
|
||||
offset_left = 410.0
|
||||
offset_top = 285.0
|
||||
offset_right = 630.0
|
||||
offset_bottom = 470.0
|
||||
layout_mode = 1
|
||||
anchors_preset = 1
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
offset_left = -330.0
|
||||
offset_top = 24.0
|
||||
offset_right = -26.0
|
||||
offset_bottom = 266.0
|
||||
grow_horizontal = 0
|
||||
grow_vertical = 0
|
||||
bbcode_enabled = false
|
||||
fit_content = false
|
||||
theme_override_colors/default_color = Color(1, 1, 0.8, 1)
|
||||
theme_override_font_sizes/normal_font_size = 14
|
||||
|
||||
[node name="ContextPromptLabel" type="Label" parent="HUD"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 10
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 348.0
|
||||
offset_top = -101.0
|
||||
offset_right = -348.0
|
||||
offset_bottom = -71.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
theme_override_colors/font_color = Color(1, 0.92, 0.63, 1)
|
||||
theme_override_font_sizes/font_size = 18
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
[node name="HelpLabel" type="Label" parent="HUD"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 12
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 28.0
|
||||
offset_top = -43.0
|
||||
offset_right = -28.0
|
||||
offset_bottom = -19.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
theme_override_colors/font_color = Color(0.82, 0.9, 1, 1)
|
||||
theme_override_font_sizes/font_size = 16
|
||||
text = "Déplacer : ZQSD / Flèches • Interagir : Espace ou E"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
|
||||
@@ -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 ""
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
extends GutTest
|
||||
|
||||
const GameScene = preload("res://scenes/Game.tscn")
|
||||
var game: Game
|
||||
|
||||
func before_each() -> void:
|
||||
game = GameScene.instantiate()
|
||||
add_child_autofree(game)
|
||||
await get_tree().process_frame
|
||||
|
||||
func test_real_game_exposes_door_and_stairs_prompts_with_help_and_event_log() -> void:
|
||||
var hud := game.get_node("HUD") as GameHud
|
||||
var state := game.get_game_state()
|
||||
var help_label := game.get_node("HUD/HelpLabel") as Label
|
||||
var prompt_label := game.get_node("HUD/ContextPromptLabel") as Label
|
||||
var event_log := game.get_node("HUD/EventLog") as RichTextLabel
|
||||
|
||||
assert_eq(hud.get_context_prompt(), "Espace — Ouvrir la porte")
|
||||
assert_eq(prompt_label.text, "Espace — Ouvrir la porte")
|
||||
assert_string_contains(help_label.text, "Déplacer : ZQSD / Flèches")
|
||||
assert_string_contains(help_label.text, "Interagir : Espace ou E")
|
||||
|
||||
var interact_event := InputEventKey.new()
|
||||
interact_event.keycode = KEY_SPACE
|
||||
interact_event.pressed = true
|
||||
game._unhandled_input(interact_event)
|
||||
assert_eq(hud.get_context_prompt(), "Espace — Ouvrir la porte")
|
||||
assert_eq(state.map.get_cell(Vector2i(2, 1)), GridMapState.CellKind.CLOSED_DOOR)
|
||||
|
||||
state.map.set_cell(Vector2i(2, 1), GridMapState.CellKind.FLOOR)
|
||||
state.player.cell = Vector2i(9, 7)
|
||||
game.submit_test_interact()
|
||||
assert_eq(hud.get_context_prompt(), "Espace — Descendre l’escalier")
|
||||
assert_eq(prompt_label.text, "Espace — Descendre l’escalier")
|
||||
|
||||
var results := game.submit_test_action(Vector2i.LEFT)
|
||||
assert_eq(results[0].kind, &"moved")
|
||||
assert_string_contains(event_log.get_parsed_text(), "You move to")
|
||||
@@ -0,0 +1,35 @@
|
||||
extends GutTest
|
||||
|
||||
const GameScene = preload("res://scenes/Game.tscn")
|
||||
var game: Game
|
||||
|
||||
func before_each() -> void:
|
||||
game = GameScene.instantiate()
|
||||
add_child_autofree(game)
|
||||
await get_tree().process_frame
|
||||
|
||||
func test_help_band_displays_the_exact_control_labels() -> void:
|
||||
var help_label := game.get_node_or_null("HUD/HelpLabel") as Label
|
||||
|
||||
assert_not_null(help_label)
|
||||
assert_string_contains(help_label.text, "Déplacer : ZQSD / Flèches")
|
||||
assert_string_contains(help_label.text, "Interagir : Espace ou E")
|
||||
|
||||
func test_hud_uses_viewport_anchored_panels_with_distinct_stats_and_log_zones() -> void:
|
||||
var hud := game.get_node("HUD") as GameHud
|
||||
var layout := hud.get_node_or_null("ResponsiveLayout") as Control
|
||||
var stats_panel := hud.get_node_or_null("ResponsiveLayout/StatsPanel") as PanelContainer
|
||||
var log_panel := hud.get_node_or_null("ResponsiveLayout/LogPanel") as PanelContainer
|
||||
var player_health := hud.get_node("PlayerHealthLabel") as Label
|
||||
var enemy_health := hud.get_node("EnemyHealthLabel") as Label
|
||||
var event_log := hud.get_node("EventLog") as RichTextLabel
|
||||
|
||||
assert_not_null(layout)
|
||||
assert_eq(layout.anchor_right, 1.0)
|
||||
assert_eq(layout.anchor_bottom, 1.0)
|
||||
assert_not_null(stats_panel)
|
||||
assert_not_null(log_panel)
|
||||
assert_true(stats_panel.get_global_rect().encloses(player_health.get_global_rect()))
|
||||
assert_true(stats_panel.get_global_rect().encloses(enemy_health.get_global_rect()))
|
||||
assert_true(log_panel.get_global_rect().encloses(event_log.get_global_rect()))
|
||||
assert_false(stats_panel.get_global_rect().intersects(log_panel.get_global_rect()))
|
||||
@@ -0,0 +1,38 @@
|
||||
extends GutTest
|
||||
|
||||
const GameScene = preload("res://scenes/Game.tscn")
|
||||
var game: Game
|
||||
|
||||
func before_each() -> void:
|
||||
game = GameScene.instantiate()
|
||||
add_child_autofree(game)
|
||||
await get_tree().process_frame
|
||||
|
||||
func test_context_prompt_describes_an_adjacent_closed_door_without_mutating_the_map() -> void:
|
||||
var hud := game.get_node("HUD") as GameHud
|
||||
var state := game.get_game_state()
|
||||
var door_cell := Vector2i(2, 1)
|
||||
|
||||
assert_eq(hud.get_context_prompt(), "Espace — Ouvrir la porte")
|
||||
assert_eq(state.map.get_cell(door_cell), GridMapState.CellKind.CLOSED_DOOR)
|
||||
|
||||
func test_context_prompt_describes_stairs_under_player_and_nothing_else() -> void:
|
||||
var hud := game.get_node("HUD") as GameHud
|
||||
var state := game.get_game_state()
|
||||
|
||||
state.map.set_cell(Vector2i(2, 1), GridMapState.CellKind.FLOOR)
|
||||
state.player.cell = Vector2i(9, 7)
|
||||
hud.refresh(state)
|
||||
assert_eq(hud.get_context_prompt(), "Espace — Descendre l’escalier")
|
||||
|
||||
state.map.set_cell(state.player.cell, GridMapState.CellKind.FLOOR)
|
||||
hud.refresh(state)
|
||||
assert_eq(hud.get_context_prompt(), "")
|
||||
|
||||
func test_context_prompt_describes_a_reached_exit() -> void:
|
||||
var hud := game.get_node("HUD") as GameHud
|
||||
var state := game.get_game_state()
|
||||
|
||||
state.exit_reached = true
|
||||
hud.refresh(state)
|
||||
assert_eq(hud.get_context_prompt(), "Sortie atteinte — prochain étage bientôt disponible")
|
||||
Reference in New Issue
Block a user