feat(hand): fan layout with bring-to-front selection, no focus shift on click

Clicking a card now selects it and brings it visually to the front (via
z_index + lift boost) without re-centering the fan. Scroll arrows deselect
the active card before spinning. Hover lift and tween-based fan layout added.

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-04-14 22:10:39 -04:00
co-authored by Claude Happy
parent affd251b10
commit 9c75c86b95
2 changed files with 308 additions and 27 deletions
@@ -1,4 +1,4 @@
[gd_scene load_steps=18 format=3 uid="uid://b17evi1hw4dqu"]
[gd_scene load_steps=20 format=3 uid="uid://b17evi1hw4dqu"]
[ext_resource type="Script" uid="uid://b8x84lb58h6gx" path="res://scenes/game/game_screen.gd" id="1_gscr"]
[ext_resource type="Texture2D" uid="uid://dvmripj4jux0b" path="res://icons/SP-Symbol-White.png" id="2_056su"]
@@ -6,6 +6,7 @@
[ext_resource type="Texture2D" uid="uid://csvmdo2kwnh7c" path="res://icons/ST-Symbol-White.png" id="3_wukpb"]
[ext_resource type="Texture2D" uid="uid://beyeu0y34m3v4" path="res://ui/icons/Deck Icon.png" id="4_ld7sk"]
[ext_resource type="Texture2D" uid="uid://c65s8sn4p7s37" path="res://ui/icons/Discard Icon.png" id="5_pryjh"]
[ext_resource type="Texture2D" uid="uid://psjb7swm36jx" path="res://ui/icons/Green_Gem_Arrow_Button_Click.png" id="6_pryjh"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_wukpb"]
@@ -27,7 +28,9 @@
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_ld7sk"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_8asym"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_w2jaq"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_fuou0"]
[node name="GameScreen" type="Node3D"]
script = ExtResource("1_gscr")
@@ -197,10 +200,12 @@ anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -276.0
offset_top = -241.0
offset_right = -84.0
offset_bottom = -77.0
offset_left = -262.0
offset_top = -220.0
offset_right = -70.0
offset_bottom = -56.0
grow_horizontal = 0
grow_vertical = 0
theme_override_styles/panel = SubResource("StyleBoxFlat_ld7sk")
[node name="RailMargin" type="MarginContainer" parent="HUD/ActionRail"]
@@ -352,22 +357,58 @@ anchors_preset = -1
anchor_top = 1.0
anchor_right = 0.75
anchor_bottom = 1.0
offset_top = -250.0
offset_top = -248.0
offset_bottom = 2.0
theme_override_styles/panel = SubResource("StyleBoxEmpty_ld7sk")
[node name="HandScroll" type="ScrollContainer" parent="HUD/HandArea"]
[node name="HandScroll" type="Control" parent="HUD/HandArea"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_styles/panel = SubResource("StyleBoxEmpty_8asym")
vertical_scroll_mode = 0
[node name="HandCards" type="HBoxContainer" parent="HUD/HandArea/HandScroll"]
[node name="HandCards" type="Control" parent="HUD/HandArea/HandScroll"]
unique_name_in_owner = true
anchors_preset = 0
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="Panel" type="Panel" parent="HUD/HandArea"]
layout_mode = 2
size_flags_vertical = 4
theme_override_constants/separation = 6
theme_override_styles/panel = SubResource("StyleBoxEmpty_w2jaq")
[node name="HandSpinLeft" type="TextureButton" parent="HUD/HandArea/Panel"]
unique_name_in_owner = true
custom_minimum_size = Vector2(22, 22)
layout_mode = 0
offset_left = -2.0
offset_top = -4.0
offset_right = 69.0
offset_bottom = 104.0
scale = Vector2(1.9999998, 1.44)
texture_normal = ExtResource("6_pryjh")
ignore_texture_size = true
stretch_mode = 5
flip_h = true
[node name="Panel2" type="Panel" parent="HUD/HandArea"]
layout_mode = 2
theme_override_styles/panel = SubResource("StyleBoxEmpty_fuou0")
[node name="HandSpinRight" type="TextureButton" parent="HUD/HandArea/Panel2"]
unique_name_in_owner = true
custom_minimum_size = Vector2(22, 22)
layout_mode = 0
offset_left = 963.0
offset_top = 6.0
offset_right = 1030.0
offset_bottom = 108.0
scale = Vector2(2.08, 1.6)
texture_normal = ExtResource("6_pryjh")
ignore_texture_size = true
stretch_mode = 5
[node name="RightPanel" type="PanelContainer" parent="HUD"]
visible = false
+254 -14
View File
@@ -45,7 +45,7 @@ enum Mode {
@onready var _opp_hand_lbl : Label = %OppHandLabel
@onready var _opp_deck_lbl : Label = %OppDeckLabel
@onready var _opp_discard_btn : Button = %OppDiscardBtn
@onready var _hand_cards : HBoxContainer = %HandCards
@onready var _hand_cards : Control = %HandCards
@onready var _sp_lbl : Label = %SpLabel
@onready var _st_lbl : Label = %StLabel
@onready var _deck_lbl : Label = %DeckLabel
@@ -72,12 +72,16 @@ enum Mode {
@onready var _go_menu_btn : Button = %GOMainMenuBtn
@onready var _hud : CanvasLayer = $HUD
@onready var _hand_area : PanelContainer = $HUD/HandArea
@onready var _hand_spin_left : TextureButton = %HandSpinLeft
@onready var _hand_spin_right : TextureButton = %HandSpinRight
var count : int = 0
var _cam_tween : Tween = null
var _last_click_frame : int = -1
var _last_click_iid : String = ""
var _is_spectating : bool = false
var _hand_focus_index : int = 0
var _hand_hover_iid : String = ""
# ── Affinity colors ───────────────────────────────────────────────────────────
const AFFINITY_COLORS : Dictionary = {
@@ -107,6 +111,9 @@ const AFFINITY_COLORS : Dictionary = {
}
const _CARD_WIDGET_SCENE := preload("res://scenes/collection/components/CardWidget.tscn")
const _HAND_ARROW_REGULAR := preload("res://ui/icons/Green_Gem_Arrow_Button_Regular.png")
const _HAND_ARROW_HOVER := preload("res://ui/icons/Green_Gem_Arrow_Button_Hover.png")
const _HAND_ARROW_PRESSED := preload("res://ui/icons/Green_Gem_Arrow_Button_Click.png")
const HI_GREEN := Color(0.20, 0.90, 0.20, 0.40)
const HI_RED := Color(1.00, 0.25, 0.25, 0.50)
@@ -301,6 +308,8 @@ func _ready() -> void:
_settings_btn.pressed.connect(func() -> void: _in_game_settings.open())
_discard_btn.pressed.connect(func() -> void: _show_own_discard())
_opp_discard_btn.pressed.connect(func() -> void: _show_opp_discard())
_hand_spin_left.pressed.connect(func() -> void: _spin_hand(-1))
_hand_spin_right.pressed.connect(func() -> void: _spin_hand(1))
_tile_drawer_toggle_btn.pressed.connect(_on_tile_drawer_toggle_pressed)
_ctx_close_btn.pressed.connect(func() -> void: _ctx_popup.visible = false)
_dv_close_btn.pressed.connect(func() -> void: _dv_overlay.visible = false)
@@ -311,6 +320,10 @@ func _ready() -> void:
_cam_orbit_btn.toggled.connect(_on_cam_orbit_btn_toggled)
_cam_pan_btn.toggled.connect(_on_cam_pan_btn_toggled)
_cam_zoom_btn.toggled.connect(_on_cam_zoom_btn_toggled)
_hand_area.resized.connect(_queue_hand_layout)
_hand_area.resized.connect(_layout_hand_spin_buttons)
_hand_cards.resized.connect(_queue_hand_layout)
_configure_hand_spin_buttons()
_sync_cam_ctrl_panel()
Settings.settings_changed.connect(_sync_cam_ctrl_panel)
_create_tile_drawer()
@@ -897,10 +910,14 @@ func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouseButton:
var mb := event as InputEventMouseButton
if mb.button_index == MOUSE_BUTTON_WHEEL_UP:
if _hand_area.get_global_rect().has_point(mb.position): return
if _hand_area.get_global_rect().has_point(mb.position):
_spin_hand(-1)
return
_zoom(1.5); return
elif mb.button_index == MOUSE_BUTTON_WHEEL_DOWN:
if _hand_area.get_global_rect().has_point(mb.position): return
if _hand_area.get_global_rect().has_point(mb.position):
_spin_hand(1)
return
_zoom(-1.5); return
elif mb.button_index == MOUSE_BUTTON_MIDDLE:
_pan_active = mb.pressed
@@ -4433,8 +4450,16 @@ func _rebuild_hand(hand: Array) -> void:
for c in _hand_cards.get_children():
_hand_cards.remove_child(c)
c.queue_free()
if hand.is_empty():
_hand_focus_index = 0
_hand_hover_iid = ""
_sync_hand_spin_buttons()
return
_hand_focus_index = posmod(_hand_focus_index, hand.size())
for card: Dictionary in hand:
_hand_cards.add_child(_make_hand_card(card))
_queue_hand_layout()
_sync_hand_spin_buttons()
func _make_hand_card(card: Dictionary) -> Control:
@@ -4442,6 +4467,14 @@ func _make_hand_card(card: Dictionary) -> Control:
var def_id : String = str(card.get("cardDefinitionId", ""))
var widget : PanelContainer = _CARD_WIDGET_SCENE.instantiate()
widget.top_level = false
widget.anchor_left = 0.0
widget.anchor_top = 0.0
widget.anchor_right = 0.0
widget.anchor_bottom = 0.0
widget.position = Vector2.ZERO
widget.size = widget.custom_minimum_size
widget.visible = true
widget.set_meta("card_instance_id", iid)
# Use the full CardDefinitionDto from ContentCache so CardWidget gets the
@@ -4456,8 +4489,18 @@ func _make_hand_card(card: Dictionary) -> Control:
def["movementPoints"] = card.get("maxMp", def.get("movementPoints", null))
widget.setup(card, def)
widget.mouse_entered.connect(func() -> void:
_hand_hover_iid = iid
_layout_hand_cards())
widget.mouse_exited.connect(func() -> void:
if _hand_hover_iid == iid:
_hand_hover_iid = ""
_layout_hand_cards())
# CardWidget emits card_pressed(definition_id); forward as hand-card click.
# Note: _focus_hand_card is intentionally NOT called here — clicking a card
# brings it to front visually (via selection z_index boost) without shifting
# its position in the fan rotation.
widget.card_pressed.connect(func(_def_id: String) -> void:
_on_hand_card_clicked(iid, widget))
@@ -4465,13 +4508,13 @@ func _make_hand_card(card: Dictionary) -> Control:
func _refresh_hand_selection() -> void:
var needs_layout := false
for widget in _hand_cards.get_children():
if not widget.has_meta("card_instance_id"): continue
var iid : String = str(widget.get_meta("card_instance_id"))
var sel : bool = ((_mode == Mode.CARD_FROM_HAND
or _mode == Mode.TERRAMORPHA_SELECT)
and _sel_card_id == iid)
var prev_sel : bool = widget.get_meta("_sel", false)
if widget.has_method("set_selected"):
widget.set_selected(sel)
# Tween scale on selection change.
@@ -4479,21 +4522,17 @@ func _refresh_hand_selection() -> void:
# current input event is fully processed. Setting z_index synchronously
# while a mouse button is held causes Godot 4 to re-evaluate GUI focus
# and deliver a synthetic second pressed=true event → immediate deselect.
if sel != prev_sel:
if sel != bool(widget.get_meta("_sel", false)):
widget.set_meta("_sel", sel)
_tween_hand_card.call_deferred(widget, sel)
needs_layout = true
if needs_layout:
_queue_hand_layout()
func _tween_hand_card(widget: Control, sel: bool) -> void:
if not is_instance_valid(widget): return
widget.pivot_offset = widget.size * 0.5
var tw := create_tween()
if sel:
tw.tween_property(widget, "scale", Vector2(1.12, 1.12), 0.14)
widget.z_index = 20
else:
tw.tween_property(widget, "scale", Vector2(1.0, 1.0), 0.10)
widget.z_index = 0
widget.set_meta("_sel", sel)
_queue_hand_layout()
func _find_hand_card(iid: String) -> Dictionary:
@@ -4502,6 +4541,207 @@ func _find_hand_card(iid: String) -> Dictionary:
return card
return {}
func _configure_hand_spin_buttons() -> void:
_hand_spin_left.texture_normal = _HAND_ARROW_REGULAR
_hand_spin_left.texture_hover = _HAND_ARROW_HOVER
_hand_spin_left.texture_pressed = _HAND_ARROW_PRESSED
_hand_spin_left.modulate = Color(1, 1, 1, 0.92)
_hand_spin_left.focus_mode = Control.FOCUS_NONE
_hand_spin_left.rotation_degrees = 0.0
_hand_spin_right.texture_normal = _HAND_ARROW_REGULAR
_hand_spin_right.texture_hover = _HAND_ARROW_HOVER
_hand_spin_right.texture_pressed = _HAND_ARROW_PRESSED
_hand_spin_right.modulate = Color(1, 1, 1, 0.92)
_hand_spin_right.focus_mode = Control.FOCUS_NONE
_hand_spin_right.rotation_degrees = 0.0
_layout_hand_spin_buttons()
func _layout_hand_spin_buttons() -> void:
_hand_spin_left.anchor_left = 0.0
_hand_spin_left.anchor_top = 0.5
_hand_spin_left.anchor_right = 0.0
_hand_spin_left.anchor_bottom = 0.5
_hand_spin_left.offset_left = 8.0
_hand_spin_left.offset_top = -11.0
_hand_spin_left.offset_right = 30.0
_hand_spin_left.offset_bottom = 11.0
_hand_spin_left.custom_minimum_size = Vector2(22, 22)
_hand_spin_left.size = Vector2(22, 22)
_hand_spin_right.anchor_left = 1.0
_hand_spin_right.anchor_top = 0.5
_hand_spin_right.anchor_right = 1.0
_hand_spin_right.anchor_bottom = 0.5
_hand_spin_right.offset_left = -30.0
_hand_spin_right.offset_top = -11.0
_hand_spin_right.offset_right = -8.0
_hand_spin_right.offset_bottom = 11.0
_hand_spin_right.custom_minimum_size = Vector2(22, 22)
_hand_spin_right.size = Vector2(22, 22)
func _sync_hand_spin_buttons() -> void:
var enabled := _hand_cards.get_child_count() > 1
_hand_spin_left.visible = enabled
_hand_spin_right.visible = enabled
_hand_spin_left.disabled = not enabled
_hand_spin_right.disabled = not enabled
func _spin_hand(direction: int) -> void:
var card_count := _hand_cards.get_child_count()
if card_count <= 1:
return
if _mode == Mode.CARD_FROM_HAND:
_set_mode(Mode.NONE)
_hand_focus_index = posmod(_hand_focus_index + direction, card_count)
_layout_hand_cards()
func _focus_hand_card(iid: String) -> void:
var idx := 0
for widget in _hand_cards.get_children():
if str(widget.get_meta("card_instance_id", "")) == iid:
_hand_focus_index = idx
_layout_hand_cards()
return
idx += 1
func _queue_hand_layout() -> void:
if not is_inside_tree():
return
_layout_hand_cards.call_deferred()
func _layout_hand_cards() -> void:
var widgets := _hand_cards.get_children()
var widget_count := widgets.size()
if widget_count == 0:
return
_hand_focus_index = posmod(_hand_focus_index, widget_count)
_hand_cards.position = Vector2.ZERO
_hand_cards.size = _hand_area.size
var viewport_size := _hand_area.size
if viewport_size.x <= 0.0 or viewport_size.y <= 0.0:
return
var sample := widgets[0] as Control
sample.size = sample.custom_minimum_size
var sample_size := _hand_card_size(sample)
var side_margin : float = 40.0
var usable_width : float = maxf(120.0, viewport_size.x - side_margin * 2.0)
var max_rel := 0
var fan_half_width : float = minf(usable_width * 0.5 - sample_size.x * 0.5, 120.0 + widget_count * 18.0)
fan_half_width = maxf(fan_half_width, 0.0)
var fit_scale : float = minf(0.92, maxf(0.52, (viewport_size.y - 36.0) / sample_size.y))
var scaled_height : float = sample_size.y * fit_scale
var base_y : float = maxf(0.0, viewport_size.y - scaled_height - 28.0)
var arc_height : float = minf(34.0, viewport_size.y * 0.14)
var max_angle_deg : float = clampf(14.0 + widget_count * 2.4, 18.0, 34.0)
for i in range(widget_count):
max_rel = max(max_rel, abs(_wrapped_hand_delta(i, widget_count)))
for i in range(widget_count):
var widget := widgets[i] as Control
if widget == null:
continue
widget.size = widget.custom_minimum_size
var rel := _wrapped_hand_delta(i, widget_count)
var t : float = 0.0 if max_rel == 0 else float(rel) / float(max_rel)
var angle_deg : float = t * max_angle_deg
var card_size := _hand_card_size(widget)
var edge_factor : float = absf(t)
var lift : float = 0.0
var scale_amt : float = fit_scale * lerpf(1.0, 0.84, edge_factor)
var is_selected := bool(widget.get_meta("_sel", false))
var card_iid := str(widget.get_meta("card_instance_id", ""))
var is_hovered := card_iid == _hand_hover_iid
if is_selected:
scale_amt += 0.08
lift += 16.0
if is_hovered:
scale_amt += 0.10
lift += 30.0
var pos := Vector2.ZERO
pos.x = viewport_size.x * 0.5 + t * fan_half_width - (card_size.x * scale_amt) * 0.5
pos.y = base_y + float(pow(edge_factor, 1.35)) * arc_height - lift
pos.x = clampf(pos.x, side_margin, maxf(side_margin, viewport_size.x - side_margin - card_size.x * scale_amt))
pos.y = clampf(pos.y, 0.0, maxf(0.0, viewport_size.y - card_size.y * scale_amt))
var z := 20 + int((1.0 - edge_factor) * 100.0)
if is_selected:
z += 120
if is_hovered:
z += 240
widget.set_meta("_hand_stack", z)
_apply_hand_card_transform(widget, pos, deg_to_rad(angle_deg * 0.35), scale_amt, z)
_restack_hand_cards()
func _apply_hand_card_transform(widget: Control, pos: Vector2, rot: float, scale_amt: float, z: int) -> void:
widget.pivot_offset = _hand_card_size(widget) * 0.5
widget.z_index = z
var existing : Variant = widget.get_meta("_hand_tween", null)
if existing is Tween and is_instance_valid(existing):
(existing as Tween).kill()
var tw := create_tween().set_parallel(true)
tw.set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_OUT)
tw.tween_property(widget, "position", pos, 0.18)
tw.tween_property(widget, "rotation", rot, 0.18)
tw.tween_property(widget, "scale", Vector2.ONE * scale_amt, 0.18)
widget.set_meta("_hand_tween", tw)
func _restack_hand_cards() -> void:
var ordered : Array[Control] = []
for child in _hand_cards.get_children():
if child is Control:
ordered.append(child as Control)
ordered.sort_custom(func(a: Control, b: Control) -> bool:
var za : int = int(a.get_meta("_hand_stack", 0))
var zb : int = int(b.get_meta("_hand_stack", 0))
if za == zb:
return int(a.get_index()) < int(b.get_index())
return za < zb
)
for i in range(ordered.size()):
_hand_cards.move_child(ordered[i], i)
func _hand_card_size(widget: Control) -> Vector2:
var size_v := widget.size
if size_v.x <= 0.0 or size_v.y <= 0.0:
size_v = widget.custom_minimum_size
if size_v.x <= 0.0:
size_v.x = 160.0
if size_v.y <= 0.0:
size_v.y = 257.0
return size_v
func _wrapped_hand_delta(index: int, total: int) -> int:
var delta := index - _hand_focus_index
if total <= 1:
return 0
if delta > total / 2:
delta -= total
elif delta < -int(ceil(total * 0.5)):
delta += total
return delta
# ── HUD update ────────────────────────────────────────────────────────────────
func _update_hud(state: Dictionary) -> void: