diff --git a/Client/origin-client/scenes/game/components/hud/hand_manager.gd b/Client/origin-client/scenes/game/components/hud/hand_manager.gd index 037f5ff..799eb69 100644 --- a/Client/origin-client/scenes/game/components/hud/hand_manager.gd +++ b/Client/origin-client/scenes/game/components/hud/hand_manager.gd @@ -606,9 +606,11 @@ func transformed_card_corner( 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() + if widget.has_meta("_hand_tween"): + var existing: Variant = widget.get_meta("_hand_tween") + if existing is Tween and is_instance_valid(existing): + (existing as Tween).kill() + widget.remove_meta("_hand_tween") if not widget.has_meta("_hand_positioned"): widget.set_meta("_hand_positioned", true) diff --git a/Client/origin-client/scenes/game/components/input/board_input_handler.gd b/Client/origin-client/scenes/game/components/input/board_input_handler.gd index 32bba0f..ae45288 100644 --- a/Client/origin-client/scenes/game/components/input/board_input_handler.gd +++ b/Client/origin-client/scenes/game/components/input/board_input_handler.gd @@ -129,8 +129,11 @@ func _input(event: InputEvent) -> void: var is_card_active: bool = card_mode_active or ability_card_active if is_card_active: if not _hand_blocks_pointer(mb.position): - _deselect_pending = true - _do_deselect_if_pending.call_deferred() + if _pointer_hits_board_target(mb.position): + _deselect_pending = false + else: + _deselect_pending = true + _do_deselect_if_pending.call_deferred() # ── Deselect-if-pending (called deferred so board click can cancel it first) ── @@ -377,3 +380,14 @@ func _hand_blocks_pointer(screen_pos: Vector2) -> bool: if hand_area.has_method("blocks_pointer"): return bool(hand_area.call("blocks_pointer", screen_pos)) return hand_area.get_global_rect().has_point(screen_pos) + + +func _pointer_hits_board_target(screen_pos: Vector2) -> bool: + if fn_mouse_to_tile_coord.is_valid(): + var coord: Vector2i = fn_mouse_to_tile_coord.call(screen_pos) + if coord.x >= 0: + return true + if fn_mouse_to_unit_id.is_valid(): + var unit_id: String = str(fn_mouse_to_unit_id.call(screen_pos)) + return not unit_id.is_empty() + return false diff --git a/Client/origin-client/scenes/game/components/selection/selection_controller.gd b/Client/origin-client/scenes/game/components/selection/selection_controller.gd index 965963f..268c935 100644 --- a/Client/origin-client/scenes/game/components/selection/selection_controller.gd +++ b/Client/origin-client/scenes/game/components/selection/selection_controller.gd @@ -210,7 +210,7 @@ func _handle_forced_target_click(coord: Vector2i, unit_id: String) -> void: collected = true if not collected: - set_mode(Mode.NONE) + return elif ability_targeting.ability_targets_this_action >= ability_targeting.ability_target_n: ability_targeting.ability_cur_action_idx += 1 ability_targeting.advance_ability_targeting() @@ -242,6 +242,9 @@ func _handle_card_from_hand_click(coord: Vector2i) -> void: if coord.x < 0: set_mode(Mode.NONE) return + if tile_target_resolver != null and card_type == "Spirit" \ + and not tile_target_resolver.valid_play_tiles(card, tile_bodies).has(coord): + return Game.send_play_card(sel_card_id, coord.x, coord.y) set_mode(Mode.NONE) @@ -331,7 +334,6 @@ func _handle_ability_target_click(coord: Vector2i, unit_id: String) -> void: var resolved: String = _resolve_occupant(coord, unit_id) if not ability_targeting.is_valid_board_target(coord, resolved): - set_mode(Mode.NONE) return var collected: bool = false @@ -358,7 +360,7 @@ func _handle_ability_target_click(coord: Vector2i, unit_id: String) -> void: collected = true if not collected: - set_mode(Mode.NONE) + return elif ability_targeting.ability_targets_this_action >= ability_targeting.ability_target_n: ability_targeting.ability_cur_action_idx += 1 ability_targeting.advance_ability_targeting() diff --git a/Client/origin-client/scenes/game/game_screen.gd b/Client/origin-client/scenes/game/game_screen.gd index 8bc6d09..810c462 100644 --- a/Client/origin-client/scenes/game/game_screen.gd +++ b/Client/origin-client/scenes/game/game_screen.gd @@ -269,6 +269,8 @@ func _ready() -> void: _input_handler.board_zoom.connect(_on_board_zoom) _input_handler.hand_scroll.connect(_on_hand_scroll) _input_handler.deselect_pending.connect(_on_deselect_pending) + _sel_ctrl.mode_changed.connect(_on_selection_mode_changed) + _on_selection_mode_changed(_sel_ctrl.mode) # ── 3. Wire scene-based components ──────────────────────────────────────── @@ -615,6 +617,15 @@ func _on_deselect_pending() -> void: or cm == SelectionController.Mode.TERRAMORPHA_SELECT: _sel_ctrl.set_mode(SelectionController.Mode.NONE) + +func _on_selection_mode_changed(new_mode: int) -> void: + if _input_handler == null: + return + _input_handler.card_mode_active = new_mode == SelectionController.Mode.CARD_FROM_HAND \ + or new_mode == SelectionController.Mode.TERRAMORPHA_SELECT + _input_handler.ability_card_active = new_mode == SelectionController.Mode.ABILITY_TARGET \ + and _abt != null and not _abt.ability_card_id.is_empty() + # ── Hand card click routing ─────────────────────────────────────────────────── func _on_hand_card_clicked(card_data: Dictionary) -> void: