fix: select visible targets and bound active effects

This commit is contained in:
goose
2026-10-09 17:51:04 -04:00
parent 70aa27d232
commit 069537e737
2 changed files with 118 additions and 21 deletions
+57 -16
View File
@@ -149,15 +149,7 @@ func apply_viewport_layout(viewport_size: Vector2) -> void:
_set_rect($QuestTrackerLabel, origin + Vector2(52, 482) * scale, Vector2(376, 92) * scale)
# Actionable status slots reserve enough room for their wrapped labels. The
# three currently useful rows are intentionally at 664, 730, and 790px.
_set_rect($CharacterStatusLabel, origin + Vector2(44, 664) * scale, Vector2(386, 50) * scale)
_set_rect($EnemyHealthLabel, origin + Vector2(44, 730) * scale, Vector2(386, 24) * scale)
_set_rect($DeadlineLabel, origin + Vector2(44, 790) * scale, Vector2(386, 52) * scale)
# These dormant slots remain below actionable information so future use cannot
# collide with an active deadline.
_set_rect($SpellLabel, origin + Vector2(44, 856) * scale, Vector2(386, 24) * scale)
_set_rect($CombatSummaryLabel, origin + Vector2(44, 892) * scale, Vector2(386, 36) * scale)
_layout_status_slots(origin, scale)
_set_rect($EventLog, origin + Vector2(1476, 164) * scale, Vector2(396, 330) * scale)
_set_rect($ContextPromptLabel, origin + Vector2(506, 1008) * scale, Vector2(578, 30) * scale)
@@ -173,6 +165,38 @@ func _set_rect(control: Control, position: Vector2, control_size: Vector2) -> vo
control.position = position
control.size = control_size
func _layout_status_slots(origin: Vector2, scale: float) -> void:
# StatusSection ends at y=928. At reference, slots follow the authored
# 664/780/824px composition. At compact scale labels retain enough physical
# height to wrap all effects, so the bounded stack is bottom-aligned instead.
var x := origin.x + 44.0 * scale
var width := 386.0 * scale
var character_y := origin.y + 664.0 * scale
var character_height := 100.0 * scale
var target_height := 24.0 * scale
var deadline_height := 60.0 * scale
var gap := 18.0 * scale
if scale < 1.0:
# These are physical compact-layout heights (not artboard-scaled): the
# multi-effect row needs its full wrapped minimum while all rows remain
# inside StatusSection at 1280×720 with a visible 12px gap.
character_height = 97.0
target_height = 23.0
deadline_height = 28.0
gap = 12.0
# Keep the StatusSection title clear while remaining above its lower edge.
character_y = maxf(origin.y + 662.0 * scale, origin.y + 928.0 * scale - character_height - target_height - deadline_height - 2.0 * gap)
var target_y := character_y + character_height + gap
var deadline_y := target_y + target_height + gap
_set_rect($CharacterStatusLabel, Vector2(x, character_y), Vector2(width, character_height))
_set_rect($EnemyHealthLabel, Vector2(x, target_y), Vector2(width, target_height))
_set_rect($DeadlineLabel, Vector2(x, deadline_y), Vector2(width, deadline_height))
# Dormant labels share a hidden lower slot. _refresh_status_section clears
# and hides them before showing actionable information.
var dormant_y := origin.y + 896.0 * scale
_set_rect($SpellLabel, Vector2(x, dormant_y), Vector2(width, 20.0 * scale))
_set_rect($CombatSummaryLabel, Vector2(x, dormant_y), Vector2(width, 20.0 * scale))
func _apply_text_scale(layout_scale: float) -> void:
var font_scale := clampf(layout_scale, MIN_FONT_SCALE, 1.0)
for control: Control in [
@@ -256,9 +280,14 @@ func _refresh_status_section(state: GameState) -> void:
var effects: Array[String] = []
for effect: StatusEffect in state.player.status_effects:
var name := String(STATUS_EFFECT_NAMES.get(effect.key, String(effect.key).capitalize()))
effects.append("%s (%d tours)" % [name, effect.duration])
if state.player.status_effects.size() <= 3:
effects.append("%s (%d tours)" % [name, effect.duration])
else:
effects.append("%s %d" % [name, effect.duration])
if not effects.is_empty():
character_status_label.text = "Effets : %s" % ", ".join(effects)
# Compact separators preserve every effect and duration in the fixed slot.
var prefix := "Effets : " if effects.size() <= 3 else "Effets (%d) : " % effects.size()
character_status_label.text = prefix + (", ".join(effects) if effects.size() <= 3 else " • ".join(effects))
character_status_label.visible = true
var target := _active_target(state)
@@ -273,9 +302,20 @@ func _refresh_status_section(state: GameState) -> void:
deadline_label.visible = true
func _active_target(state: GameState) -> ActorState:
if state.enemies.has(&"goblin"):
return state.enemies[&"goblin"] as ActorState
return null
var candidates: Array[ActorState] = []
for enemy: ActorState in state.enemies.values():
if enemy.is_alive() and bool(state.visible_cells.get(enemy.cell, false)):
candidates.append(enemy)
if candidates.is_empty():
return null
candidates.sort_custom(func(left: ActorState, right: ActorState) -> bool:
var left_distance := state.player.cell.distance_squared_to(left.cell)
var right_distance := state.player.cell.distance_squared_to(right.cell)
if left_distance != right_distance:
return left_distance < right_distance
return String(left.id) < String(right.id)
)
return candidates[0]
func _target_name(target: ActorState) -> String:
if target.id == &"goblin" or target.content_id == &"goblin":
@@ -283,8 +323,9 @@ func _target_name(target: ActorState) -> String:
if _run_state != null and _run_state.content_catalog != null:
var definition := _run_state.content_catalog.get_enemy(target.content_id)
if not definition.is_empty():
return String(definition.get("name", target.content_id)).capitalize()
return String(target.content_id).capitalize()
return String(definition.get("name", "Ennemi"))
# Never expose an actor/content identifier as player-facing HUD text.
return "Ennemi"
func _should_show_in_journal(event: GameEvent) -> bool:
return event.kind not in HIDDEN_JOURNAL_KINDS