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 var detail_role: Label var detail_meta: Label var detail_bio: Label var detail_snack: Label var detail_status: Label var crumb_frame_holder: CenterContainer var crumb_frame_id := "" 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() margin.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) margin.add_theme_constant_override("margin_left", 12) margin.add_theme_constant_override("margin_right", 12) margin.add_theme_constant_override("margin_top", UI.safe_top()) margin.add_theme_constant_override("margin_bottom", UI.safe_bottom()) add_child(margin) var column := VBoxContainer.new() column.add_theme_constant_override("separation", 6) margin.add_child(column) var top := HBoxContainer.new() top.add_theme_constant_override("separation", 6) column.add_child(top) var back := UI.round_button("res://assets/icons/arrow-left.svg", 40) back.pressed.connect(func() -> void: back_pressed.emit()) top.add_child(back) var title := UI.label("The Guest Book", 22) title.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT title.size_flags_horizontal = Control.SIZE_EXPAND_FILL top.add_child(title) progress_label = UI.label("5 of 25", 10, Palette.MUTED) progress_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT progress_label.autowrap_mode = TextServer.AUTOWRAP_OFF progress_label.custom_minimum_size = Vector2(70, 0) top.add_child(progress_label) column.add_child(_make_crumb_card()) status_label = UI.label("Tap a guest to read their card.", 10, Palette.MUTED) status_label.custom_minimum_size = Vector2(0, 20) column.add_child(status_label) 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() grid.columns = 3 grid.size_flags_horizontal = Control.SIZE_EXPAND_FILL grid.add_theme_constant_override("h_separation", 5) grid.add_theme_constant_override("v_separation", 5) scroll.add_child(grid) _build_detail() SaveGame.progress_changed.connect(refresh) refresh() func _build_crumb_frame() -> void: if crumb_frame_holder == null: return var selected := SaveGame.selected_frame() if crumb_frame_id == selected and crumb_frame_holder.get_child_count() > 0: return for child in crumb_frame_holder.get_children(): child.queue_free() var frame := Frames.frame_panel(selected, 56) var portrait := TextureRect.new() portrait.custom_minimum_size = Vector2(44, 44) portrait.expand_mode = TextureRect.EXPAND_IGNORE_SIZE portrait.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED portrait.texture = load("res://art/crumb_head.png") portrait.mouse_filter = Control.MOUSE_FILTER_IGNORE frame.add_child(portrait) crumb_frame_holder.add_child(frame) crumb_frame_id = selected func _make_crumb_card() -> PanelContainer: var panel := UI.panel(Palette.PAPER, 14, 8) var row := HBoxContainer.new() row.add_theme_constant_override("separation", 8) panel.add_child(row) crumb_frame_holder = CenterContainer.new() crumb_frame_holder.custom_minimum_size = Vector2(56, 56) row.add_child(crumb_frame_holder) _build_crumb_frame() var text := VBoxContainer.new() text.size_flags_horizontal = Control.SIZE_EXPAND_FILL text.alignment = BoxContainer.ALIGNMENT_CENTER text.add_theme_constant_override("separation", 0) row.add_child(text) var name := UI.label("Crumb", 16) name.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT text.add_child(name) var role := UI.label("Innkeeper · always in", 10, Palette.MUTED) role.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT text.add_child(role) return panel func refresh() -> void: if grid == null: return _build_crumb_frame() for child in grid.get_children(): child.queue_free() var guests := Guests.all() var unlocked := SaveGame.unlocked_count(guests) progress_label.text = "%d/%d" % [unlocked, guests.size()] for guest in guests: grid.add_child(_make_card(guest)) # Let a finger drag reach the ScrollContainer even when it starts on a # card; the card still gets its own press/release for tap detection. UI.pass_scroll_input(grid) func _make_card(guest: Dictionary) -> PanelContainer: var id := str(guest["id"]) var locked := not SaveGame.is_guest_unlocked(id) var accent := Color(str(guest.get("accent", "#8c7460"))) var panel := UI.panel(Palette.PAPER, 12, 5) panel.custom_minimum_size = Vector2(105, 148) panel.size_flags_horizontal = Control.SIZE_EXPAND_FILL panel.mouse_filter = Control.MOUSE_FILTER_STOP panel.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND panel.gui_input.connect(_on_card_input.bind(guest, locked)) var box := VBoxContainer.new() box.add_theme_constant_override("separation", 1) box.mouse_filter = Control.MOUSE_FILTER_IGNORE panel.add_child(box) var portrait := Control.new() portrait.custom_minimum_size = Vector2(94, 96) portrait.mouse_filter = Control.MOUSE_FILTER_IGNORE box.add_child(portrait) var texture := TextureRect.new() texture.expand_mode = TextureRect.EXPAND_IGNORE_SIZE texture.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED texture.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) texture.mouse_filter = Control.MOUSE_FILTER_IGNORE texture.texture = load(Guests.portrait(id, "thumbs")) portrait.add_child(texture) if locked: texture.modulate = Color(1, 1, 1, 0.18) var veil := ColorRect.new() veil.color = Color(0.98, 0.93, 0.84, 0.78) veil.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) veil.mouse_filter = Control.MOUSE_FILTER_IGNORE portrait.add_child(veil) var mystery := UI.label("???", 22, Palette.INK) mystery.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) mystery.vertical_alignment = VERTICAL_ALIGNMENT_CENTER mystery.mouse_filter = Control.MOUSE_FILTER_IGNORE portrait.add_child(mystery) var name_label := UI.label("???" if locked else str(guest["name"]), 12) name_label.mouse_filter = Control.MOUSE_FILTER_IGNORE box.add_child(name_label) var role_text := "Room %d" % int(guest.get("unlock_room", 0)) if locked else str(guest["role"]) var role_label := UI.label(role_text, 9, Palette.MUTED if locked else accent) role_label.mouse_filter = Control.MOUSE_FILTER_IGNORE box.add_child(role_label) 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 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 # Do not consume the event: the ScrollContainer needs the release to end # its drag. A real tap is still safe because the detail sheet guards # Close for 250ms after opening. 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 status_label.add_theme_color_override("font_color", Palette.RED) else: status_label.text = "Tap a guest to read their card." status_label.add_theme_color_override("font_color", Palette.MUTED) _show_detail(guest) func _build_detail() -> void: detail_layer = ColorRect.new() detail_layer.color = Color(0.18, 0.12, 0.08, 0.52) 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() box.add_theme_constant_override("separation", 4) panel.add_child(box) detail_portrait = TextureRect.new() detail_portrait.custom_minimum_size = Vector2(180, 180) detail_portrait.expand_mode = TextureRect.EXPAND_IGNORE_SIZE detail_portrait.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED box.add_child(detail_portrait) detail_name = UI.heading("Name", 22) box.add_child(detail_name) detail_role = UI.label("Role", 13, Palette.MUTED) box.add_child(detail_role) detail_meta = UI.label("Variety", 11, Palette.MUTED) box.add_child(detail_meta) detail_bio = UI.label("", 12) detail_bio.custom_minimum_size = Vector2(0, 38) box.add_child(detail_bio) detail_snack = UI.label("", 11, Palette.MUTED) box.add_child(detail_snack) detail_status = UI.label("", 10, Palette.MUTED) box.add_child(detail_status) var close := UI.button("Close", false, 44) close.add_theme_font_size_override("font_size", 16) close.pressed.connect(_try_close_detail) box.add_child(close) func _show_detail(guest: Dictionary) -> void: var id := str(guest["id"]) var accent := Color(str(guest.get("accent", "#8c7460"))) detail_portrait.texture = load(Guests.portrait(id, "cards")) detail_name.text = str(guest["name"]) detail_role.text = "%s · %s" % [str(guest["role"]), str(guest.get("pronouns", ""))] detail_role.add_theme_color_override("font_color", accent) detail_meta.text = "%s coat · %s" % [str(guest.get("variety", "")), str(guest.get("coat", ""))] detail_bio.text = str(guest.get("personality", "")) detail_snack.text = "Favourite snack: %s" % str(guest.get("snack", "")) 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