feat(input): guard Guest Book taps and add double-tap placement

Guest Book: only open a card on a short stationary tap, ignore drags and flings, and guard the detail Close button after opening. Board: add a persisted double-tap placement mode with deferred single taps, while hold stays the default and right-click works in both modes.
This commit is contained in:
Ratdoku Builder committed 2026-12-02 20:10:44 -06:00
1 parent bed81a2e05
commit af4951baf8
8 files changed
+344 -11

No files matched your search

+92 -3
View File
@@ -2,9 +2,17 @@ extends Control
signal back_pressed
## A tap is only trusted when it is short and stationary. Anything that
## drifts or moves the scroll container is treated as a scroll gesture.
const TAP_MAX_MOVE := 12.0
const TAP_MAX_MS := 500
const DRAG_SUPPRESS_MS := 180
const DETAIL_CLOSE_GUARD_MS := 250
var grid: GridContainer
var progress_label: Label
var status_label: Label
var scroll: ScrollContainer
var detail_layer: ColorRect
var detail_portrait: TextureRect
var detail_name: Label
@@ -14,6 +22,14 @@ var detail_bio: Label
var detail_snack: Label
var detail_status: Label
var _press_active := false
var _press_at := 0
var _press_pos := Vector2.ZERO
var _press_scroll := 0
var _dragged := false
var _suppress_until := 0
var _detail_opened_at := 0
func _ready() -> void:
var margin := MarginContainer.new()
@@ -53,10 +69,12 @@ func _ready() -> void:
status_label.custom_minimum_size = Vector2(0, 20)
column.add_child(status_label)
var scroll := ScrollContainer.new()
scroll = ScrollContainer.new()
scroll.size_flags_horizontal = Control.SIZE_EXPAND_FILL
scroll.size_flags_vertical = Control.SIZE_EXPAND_FILL
scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
scroll.scroll_started.connect(_on_scroll_started)
scroll.scroll_ended.connect(_on_scroll_ended)
column.add_child(scroll)
grid = GridContainer.new()
@@ -173,9 +191,62 @@ func _make_card(guest: Dictionary) -> PanelContainer:
return panel
func _on_scroll_started() -> void:
_dragged = true
func _on_scroll_ended() -> void:
_dragged = true
_suppress_until = max(_suppress_until, Time.get_ticks_msec() + DRAG_SUPPRESS_MS)
func _on_card_input(event: InputEvent, guest: Dictionary, locked: bool) -> void:
if not (event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT):
if event is InputEventMouseMotion and _press_active:
var motion := event as InputEventMouseMotion
if motion.global_position.distance_to(_press_pos) > TAP_MAX_MOVE:
_dragged = true
return
if not (event is InputEventMouseButton):
return
var button := event as InputEventMouseButton
if button.button_index != MOUSE_BUTTON_LEFT:
return
if button.pressed:
# Remember where and when the finger landed, and how far the list
# was scrolled, so a release can be checked against it.
_press_active = true
_press_at = Time.get_ticks_msec()
_press_pos = button.global_position
_press_scroll = scroll.scroll_vertical if scroll != null else 0
_dragged = false
return
if not _press_active:
return
_press_active = false
var now := Time.get_ticks_msec()
var moved: float = button.global_position.distance_to(_press_pos)
var scroll_now := scroll.scroll_vertical if scroll != null else 0
var scrolled := _dragged or absi(scroll_now - _press_scroll) > 1
var is_tap: bool = (
not scrolled
and moved <= TAP_MAX_MOVE
and now - _press_at <= TAP_MAX_MS
and now >= _suppress_until
)
if scrolled:
_suppress_until = now + DRAG_SUPPRESS_MS
# Consume the release either way: a scroll must not fall through to a
# card, and a tap must not reach the detail sheet that is about to open.
accept_event()
if not is_tap:
return
if locked:
var room := int(guest.get("unlock_room", 0))
status_label.text = "Check in a guest from Room %d to meet them." % room
@@ -192,14 +263,17 @@ func _build_detail() -> void:
detail_layer.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
detail_layer.mouse_filter = Control.MOUSE_FILTER_STOP
detail_layer.visible = false
detail_layer.gui_input.connect(_on_detail_input)
add_child(detail_layer)
var center := CenterContainer.new()
center.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
center.mouse_filter = Control.MOUSE_FILTER_IGNORE
detail_layer.add_child(center)
var panel := UI.panel(Palette.CREAM, 24, 16)
panel.custom_minimum_size = Vector2(320, 0)
panel.mouse_filter = Control.MOUSE_FILTER_STOP
center.add_child(panel)
var box := VBoxContainer.new()
@@ -230,7 +304,7 @@ func _build_detail() -> void:
var close := UI.button("Close", false, 44)
close.add_theme_font_size_override("font_size", 16)
close.pressed.connect(func() -> void: detail_layer.visible = false)
close.pressed.connect(_try_close_detail)
box.add_child(close)
@@ -247,4 +321,19 @@ func _show_detail(guest: Dictionary) -> void:
detail_status.text = "Checked in · Room %d" % int(guest.get("unlock_room", 0))
if int(guest.get("unlock_room", 0)) == 0:
detail_status.text = "Resident · always in"
_detail_opened_at = Time.get_ticks_msec()
detail_layer.visible = true
detail_layer.move_to_front()
func _on_detail_input(event: InputEvent) -> void:
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and not event.pressed:
_try_close_detail()
func _try_close_detail() -> void:
# The opening tap can land where the sheet appears. Ignore close input
# for a moment so one deliberate tap opens and a second one closes.
if Time.get_ticks_msec() - _detail_opened_at < DETAIL_CLOSE_GUARD_MS:
return
detail_layer.visible = false