Below 45% zoom a CardShield covers each card and collapsed group: the name shows as a tooltip, dragging moves it, right-click opens its menu, and in Play a click rolls it. Zoom back in and the card's own controls return. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
1.7 KiB
GDScript
49 lines
1.7 KiB
GDScript
class_name CardShield
|
|
extends Control
|
|
## Zoomed out (below BoardView.COMPACT_ZOOM) a card's buttons are too small to
|
|
## hit, so this cover takes the mouse instead: the name shows as a tooltip,
|
|
## dragging moves the card (or group), right-click opens its menu, and in Play
|
|
## a click rolls it. The host's container lays it over the whole host; it's
|
|
## kept as the host's last child and hidden while zoomed in.
|
|
|
|
var main: Main
|
|
## Gets every left-button event (the host's own drag handling).
|
|
var on_left: Callable
|
|
## Gets right-button presses; returns true when it opened a menu.
|
|
var on_right: Callable
|
|
## Rolls the host (Play click); empty for hosts that don't roll.
|
|
var on_roll: Callable
|
|
var _press := Vector2(-1, -1)
|
|
|
|
|
|
func _init(p_main: Main, left: Callable, right: Callable, roll: Callable = Callable()) -> void:
|
|
main = p_main
|
|
on_left = left
|
|
on_right = right
|
|
on_roll = roll
|
|
mouse_filter = MOUSE_FILTER_STOP
|
|
visible = main.board != null and main.board.compact
|
|
|
|
|
|
func set_name_tip(text: String) -> void:
|
|
tooltip_text = text + ("\nClick to roll" if on_roll.is_valid() and main.mode == Main.Mode.PLAY else "")
|
|
|
|
|
|
func _gui_input(ev: InputEvent) -> void:
|
|
var mb := ev as InputEventMouseButton
|
|
if mb and mb.button_index == MOUSE_BUTTON_RIGHT:
|
|
on_right.call(mb)
|
|
accept_event()
|
|
return
|
|
if mb and mb.button_index == MOUSE_BUTTON_LEFT:
|
|
if mb.pressed:
|
|
_press = mb.global_position
|
|
elif _press.x >= 0.0 and mb.global_position.distance_to(_press) < 4.0 and main.mode == Main.Mode.PLAY and on_roll.is_valid():
|
|
on_left.call(ev, self)
|
|
_press = Vector2(-1, -1)
|
|
on_roll.call()
|
|
accept_event()
|
|
return
|
|
if mb or ev is InputEventMouseMotion:
|
|
on_left.call(ev, self)
|
|
accept_event()
|