From afa9e73489e0dfbf6a9851e0d0cab13f2e8bbace Mon Sep 17 00:00:00 2001 From: dingo Date: Wed, 15 Apr 2026 09:31:30 -0400 Subject: [PATCH] fix(hand): scroll throttle, deselect on spin/click-outside for all card modes - Throttle hand scroll to one step per 150 ms so each wheel tick advances exactly one card - Deselect selected card when clicking outside the hand area (deferred flag pattern so board clicks still play the card) - Extend spin and click-outside deselect to cover TERRAMORPHA_SELECT and card-triggered ABILITY_TARGET (Repentance/Instinct), not just CARD_FROM_HAND - Show Repentance/Instinct cards as visually selected in hand when in ABILITY_TARGET mode - Drop stale spectator state_update pushes from wrong sessions - Auto-create missing audio buses on Settings._ready to avoid bus-not-found errors Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- Client/origin-client/autoloads/Game.gd | 6 +++ Client/origin-client/autoloads/Settings.gd | 10 ++++ .../origin-client/scenes/game/GameScreen.tscn | 13 +++--- .../origin-client/scenes/game/game_screen.gd | 46 ++++++++++++++++--- 4 files changed, 63 insertions(+), 12 deletions(-) diff --git a/Client/origin-client/autoloads/Game.gd b/Client/origin-client/autoloads/Game.gd index 75669cb..83eb01a 100644 --- a/Client/origin-client/autoloads/Game.gd +++ b/Client/origin-client/autoloads/Game.gd @@ -603,6 +603,12 @@ func _on_server_push(type: String, payload: Variant) -> void: var d := payload as Dictionary var s := d.get("state", {}) as Dictionary if not s.is_empty(): + # Drop stale spectator pushes that belong to a session we already left. + var update_sid : String = str(s.get("sessionId", "")) + if not session_id.is_empty() and update_sid != session_id: + if debug_output: + print("[Game] PUSH state_update IGNORED (wrong session): ", update_sid) + return _state_version = int(s.get("stateVersion", -1)) if debug_output: print("[Game] PUSH state_update phase=", s.get("phase","?"), diff --git a/Client/origin-client/autoloads/Settings.gd b/Client/origin-client/autoloads/Settings.gd index 0b11729..9efbf64 100644 --- a/Client/origin-client/autoloads/Settings.gd +++ b/Client/origin-client/autoloads/Settings.gd @@ -119,12 +119,22 @@ func clear_highlight_override(type: String) -> void: # ── Lifecycle ───────────────────────────────────────────────────────────────── func _ready() -> void: + _ensure_buses() _load() _apply_music() _apply_sfx() # ── Internal ────────────────────────────────────────────────────────────────── +func _ensure_buses() -> void: + for bus_name in [BUS_MUSIC, BUS_SFX]: + if AudioServer.get_bus_index(bus_name) < 0: + var idx := AudioServer.bus_count + AudioServer.add_bus() + AudioServer.set_bus_name(idx, bus_name) + AudioServer.set_bus_send(idx, "Master") + + func _apply_music() -> void: var idx := AudioServer.get_bus_index(BUS_MUSIC) if idx < 0: diff --git a/Client/origin-client/scenes/game/GameScreen.tscn b/Client/origin-client/scenes/game/GameScreen.tscn index e23a458..e277960 100644 --- a/Client/origin-client/scenes/game/GameScreen.tscn +++ b/Client/origin-client/scenes/game/GameScreen.tscn @@ -13,6 +13,7 @@ [sub_resource type="Theme" id="Theme_056su"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ld7sk"] +bg_color = Color(0.38039216, 0.38039216, 0.38039216, 0.58431375) [sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_xjmfi"] @@ -574,12 +575,6 @@ layout_mode = 2 theme_override_font_sizes/font_size = 15 text = "Return to Main Menu" -[node name="SettingsLayer" type="CanvasLayer" parent="."] -layer = 15 - -[node name="InGameSettings" parent="SettingsLayer" instance=ExtResource("2_igs")] -unique_name_in_owner = true - [node name="CamCtrlPanel" type="PanelContainer" parent="HUD"] unique_name_in_owner = true visible = false @@ -613,6 +608,12 @@ layout_mode = 2 toggle_mode = true text = "Zoom" +[node name="SettingsLayer" type="CanvasLayer" parent="."] +layer = 15 + +[node name="InGameSettings" parent="SettingsLayer" instance=ExtResource("2_igs")] +unique_name_in_owner = true + [node name="HoldTimer" type="Timer" parent="."] unique_name_in_owner = true wait_time = 0.5 diff --git a/Client/origin-client/scenes/game/game_screen.gd b/Client/origin-client/scenes/game/game_screen.gd index 5ca595e..39891e1 100644 --- a/Client/origin-client/scenes/game/game_screen.gd +++ b/Client/origin-client/scenes/game/game_screen.gd @@ -81,6 +81,8 @@ var _last_click_frame : int = -1 var _last_click_iid : String = "" var _is_spectating : bool = false var _hand_focus_index : int = 0 +var _hand_scroll_time : float = 0.0 # monotonic time of last hand scroll +var _deselect_pending : bool = false # set in _input, cleared by board unhandled click var _hand_hover_iid : String = "" var _cached_hand_iids : Array[String] = [] var _pending_popup_cards : Array[Dictionary] = [] @@ -916,17 +918,47 @@ func _on_cam_gesture_timer_fired() -> void: # ── Input ───────────────────────────────────────────────────────────────────── +func _input(event: InputEvent) -> void: + if event is InputEventMouseButton: + var mb := event as InputEventMouseButton + if mb.button_index == MOUSE_BUTTON_LEFT and mb.pressed and not mb.double_click: + var _card_mode_active := _mode in [Mode.CARD_FROM_HAND, Mode.TERRAMORPHA_SELECT] or \ + (_mode == Mode.ABILITY_TARGET and not _ability_card_id.is_empty()) + if _card_mode_active: + if not _hand_area.get_global_rect().has_point(mb.position): + _deselect_pending = true + _do_deselect_if_pending.call_deferred() + + +func _do_deselect_if_pending() -> void: + if _deselect_pending: + _deselect_pending = false + if _mode in [Mode.CARD_FROM_HAND, Mode.TERRAMORPHA_SELECT] or \ + (_mode == Mode.ABILITY_TARGET and not _ability_card_id.is_empty()): + _set_mode(Mode.NONE) + + func _unhandled_input(event: InputEvent) -> void: if event is InputEventMouseButton: var mb := event as InputEventMouseButton + # Left-click reaching here is a board click — cancel any pending deselect + # so _do_deselect_if_pending won't wipe selection before the card is played. + if mb.button_index == MOUSE_BUTTON_LEFT and mb.pressed: + _deselect_pending = false if mb.button_index == MOUSE_BUTTON_WHEEL_UP: if _hand_area.get_global_rect().has_point(mb.position): - _spin_hand(-1) + var now := Time.get_ticks_msec() / 1000.0 + if now - _hand_scroll_time >= 0.15: + _hand_scroll_time = now + _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): - _spin_hand(1) + var now := Time.get_ticks_msec() / 1000.0 + if now - _hand_scroll_time >= 0.15: + _hand_scroll_time = now + _spin_hand(1) return _zoom(-1.5); return elif mb.button_index == MOUSE_BUTTON_MIDDLE: @@ -4455,7 +4487,7 @@ func _rebuild_hand(hand: Array) -> void: # Build new IID list. var new_iids : Array[String] = [] for card: Dictionary in hand: - var raw_iid := card.get("instanceId") + var raw_iid : Variant = card.get("instanceId") new_iids.append(str(raw_iid) if raw_iid != null else "") if new_iids == _cached_hand_iids: _refresh_hand_selection() @@ -4690,7 +4722,8 @@ func _refresh_hand_selection() -> void: 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) + or _mode == Mode.TERRAMORPHA_SELECT + or (_mode == Mode.ABILITY_TARGET and not _ability_card_id.is_empty())) and _sel_card_id == iid) if widget.has_method("set_selected"): widget.set_selected(sel) @@ -4772,7 +4805,8 @@ 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: + if _mode in [Mode.CARD_FROM_HAND, Mode.TERRAMORPHA_SELECT] or \ + (_mode == Mode.ABILITY_TARGET and not _ability_card_id.is_empty()): _set_mode(Mode.NONE) _hand_focus_index = posmod(_hand_focus_index + direction, card_count) _layout_hand_cards() @@ -4928,7 +4962,7 @@ func _update_hud(state: Dictionary) -> void: var is_mine : bool = (not _is_spectating) and Game.is_my_turn() var my : Dictionary = Game.get_my_player() var opp : Dictionary = Game.get_opponent() - print("[MY]", my) + #print("[MY]", my) _phase_lbl.text = "Phase: %s" % phase if _is_spectating: var active_id : String = str(state.get("activePlayerAccountId", ""))