From 8f37dd7e9b3b25bff4550d9fcbfd7629aa2242d2 Mon Sep 17 00:00:00 2001 From: dingo Date: Tue, 14 Apr 2026 22:54:01 -0400 Subject: [PATCH] feat(hand): cache hand by IID, fix click precision, double arrow button size - Skip widget rebuild when hand IIDs are unchanged; only refresh selection - Store _fan_slot metadata so _restack_hand_cards can reorder children by z-index (for correct GUI input routing) without corrupting fan positions - Double spin arrow hit targets from 22x22 to 44x44 Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- .../origin-client/scenes/game/game_screen.gd | 58 ++++++++++++++----- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/Client/origin-client/scenes/game/game_screen.gd b/Client/origin-client/scenes/game/game_screen.gd index c9b9a7a..02acb5c 100644 --- a/Client/origin-client/scenes/game/game_screen.gd +++ b/Client/origin-client/scenes/game/game_screen.gd @@ -82,6 +82,7 @@ var _last_click_iid : String = "" var _is_spectating : bool = false var _hand_focus_index : int = 0 var _hand_hover_iid : String = "" +var _cached_hand_iids : Array[String] = [] # ── Affinity colors ─────────────────────────────────────────────────────────── const AFFINITY_COLORS : Dictionary = { @@ -4442,6 +4443,15 @@ func _on_hand_card_clicked(iid: String, _panel: PanelContainer) -> void: # ── Hand display ────────────────────────────────────────────────────────────── func _rebuild_hand(hand: Array) -> void: + # Build the new IID list and skip a full rebuild if the hand hasn't changed. + var new_iids : Array[String] = [] + for card: Dictionary in hand: + new_iids.append(card.get("instanceId", "") as String) + if new_iids == _cached_hand_iids: + _refresh_hand_selection() + return + _cached_hand_iids = new_iids + # Use remove_child + queue_free (not queue_free alone) so stale widgets are # immediately pulled from the GUI tree. queue_free() alone keeps the node in # get_children() and receiving input events until end-of-frame; if two state @@ -4456,8 +4466,12 @@ func _rebuild_hand(hand: Array) -> void: _sync_hand_spin_buttons() return _hand_focus_index = posmod(_hand_focus_index, hand.size()) + var slot := 0 for card: Dictionary in hand: - _hand_cards.add_child(_make_hand_card(card)) + var widget := _make_hand_card(card) + widget.set_meta("_fan_slot", slot) + _hand_cards.add_child(widget) + slot += 1 _queue_hand_layout() _sync_hand_spin_buttons() @@ -4558,22 +4572,22 @@ func _layout_hand_spin_buttons() -> void: _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_left.offset_top = -22.0 + _hand_spin_left.offset_right = 52.0 + _hand_spin_left.offset_bottom = 22.0 + _hand_spin_left.custom_minimum_size = Vector2(44, 44) + _hand_spin_left.size = Vector2(44, 44) _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_left = -52.0 + _hand_spin_right.offset_top = -22.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) + _hand_spin_right.offset_bottom = 22.0 + _hand_spin_right.custom_minimum_size = Vector2(44, 44) + _hand_spin_right.size = Vector2(44, 44) func _sync_hand_spin_buttons() -> void: @@ -4638,7 +4652,8 @@ func _layout_hand_cards() -> void: 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))) + var slot_i := int((widgets[i] as Control).get_meta("_fan_slot", i)) + max_rel = max(max_rel, abs(_wrapped_hand_delta(slot_i, widget_count))) for i in range(widget_count): var widget := widgets[i] as Control @@ -4646,7 +4661,8 @@ func _layout_hand_cards() -> void: continue widget.size = widget.custom_minimum_size - var rel := _wrapped_hand_delta(i, widget_count) + var slot := int(widget.get_meta("_fan_slot", i)) + var rel := _wrapped_hand_delta(slot, 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) @@ -4671,6 +4687,22 @@ func _layout_hand_cards() -> void: _apply_hand_card_transform(widget, pos, deg_to_rad(angle_deg * 0.35), scale_amt, z) + # Reorder children by z so Godot routes GUI input to the visually topmost card. + # Positions are stable because we use _fan_slot metadata, not child index. + _restack_hand_cards() + + +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: + return int(a.get_meta("_hand_stack", 0)) < int(b.get_meta("_hand_stack", 0)) + ) + for i in range(ordered.size()): + _hand_cards.move_child(ordered[i], i) + 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