Stabilize hand click-through and spin controls

This commit is contained in:
dingo
2026-05-07 13:25:33 -04:00
parent d621d9b03e
commit f6210caef4
3 changed files with 320 additions and 95 deletions
@@ -1,7 +1,8 @@
class_name HandManager
extends Node
extends PanelContainer
signal hand_card_clicked(card_data: Dictionary)
signal hand_spin_requested(direction: int)
# ── Preloaded resources ───────────────────────────────────────────────────────
@@ -10,28 +11,41 @@ const _HAND_ARROW_REGULAR: Texture2D = preload("res://ui/icons/Green_Gem_Arrow_B
const _HAND_ARROW_HOVER: Texture2D = preload("res://ui/icons/Green_Gem_Arrow_Button_Hover.png")
const _HAND_ARROW_PRESSED: Texture2D = preload("res://ui/icons/Green_Gem_Arrow_Button_Click.png")
# ── Scene node refs ───────────────────────────────────────────────────────────
@onready var hand_cards : Control = %HandCards
@onready var _hand_spin_left : TextureButton = %HandSpinLeft
@onready var _hand_spin_right: TextureButton = %HandSpinRight
# ── Hand state ────────────────────────────────────────────────────────────────
var hand_focus_index: int = 0
var hand_scroll_time: float = 0.0
var hand_hover_iid: String = ""
var cached_hand_iids: Array = []
var pending_popup_cards: Array = []
var popup_layer: CanvasLayer = null
var sel_card_id: String = "" # set by selection_controller to highlight
var _spin_layout_iids: Array = []
var _spin_layout_viewport_size: Vector2 = Vector2.ZERO
var _spin_layout_bounds: Rect2 = Rect2()
var _spin_min_bounds: Rect2 = Rect2()
var _has_spin_layout_bounds: bool = false
var _has_spin_min_bounds: bool = false
var _spin_min_card_count: int = 0
# ── Node refs (set from parent) ───────────────────────────────────────────────
# ── Lifecycle ─────────────────────────────────────────────────────────────────
var hand_cards: Control = null
var hand_area: PanelContainer = null
var hand_spin_left: TextureButton = null
var hand_spin_right: TextureButton = null
var hud: CanvasLayer = null
func _ready() -> void:
mouse_filter = Control.MOUSE_FILTER_IGNORE
$HandScroll.mouse_filter = Control.MOUSE_FILTER_IGNORE
hand_cards.mouse_filter = Control.MOUSE_FILTER_IGNORE
configure_hand_spin_buttons()
resized.connect(queue_hand_layout)
resized.connect(layout_hand_spin_buttons)
hand_cards.resized.connect(queue_hand_layout)
# ── Public API ────────────────────────────────────────────────────────────────
## Called by game_screen when the hand card clicked event fires.
## Emits hand_card_clicked so game_screen can handle routing logic.
func on_hand_card_clicked(iid: String, _panel: PanelContainer) -> void:
var card: Dictionary = find_hand_card(iid)
if card.is_empty():
@@ -39,8 +53,29 @@ func on_hand_card_clicked(iid: String, _panel: PanelContainer) -> void:
emit_signal("hand_card_clicked", card)
func blocks_pointer(screen_pos: Vector2) -> bool:
if not visible or not is_inside_tree():
return false
if _control_contains_global_point(_hand_spin_left, screen_pos):
return true
if _control_contains_global_point(_hand_spin_right, screen_pos):
return true
for child: Node in hand_cards.get_children():
if child is Control and _control_contains_global_point(child as Control, screen_pos):
return true
return false
func _control_contains_global_point(control: Control, screen_pos: Vector2) -> bool:
if control == null or not is_instance_valid(control):
return false
if not control.visible or control.mouse_filter == Control.MOUSE_FILTER_IGNORE:
return false
var local_pos: Vector2 = control.get_global_transform().affine_inverse() * screen_pos
return Rect2(Vector2.ZERO, control.size).has_point(local_pos)
func rebuild_hand(hand: Array, is_spectating: bool) -> void:
# Build new IID list.
var new_iids: Array = []
for card: Dictionary in hand:
var raw_iid: Variant = card.get("instanceId")
@@ -51,12 +86,10 @@ func rebuild_hand(hand: Array, is_spectating: bool) -> void:
cached_hand_iids = new_iids
# Spectators have no playable hand — just clear any stale widgets and stop.
if is_spectating:
apply_display_hand([])
return
# Detect brand-new cards (not in previous server hand, not already queued).
var pending_iids: Array = []
for c: Dictionary in pending_popup_cards:
pending_iids.append(c.get("instanceId", "") as String)
@@ -68,14 +101,12 @@ func rebuild_hand(hand: Array, is_spectating: bool) -> void:
if iid not in cached_hand_iids and iid not in pending_iids:
brand_new.append(card)
# Drop pending popups for cards that left the hand (avoid typed-array filter).
var kept: Array = []
for c: Dictionary in pending_popup_cards:
if c.get("instanceId", "") in new_iids:
kept.append(c)
pending_popup_cards = kept
# Queue brand-new cards for popup; exclude them from the live hand display.
for card: Dictionary in brand_new:
pending_popup_cards.append(card)
@@ -83,7 +114,6 @@ func rebuild_hand(hand: Array, is_spectating: bool) -> void:
for c: Dictionary in pending_popup_cards:
popup_iids.append(c.get("instanceId", "") as String)
# Build the display hand (everything except cards waiting in popup queue).
var display_hand: Array = []
for card: Dictionary in hand:
if card.get("instanceId", "") not in popup_iids:
@@ -91,7 +121,6 @@ func rebuild_hand(hand: Array, is_spectating: bool) -> void:
apply_display_hand(display_hand)
# Kick off popup for the first pending card if nothing is showing yet.
if not pending_popup_cards.is_empty() and (popup_layer == null or not popup_layer.visible):
show_next_card_popup()
@@ -102,11 +131,11 @@ func apply_display_hand(hand: Array) -> void:
hand_cards.remove_child(c)
c.queue_free()
hand_focus_index = 0
hand_hover_iid = ""
_spin_layout_iids = []
_has_spin_layout_bounds = false
sync_hand_spin_buttons()
return
# 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"):
@@ -116,7 +145,6 @@ func apply_display_hand(hand: Array) -> void:
for card: Dictionary in hand:
hand_iids.append(card.get("instanceId", "") as String)
# Remove widgets for cards no longer in the display hand.
for iid: String in existing.keys():
if iid not in hand_iids:
var w: Node = existing[iid]
@@ -124,7 +152,6 @@ func apply_display_hand(hand: Array) -> void:
hand_cards.remove_child(w)
w.queue_free()
# Add widgets for new cards, update _fan_slot on all.
var slot: int = 0
for card: Dictionary in hand:
var iid: String = card.get("instanceId", "")
@@ -146,25 +173,21 @@ func show_next_card_popup() -> void:
return
var card: Dictionary = pending_popup_cards[0]
# Create (or reuse) a dedicated CanvasLayer above the HUD.
if popup_layer == null or not is_instance_valid(popup_layer):
popup_layer = CanvasLayer.new()
popup_layer.layer = 20
get_parent().add_child(popup_layer)
add_child(popup_layer)
# Clear any previous content.
for c in popup_layer.get_children():
c.queue_free()
popup_layer.visible = true
# Dim background — catches clicks that miss the card.
var bg: ColorRect = ColorRect.new()
bg.color = Color(0.0, 0.0, 0.0, 0.65)
bg.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
bg.mouse_filter = Control.MOUSE_FILTER_STOP
popup_layer.add_child(bg)
# Centred column: label + card.
var vbox: VBoxContainer = VBoxContainer.new()
vbox.set_anchors_preset(Control.PRESET_CENTER)
vbox.grow_horizontal = Control.GROW_DIRECTION_BOTH
@@ -190,7 +213,6 @@ func show_next_card_popup() -> void:
widget.setup(card, def)
vbox.add_child(widget)
# Either clicking the card or the background dismisses the popup.
bg.gui_input.connect(func(ev: InputEvent) -> void:
if ev is InputEventMouseButton and (ev as InputEventMouseButton).pressed:
dismiss_card_popup())
@@ -202,26 +224,21 @@ func dismiss_card_popup() -> void:
return
var card: Dictionary = pending_popup_cards.pop_front()
# Hide the overlay.
if is_instance_valid(popup_layer):
popup_layer.visible = false
# Build the updated display hand: currently shown widgets + this newly added card.
var display_iids: Array = []
for child in hand_cards.get_children():
if child.has_meta("card_instance_id"):
display_iids.append(str(child.get_meta("card_instance_id")))
display_iids.append(card.get("instanceId", "") as String)
# Reconstruct display hand in server order (from cached_hand_iids).
var display_hand: Array = []
for iid: String in cached_hand_iids:
if iid in display_iids:
# Find the card dict; use the drawn card if it matches.
if iid == card.get("instanceId", ""):
display_hand.append(card)
else:
# Pull from live Game hand for existing cards.
for hc: Dictionary in Game.get_hand():
if hc.get("instanceId", "") == iid:
display_hand.append(hc)
@@ -229,7 +246,6 @@ func dismiss_card_popup() -> void:
apply_display_hand(display_hand)
# Show next queued popup if any.
if not pending_popup_cards.is_empty():
show_next_card_popup()
@@ -249,23 +265,12 @@ func make_hand_card(card: Dictionary) -> Control:
widget.visible = true
widget.set_meta("card_instance_id", iid)
# Use the full CardDefinitionDto from ContentCache so CardWidget gets the
# assets array (Art2D cdnUrl) and can load card art. Fall back to the
# instance data if the definition hasn't been synced yet.
var def: Dictionary = ContentCache.get_definition(def_id)
if def.is_empty():
def = card.duplicate()
# CardWidget._load_stats reads "movementPoints"; the CardInstanceDto calls
# it "maxMp", so alias it into the def dict before passing.
def["movementPoints"] = card.get("maxMp", def.get("movementPoints", null))
widget.setup(card, def)
# 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))
@@ -281,11 +286,6 @@ func refresh_hand_selection() -> void:
var sel: bool = sel_card_id == iid and not sel_card_id.is_empty()
if widget.has_method("set_selected"):
widget.set_selected(sel)
# Tween scale on selection change.
# IMPORTANT: defer the tween + z_index update so they run AFTER the
# 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 != bool(widget.get_meta("_sel", false)):
widget.set_meta("_sel", sel)
needs_layout = true
@@ -308,52 +308,64 @@ func find_hand_card(iid: String) -> Dictionary:
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_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
if not _hand_spin_left.pressed.is_connected(_on_hand_spin_left_pressed):
_hand_spin_left.pressed.connect(_on_hand_spin_left_pressed)
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
_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
if not _hand_spin_right.pressed.is_connected(_on_hand_spin_right_pressed):
_hand_spin_right.pressed.connect(_on_hand_spin_right_pressed)
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 = -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)
func _on_hand_spin_left_pressed() -> void:
hand_spin_requested.emit(-1)
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 = -52.0
hand_spin_right.offset_top = -22.0
hand_spin_right.offset_right = -8.0
hand_spin_right.offset_bottom = 22.0
hand_spin_right.custom_minimum_size = Vector2(44, 44)
hand_spin_right.size = Vector2(44, 44)
func _on_hand_spin_right_pressed() -> void:
hand_spin_requested.emit(1)
func layout_hand_spin_buttons() -> void:
_hand_spin_left.anchor_left = 0.0
_hand_spin_left.anchor_top = 0.0
_hand_spin_left.anchor_right = 0.0
_hand_spin_left.anchor_bottom = 0.0
_hand_spin_left.offset_left = 8.0
_hand_spin_left.offset_top = 103.0
_hand_spin_left.offset_right = 52.0
_hand_spin_left.offset_bottom = 147.0
#_hand_spin_left.custom_minimum_size = Vector2(44, 44)
#_hand_spin_left.size = Vector2(44, 44)
_hand_spin_right.anchor_left = 0.0
_hand_spin_right.anchor_top = 0.0
_hand_spin_right.anchor_right = 0.0
_hand_spin_right.anchor_bottom = 0.0
_hand_spin_right.offset_left = maxf(8.0, size.x - 52.0)
_hand_spin_right.offset_top = 103.0
_hand_spin_right.offset_right = maxf(52.0, size.x - 8.0)
_hand_spin_right.offset_bottom = 147.0
#_hand_spin_right.custom_minimum_size = Vector2(44, 44)
#_hand_spin_right.size = Vector2(44, 44)
func sync_hand_spin_buttons() -> void:
var enabled: bool = 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
_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:
@@ -388,15 +400,15 @@ func layout_hand_cards() -> void:
hand_focus_index = posmod(hand_focus_index, widget_count)
hand_cards.position = Vector2.ZERO
hand_cards.size = hand_area.size
var viewport_size: Vector2 = hand_area.size
hand_cards.size = size # self IS the hand area
var viewport_size: Vector2 = size
if viewport_size.x <= 0.0 or viewport_size.y <= 0.0:
return
var sample: Control = widgets[0] as Control
sample.size = sample.custom_minimum_size
var sample_size: Vector2 = hand_card_size(sample)
var side_margin: float = 40.0
var side_margin: float = 64.0 if widget_count > 1 else 40.0
var usable_width: float = maxf(120.0, viewport_size.x - side_margin * 2.0)
var max_rel: int = 0
var fan_half_width: float = minf(usable_width * 0.5 - sample_size.x * 0.5, 120.0 + widget_count * 18.0)
@@ -411,6 +423,10 @@ func layout_hand_cards() -> void:
var slot_i: int = int((widgets[i] as Control).get_meta("_fan_slot", i))
max_rel = max(max_rel, abs(wrapped_hand_delta(slot_i, widget_count)))
var hand_bounds: Rect2 = Rect2()
var has_hand_bounds: bool = false
var layout_entries: Array = []
for i in range(widget_count):
var widget: Control = widgets[i] as Control
if widget == null:
@@ -441,10 +457,31 @@ func layout_hand_cards() -> void:
z += 120
widget.set_meta("_hand_stack", z)
apply_hand_card_transform(widget, pos, deg_to_rad(angle_deg * 0.35), scale_amt, z)
var rot: float = deg_to_rad(angle_deg * 0.35)
var card_bounds: Rect2 = transformed_card_rect(pos, card_size, rot, scale_amt)
hand_bounds = card_bounds if not has_hand_bounds else hand_bounds.merge(card_bounds)
has_hand_bounds = true
layout_entries.append({
"widget": widget,
"position": pos,
"rotation": rot,
"scale": scale_amt,
"z": z,
})
if has_hand_bounds:
var stable_bounds: Rect2 = stable_hand_spin_bounds(hand_bounds, viewport_size)
var fan_offset: Vector2 = stable_bounds.get_center() - hand_bounds.get_center()
for entry: Dictionary in layout_entries:
apply_hand_card_transform(
entry["widget"] as Control,
(entry["position"] as Vector2) + fan_offset,
float(entry["rotation"]),
float(entry["scale"]),
int(entry["z"]))
layout_hand_spin_buttons_near_cards(stable_bounds)
# 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()
@@ -460,6 +497,112 @@ func restack_hand_cards() -> void:
hand_cards.move_child(ordered[i], i)
func stable_hand_spin_bounds(current_bounds: Rect2, viewport_size: Vector2) -> Rect2:
var current_iids: Array = current_display_hand_iids()
if not _has_spin_min_bounds or (_spin_min_card_count <= 1 and current_iids.size() > 1):
_spin_min_bounds = current_bounds
_has_spin_min_bounds = true
_spin_min_card_count = current_iids.size()
var next_bounds: Rect2 = expand_rect_to_min_size(current_bounds, _spin_min_bounds.size)
var membership_changed: bool = current_iids != _spin_layout_iids
var viewport_changed: bool = (
absf(viewport_size.x - _spin_layout_viewport_size.x) > 0.5
or absf(viewport_size.y - _spin_layout_viewport_size.y) > 0.5
)
if not _has_spin_layout_bounds or membership_changed or viewport_changed:
_spin_layout_iids = current_iids
_spin_layout_viewport_size = viewport_size
_spin_layout_bounds = next_bounds
_has_spin_layout_bounds = true
return _spin_layout_bounds
func current_display_hand_iids() -> Array:
var iids: Array = []
for child: Node in hand_cards.get_children():
if child.has_meta("card_instance_id"):
iids.append(str(child.get_meta("card_instance_id")))
iids.sort()
return iids
func expand_rect_to_min_size(rect: Rect2, min_size: Vector2) -> Rect2:
var next_size: Vector2 = Vector2(
maxf(rect.size.x, min_size.x),
maxf(rect.size.y, min_size.y)
)
return Rect2(rect.get_center() - next_size * 0.5, next_size)
func layout_hand_spin_buttons_near_cards(hand_bounds: Rect2) -> void:
var button_size: Vector2 = Vector2(44.0, 44.0)
var gap: float = 10.0
var y: float = clampf(
hand_bounds.get_center().y - button_size.y * 0.5,
4.0,
maxf(4.0, size.y - button_size.y - 4.0))
var left_x: float = clampf(
hand_bounds.position.x - gap - button_size.x,
4.0,
maxf(4.0, size.x - button_size.x - 4.0))
var right_x: float = clampf(
hand_bounds.end.x + gap,
4.0,
maxf(4.0, size.x - button_size.x - 4.0))
position_hand_spin_button(_hand_spin_left, Vector2(left_x, y), button_size)
position_hand_spin_button(_hand_spin_right, Vector2(right_x, y), button_size)
func position_hand_spin_button(button: TextureButton, pos: Vector2, button_size: Vector2) -> void:
var parent_control: Control = button.get_parent() as Control
var local_pos: Vector2 = pos
if parent_control != null:
var global_pos: Vector2 = get_global_transform() * pos
local_pos = parent_control.get_global_transform().affine_inverse() * global_pos
button.anchor_left = 0.0
button.anchor_top = 0.0
button.anchor_right = 0.0
button.anchor_bottom = 0.0
button.offset_left = local_pos.x
button.offset_top = local_pos.y
button.offset_right = local_pos.x + button_size.x
button.offset_bottom = local_pos.y + button_size.y
func transformed_card_rect(pos: Vector2, card_size: Vector2, rot: float, scale_amt: float) -> Rect2:
var pivot: Vector2 = card_size * 0.5
var basis_x: Vector2 = Vector2(cos(rot), sin(rot)) * scale_amt
var basis_y: Vector2 = Vector2(-sin(rot), cos(rot)) * scale_amt
var corners: Array[Vector2] = [
transformed_card_corner(pos, pivot, basis_x, basis_y, Vector2(0.0, 0.0)),
transformed_card_corner(pos, pivot, basis_x, basis_y, Vector2(card_size.x, 0.0)),
transformed_card_corner(pos, pivot, basis_x, basis_y, Vector2(card_size.x, card_size.y)),
transformed_card_corner(pos, pivot, basis_x, basis_y, Vector2(0.0, card_size.y)),
]
var min_pos: Vector2 = corners[0]
var max_pos: Vector2 = corners[0]
for corner: Vector2 in corners:
min_pos.x = minf(min_pos.x, corner.x)
min_pos.y = minf(min_pos.y, corner.y)
max_pos.x = maxf(max_pos.x, corner.x)
max_pos.y = maxf(max_pos.y, corner.y)
return Rect2(min_pos, max_pos - min_pos)
func transformed_card_corner(
pos: Vector2,
pivot: Vector2,
basis_x: Vector2,
basis_y: Vector2,
corner: Vector2) -> Vector2:
var local: Vector2 = corner - pivot
return pos + pivot + basis_x * local.x + basis_y * local.y
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
@@ -467,8 +610,6 @@ 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
@@ -0,0 +1,74 @@
[gd_scene load_steps=6 format=3 uid="uid://cowqg2xdx0x7g"]
[ext_resource type="Script" uid="uid://cjntlh271gouc" path="res://scenes/game/components/hud/hand_manager.gd" id="1_script"]
[ext_resource type="Texture2D" uid="uid://psjb7swm36jx" path="res://ui/icons/Green_Gem_Arrow_Button_Click.png" id="2_arrow"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_hand"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_panel"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_panel2"]
[node name="HandManager" type="PanelContainer"]
anchors_preset = -1
anchor_top = 1.0
anchor_right = 0.75
anchor_bottom = 1.0
offset_top = -248.0
offset_bottom = 2.0
mouse_filter = 2
theme_override_styles/panel = SubResource("StyleBoxEmpty_hand")
script = ExtResource("1_script")
[node name="HandScroll" type="Control" parent="."]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
mouse_filter = 2
[node name="HandCards" type="Control" parent="HandScroll"]
unique_name_in_owner = true
anchors_preset = 0
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
[node name="Panel" type="Panel" parent="."]
layout_mode = 2
mouse_filter = 2
theme_override_styles/panel = SubResource("StyleBoxEmpty_panel")
[node name="HandSpinLeft" type="TextureButton" parent="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("2_arrow")
ignore_texture_size = true
stretch_mode = 5
flip_h = true
[node name="Panel2" type="Panel" parent="."]
layout_mode = 2
mouse_filter = 2
theme_override_styles/panel = SubResource("StyleBoxEmpty_panel2")
[node name="HandSpinRight" type="TextureButton" parent="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("2_arrow")
ignore_texture_size = true
stretch_mode = 5
@@ -127,7 +127,7 @@ func _input(event: InputEvent) -> void:
if mb.button_index == MOUSE_BUTTON_LEFT and mb.pressed and not mb.double_click:
var is_card_active: bool = card_mode_active or ability_card_active
if is_card_active:
if hand_area != null and not hand_area.get_global_rect().has_point(mb.position):
if not _hand_blocks_pointer(mb.position):
_deselect_pending = true
_do_deselect_if_pending.call_deferred()
@@ -175,6 +175,8 @@ func _unhandled_input(event: InputEvent) -> void:
last_mouse = mb.position
elif mb.button_index == MOUSE_BUTTON_LEFT:
if mb.pressed:
if _hand_blocks_pointer(mb.position):
return
# Double-click on a battlefield unit → show full card detail popup.
if mb.double_click:
var dbl_unit_id: String = ""
@@ -364,3 +366,11 @@ func _touch_pair_mid() -> Vector2:
if keys.size() < 2:
return Vector2.ZERO
return ((touch_points[keys[0]] as Vector2) + (touch_points[keys[1]] as Vector2)) * 0.5
func _hand_blocks_pointer(screen_pos: Vector2) -> bool:
if hand_area == null or not is_instance_valid(hand_area):
return false
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)