Game screen: CardWidget hand, Dimorpha/Trimorpha tile hints, attack range, camera

Hand display:
- Replace bespoke _make_hand_card() with CardWidget.tscn (the shared collection
  card widget) — shows art, stats, affinity border, SP/ST costs
- Pass live game card dict as both dto and def; all camelCase fields match
- _refresh_hand_selection() now calls widget.set_selected() instead of
  manipulating StyleBoxFlat directly
- HandArea/RightPanel height 180 → 260px to fit CardWidget (238px natural height)
- HBoxContainer separation -12 (overlap) → 6px (proper spacing)

Terramorpha tile selection (Dimorpha / Trimorpha):
- After each tile pick, re-highlight: orange for already-selected tiles, green
  for valid adjacent tiles for the next pick — no more silent rejection of
  non-adjacent clicks

Attack range visualization:
- _attack_range_tiles(): returns all tiles within minAttackRange–maxAttackRange
  for units with maxRange > 1 (ranged spirits)
- _select_unit() shows orange range area first, then red on top for actual
  attackable enemies — players can now see a ranged unit's full reach

Camera orientation:
- On first state that includes playerOneAccountId, orient camera behind the
  local player's row: P1 (row 0, world -Z) gets yaw=180°, P2 keeps yaw=0°
- _camera_oriented flag ensures this only runs once per scene entry

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-03-07 21:24:52 -05:00
co-authored by Claude Happy
parent 0af6b61999
commit 28892cbe10
2 changed files with 83 additions and 95 deletions
@@ -96,7 +96,7 @@ anchor_left = 0.0
anchor_top = 1.0
anchor_right = 0.75
anchor_bottom = 1.0
offset_top = -180.0
offset_top = -260.0
offset_right = 0.0
[node name="HandScroll" type="ScrollContainer" parent="HUD/HandArea"]
@@ -110,7 +110,7 @@ vertical_scroll_mode = 0
unique_name_in_owner = true
layout_mode = 2
size_flags_vertical = 4
theme_override_constants/separation = -12
theme_override_constants/separation = 6
[node name="RightPanel" type="PanelContainer" parent="HUD"]
layout_mode = 1
@@ -119,7 +119,7 @@ anchor_left = 0.75
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_top = -180.0
offset_top = -260.0
[node name="RightMargin" type="MarginContainer" parent="HUD/RightPanel"]
layout_mode = 2
+80 -92
View File
@@ -89,6 +89,8 @@ const AFFINITY_COLORS : Dictionary = {
"GatewayField": Color(0.52, 0.60, 0.22),
}
const _CARD_WIDGET_SCENE := preload("res://scenes/collection/components/CardWidget.tscn")
const HI_GREEN := Color(0.20, 0.90, 0.20, 0.40)
const HI_RED := Color(1.00, 0.25, 0.25, 0.50)
const HI_BLUE := Color(0.20, 0.50, 1.00, 0.40)
@@ -97,11 +99,12 @@ const HI_ORANGE := Color(1.00, 0.60, 0.10, 0.45)
# ── Camera state ──────────────────────────────────────────────────────────────
var _cam_yaw : float = 0.0
var _cam_pitch : float = 40.0
var _cam_distance : float = 14.0
var _cam_pivot : Vector3 = Vector3.ZERO
var _drag_active : bool = false
var _cam_yaw : float = 0.0
var _cam_pitch : float = 40.0
var _cam_distance : float = 14.0
var _cam_pivot : Vector3 = Vector3.ZERO
var _drag_active : bool = false
var _camera_oriented: bool = false
var _pan_active : bool = false
var _last_mouse : Vector2 = Vector2.ZERO
var _touch_points : Dictionary = {}
@@ -616,6 +619,27 @@ func _valid_attack_target_ids(unit: Dictionary) -> Array:
return results
## All tiles within a unit's attack range (regardless of occupancy).
## Used to show the orange reach area for ranged units.
func _attack_range_tiles(unit: Dictionary) -> Array:
var results : Array = []
var pos : Dictionary = unit.get("position", {})
if pos.is_empty(): return results
var ux : int = pos.get("x", 0)
var uy : int = pos.get("y", 0)
var min_r : int = unit.get("minAttackRange", 1)
var max_r : int = unit.get("maxAttackRange", 1)
if max_r <= 1: return results # skip melee — no separate range indicator needed
var bw : int = Game.board_width()
var bh : int = Game.board_height()
for tx in range(bw):
for ty in range(bh):
var dist : int = abs(tx - ux) + abs(ty - uy)
if dist >= min_r and dist <= max_r:
results.append(Vector2i(tx, ty))
return results
func _valid_placement_tiles() -> Array:
var results : Array = []
var my_id := Auth.user_id
@@ -683,7 +707,6 @@ func _handle_board_click(mouse_pos: Vector2) -> void:
# Avoid duplicates.
if _terra_targets.has(coord): return
_terra_targets.append(coord)
_add_highlight(coord.x, coord.y, HI_ORANGE)
if _terra_targets.size() >= _terra_count:
# All tiles selected — send play.
@@ -691,6 +714,20 @@ func _handle_board_click(mouse_pos: Vector2) -> void:
return { "x": v.x, "y": v.y })
Game.send_play_card_multi(_sel_card_id, targets)
_set_mode(Mode.NONE)
else:
# More tiles needed — re-highlight: orange for picked, green for valid next.
_clear_highlights()
for t: Vector2i in _terra_targets:
_add_highlight(t.x, t.y, HI_ORANGE)
var last2 : Vector2i = _terra_targets.back()
var bw2 := Game.board_width()
var bh2 := Game.board_height()
for d: Vector2i in [Vector2i(1,0), Vector2i(-1,0), Vector2i(0,1), Vector2i(0,-1)]:
var nx := last2.x + d.x
var ny := last2.y + d.y
if nx < 0 or ny < 0 or nx >= bw2 or ny >= bh2: continue
if _terra_targets.has(Vector2i(nx, ny)): continue
_add_highlight(nx, ny, HI_GREEN)
Mode.UNIT_SELECTED:
if not unit_id.is_empty():
@@ -743,7 +780,9 @@ func _select_unit(unit_id: String) -> void:
# Movement range (green).
_highlight_tiles(_valid_move_tiles(unit), HI_GREEN)
# Attack range (red).
# Attack range area (orange) — visible reach even when no enemies are in range.
_highlight_tiles(_attack_range_tiles(unit), HI_ORANGE)
# Attackable enemies (red — drawn on top of orange).
_highlight_tiles(_valid_attack_target_coords(unit), HI_RED)
# Show ability panel if unit has active abilities.
@@ -1015,92 +1054,34 @@ func _rebuild_hand(hand: Array) -> void:
func _make_hand_card(card: Dictionary) -> Control:
var iid : String = card.get("instanceId", "")
var name_str : String = card.get("name", "?")
var sp_cost : int = card.get("spCost", 0)
var card_type : String = card.get("cardType", "")
var affinity : String = card.get("affinity", "Void")
var aff_color : Color = AFFINITY_COLORS.get(affinity, Color(0.2, 0.2, 0.2))
var iid : String = card.get("instanceId", "")
var panel := PanelContainer.new()
panel.custom_minimum_size = Vector2(100, 155)
panel.set_meta("card_instance_id", iid)
var style := StyleBoxFlat.new()
style.bg_color = aff_color.darkened(0.35)
for corner in ["top_left","top_right","bottom_left","bottom_right"]:
style.set("corner_radius_" + corner, 6)
for side in ["left","right","top","bottom"]:
style.set("border_width_" + side, 2)
style.border_color = aff_color.lightened(0.2)
panel.add_theme_stylebox_override("panel", style)
var vbox := VBoxContainer.new()
vbox.add_theme_constant_override("separation", 2)
vbox.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
var cost_lbl := Label.new()
cost_lbl.text = "%d SP" % sp_cost
cost_lbl.add_theme_font_size_override("font_size", 10)
cost_lbl.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
cost_lbl.add_theme_color_override("font_color", Color(0.9, 0.85, 0.5))
vbox.add_child(cost_lbl)
var art := ColorRect.new()
art.color = aff_color.lightened(0.15)
art.custom_minimum_size = Vector2(0, 72)
art.size_flags_vertical = Control.SIZE_EXPAND_FILL
vbox.add_child(art)
var name_lbl := Label.new()
name_lbl.text = name_str
name_lbl.add_theme_font_size_override("font_size", 10)
name_lbl.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
name_lbl.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
vbox.add_child(name_lbl)
var type_lbl := Label.new()
type_lbl.text = card_type
type_lbl.add_theme_font_size_override("font_size", 9)
type_lbl.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
type_lbl.add_theme_color_override("font_color", Color(0.65, 0.65, 0.72))
vbox.add_child(type_lbl)
var stat_str := ""
if card.get("damage") != null:
stat_str = "ATK %d" % int(card.get("damage"))
elif card.get("maxHealth") != null:
stat_str = "HP %d" % int(card.get("maxHealth"))
if not stat_str.is_empty():
var stat_lbl := Label.new()
stat_lbl.text = stat_str
stat_lbl.add_theme_font_size_override("font_size", 10)
stat_lbl.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
stat_lbl.add_theme_color_override("font_color", Color(0.8, 0.9, 1.0))
vbox.add_child(stat_lbl)
panel.add_child(vbox)
# Instantiate the shared CardWidget scene used by the collection UI.
# Pass the live game card dict as both dto and def — all stat fields
# (spCost, damage, maxHealth, minAttackRange, …) are in camelCase and
# match what CardWidget.setup() reads from the def dict.
var widget : PanelContainer = _CARD_WIDGET_SCENE.instantiate()
widget.set_meta("card_instance_id", iid)
widget.setup(card, card)
# Hover: scale up and rise.
panel.mouse_entered.connect(func() -> void:
panel.pivot_offset = panel.size * 0.5
widget.mouse_entered.connect(func() -> void:
widget.pivot_offset = widget.size * 0.5
var tw := create_tween()
tw.tween_property(panel, "scale", Vector2(1.18, 1.18), 0.12)
tw.parallel().tween_property(panel, "position:y", panel.position.y - 28.0, 0.12)
panel.z_index = 20)
panel.mouse_exited.connect(func() -> void:
tw.tween_property(widget, "scale", Vector2(1.10, 1.10), 0.12)
tw.parallel().tween_property(widget, "position:y", widget.position.y - 20.0, 0.12)
widget.z_index = 20)
widget.mouse_exited.connect(func() -> void:
var tw := create_tween()
tw.tween_property(panel, "scale", Vector2(1.0, 1.0), 0.10)
tw.parallel().tween_property(panel, "position:y", 0.0, 0.10)
panel.z_index = 0)
tw.tween_property(widget, "scale", Vector2(1.0, 1.0), 0.10)
tw.parallel().tween_property(widget, "position:y", 0.0, 0.10)
widget.z_index = 0)
panel.gui_input.connect(func(event: InputEvent) -> void:
if event is InputEventMouseButton:
var mb := event as InputEventMouseButton
if mb.button_index == MOUSE_BUTTON_LEFT and mb.pressed:
_on_hand_card_clicked(iid, panel))
# CardWidget emits card_pressed(definition_id); forward as hand-card click.
widget.card_pressed.connect(func(_def_id: String) -> void:
_on_hand_card_clicked(iid, widget))
return panel
return widget
func _refresh_hand_selection() -> void:
@@ -1110,12 +1091,8 @@ func _refresh_hand_selection() -> void:
var sel : bool = ((_mode == Mode.CARD_FROM_HAND
or _mode == Mode.TERRAMORPHA_SELECT)
and _sel_card_id == iid)
var style = widget.get_theme_stylebox("panel") as StyleBoxFlat
if style:
var card := _find_hand_card(iid)
var aff : String = card.get("affinity", "Void") if not card.is_empty() else "Void"
style.border_color = Color(1.0, 0.9, 0.2) if sel \
else AFFINITY_COLORS.get(aff, Color(0.3, 0.3, 0.3)).lightened(0.2)
if widget.has_method("set_selected"):
widget.set_selected(sel)
func _find_hand_card(iid: String) -> Dictionary:
@@ -1255,6 +1232,17 @@ func _on_game_over(winner_id: String, win_condition: String,
func _on_state_updated(state: Dictionary) -> void:
_rebuild_ownership(state)
# Orient camera behind the local player's row on the first state with playerOneAccountId.
if not _camera_oriented:
var p1_id : String = str(state.get("playerOneAccountId", ""))
if not p1_id.is_empty():
_camera_oriented = true
# P1 places at row y=0 (world -Z). Camera must look FROM -Z toward +Z → yaw=180°.
# P2 places at row y=bh-1 (world +Z). Camera looks FROM +Z → yaw=0° (default).
if Auth.user_id.to_lower() == p1_id.to_lower():
_cam_yaw = 180.0
_apply_camera()
var board : Dictionary = state.get("board", {})
if _tile_bodies.is_empty() and not board.is_empty():
_build_board(board)