diff --git a/src/components/frontend/personnel/NpcConversation.tsx b/src/components/frontend/personnel/NpcConversation.tsx index 1064f48a..81834d03 100644 --- a/src/components/frontend/personnel/NpcConversation.tsx +++ b/src/components/frontend/personnel/NpcConversation.tsx @@ -549,6 +549,16 @@ export function NpcConversation({ : []; const anySelectableChoice = visibleChoices.some((choice) => !choice.locked); + /** The node whose options belong on screen. Null while anything is still + * arriving, which is what opens and closes the footer: the row animates from + * 0fr to 1fr, so the menu slides in instead of the text jumping. */ + const footerNode = (() => { + if (typing !== null || playerTyping || streamingId !== null) return null; + if (!lastNode || lastNode.kind !== "node") return null; + const node = lastNode.node; + return node.type === "choice" || node.type === "end" ? node : null; + })(); + // Keep the newest line in view. `streamingId` and the choice count are in the // dependencies because the footer appearing (or a menu growing) changes how // much room the log has, and the log would otherwise leave the newest line @@ -558,6 +568,21 @@ export function NpcConversation({ if (el) el.scrollTop = el.scrollHeight; }, [log, typing, playerTyping, open, streamingId, visibleChoices.length]); + // The footer grows over several frames, so the log keeps shrinking after the + // effect above has run. Follow it while the player is at the bottom; if they + // scrolled up to re-read something, leave their position alone. + useEffect(() => { + const el = scrollRef.current; + if (!el || typeof ResizeObserver === "undefined") return; + const observer = new ResizeObserver(() => { + if (el.scrollHeight - el.clientHeight - el.scrollTop < 40) { + el.scrollTop = el.scrollHeight; + } + }); + observer.observe(el); + return () => observer.disconnect(); + }, []); + /** Button text for a choice: the server-resolved label when the choice * node's strings contained flag tokens, the raw label otherwise. */ @@ -676,6 +701,7 @@ export function NpcConversation({ if (streamingId) skipRevealRef.current = streamingId; else skipBeatRef.current = true; }} + data-log="conversation" className="min-h-0 flex-1 overflow-y-auto p-5" > {/* Bottom-anchored like a messenger: a short conversation sits @@ -715,14 +741,21 @@ export function NpcConversation({ - {!typing && - !playerTyping && - streamingId === null && - lastNode && - lastNode.kind === "node" && - (lastNode.node.type === "choice" || lastNode.node.type === "end") && ( -
- {lastNode.node.type === "choice" && visibleChoices.length > 0 && ( + {/* The footer opens by growing its grid row, so the menu slides in + and the log above it gives up height over the same 260ms + instead of the text jumping up in one frame. Always mounted so + the transition has something to animate; `motion-reduce` + collapses the timing to nothing. */} +
+
+ {footerNode && ( +
+ {footerNode.type === "choice" && visibleChoices.length > 0 && ( {visibleChoices.map(({ hop, index, locked }) => { const isNew = unseenTargets.has(hop.target); @@ -731,7 +764,8 @@ export function NpcConversation({ type="button" disabled={locked} onClick={() => pick(hop, index, choiceLabel(hop, index))} - className={`w-full rounded-none border px-3 py-2 text-left text-sm transition-colors ${ + style={{ animationDelay: `${Math.min(index, 6) * 40}ms` }} + className={`w-full rounded-none border px-3 py-2 text-left text-sm transition-colors animate-in fade-in-0 slide-in-from-bottom-1 fill-mode-both duration-200 motion-reduce:animate-none ${ locked ? "cursor-not-allowed border-white/10 bg-black/20 text-white/35" : "border-white/20 bg-black/40 text-white/80 hover:border-cyan-500/60 hover:text-white" @@ -767,7 +801,7 @@ export function NpcConversation({ })} )} - {(lastNode.node.type === "end" || !anySelectableChoice) && ( + {(footerNode.type === "end" || !anySelectableChoice) && (
- )} + )} +
+
)} diff --git a/src/lib/npc-dialogue/AGENTS.md b/src/lib/npc-dialogue/AGENTS.md index 27d92f54..2cc6189a 100644 --- a/src/lib/npc-dialogue/AGENTS.md +++ b/src/lib/npc-dialogue/AGENTS.md @@ -243,7 +243,24 @@ it, `justify-end` puts overflow above the scroll origin where it cannot be reach The auto-scroll effect depends on `streamingId` and `visibleChoices.length` as well as the log: the footer appearing (or a menu gaining items) changes how much room the -log has, and without those the newest line can end up scrolled out of sight. +log has, and without those the newest line can end up scrolled out of sight. A +`ResizeObserver` on the log keeps pinning it to the bottom while the footer animates, +but only when the player is already near the bottom, so nobody reading further up +gets yanked. + +**The footer slides in.** It is wrapped in a grid whose +`grid-template-rows` goes `0fr` to `1fr` over 300ms, with the item `min-h-0` and the +wrapper `overflow-hidden`; the content mounts at the same moment the row starts +growing, so the log gives up height progressively and the lines above glide instead +of being knocked upward in one frame (measured: 19 frames from 0 to 163 px, log 529 +to 366 in step). The buttons stagger in behind it with `animate-in` and a 40ms +per-item delay. `motion-reduce` sets `transition-property: none`, so the menu lands +at once for a reduced-motion device. + +The **exit is deliberately instant**: a pick swaps the footer for the player's typing +indicator, and the menu vanishing the moment it is used is the expected feedback. +Animating it out would mean latching the last choice node so its buttons could stay +mounted while collapsing; that is not worth the extra state unless someone asks. ## AI drafting behaviour worth knowing