diff --git a/Client/origin-client/scenes/game/game_screen.gd b/Client/origin-client/scenes/game/game_screen.gd index 02acb5c..4b98c9f 100644 --- a/Client/origin-client/scenes/game/game_screen.gd +++ b/Client/origin-client/scenes/game/game_screen.gd @@ -4443,7 +4443,7 @@ 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. + # Build new IID list. var new_iids : Array[String] = [] for card: Dictionary in hand: new_iids.append(card.get("instanceId", "") as String) @@ -4452,26 +4452,44 @@ func _rebuild_hand(hand: Array) -> void: 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 - # updates arrive in the same frame we'd have two overlapping CardWidgets at the - # same position → two card_pressed emissions → double _on_hand_card_clicked. - for c in _hand_cards.get_children(): - _hand_cards.remove_child(c) - c.queue_free() if hand.is_empty(): + for c in _hand_cards.get_children(): + _hand_cards.remove_child(c) + c.queue_free() _hand_focus_index = 0 _hand_hover_iid = "" _sync_hand_spin_buttons() return - _hand_focus_index = posmod(_hand_focus_index, hand.size()) + + # Map existing widgets by IID so we can reuse them. + var existing : Dictionary = {} + for child in _hand_cards.get_children(): + if child.has_meta("card_instance_id"): + existing[str(child.get_meta("card_instance_id"))] = child + + # Remove widgets for cards that left the hand. + # Use remove_child + queue_free so the node leaves the GUI tree immediately; + # queue_free alone keeps it in get_children() until end-of-frame. + for iid: String in existing.keys(): + if iid not in new_iids: + var w : Node = existing[iid] + existing.erase(iid) + _hand_cards.remove_child(w) + w.queue_free() + + # Add widgets for cards newly in the hand, update _fan_slot on all. var slot := 0 for card: Dictionary in hand: - var widget := _make_hand_card(card) - widget.set_meta("_fan_slot", slot) - _hand_cards.add_child(widget) + var iid : String = card.get("instanceId", "") + if not existing.has(iid): + var widget := _make_hand_card(card) + widget.set_meta("_fan_slot", slot) + _hand_cards.add_child(widget) + else: + (existing[iid] as Control).set_meta("_fan_slot", slot) slot += 1 + + _hand_focus_index = posmod(_hand_focus_index, hand.size()) _queue_hand_layout() _sync_hand_spin_buttons() @@ -4711,6 +4729,15 @@ func _apply_hand_card_transform(widget: Control, pos: Vector2, rot: float, scale if existing is Tween and is_instance_valid(existing): (existing as Tween).kill() + # New widgets have never been positioned — snap them in place so they don't + # slide in from (0,0). All subsequent layout calls tween normally. + if not widget.has_meta("_hand_positioned"): + widget.set_meta("_hand_positioned", true) + widget.position = pos + widget.rotation = rot + widget.scale = Vector2.ONE * scale_amt + return + 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)