import { useState, useEffect } from "react"; import { motion } from "framer-motion"; import { Image } from "@/components"; import { getStaticImage } from "@/lib/utils"; import { DialogueClueData } from "./types"; export interface DialogueContentProps { /** 对话线索数据 */ clue: DialogueClueData; } /** * 对话内容组件 * 依次显示多条对话,所有对话同时展示,带有动画效果 */ const DialogueContent = ({ clue }: DialogueContentProps) => { const [visibleIndices, setVisibleIndices] = useState([]); // 依次显示对话:先显示第一条,延迟后显示第二条 useEffect(() => { if (clue.dialogues.length === 0) return; // 立即显示第一条对话 setVisibleIndices([0]); // 延迟显示后续对话 if (clue.dialogues.length > 1) { const timer = setTimeout(() => { setVisibleIndices((prev) => [...prev, 1]); }, 1500); // 第一条显示1.5秒后显示第二条 return () => clearTimeout(timer); } }, [clue.dialogues.length]); return (
{clue.dialogues.map((dialogue, index) => { const isVisible = visibleIndices.includes(index); return ( {/* 角色头像 */} {dialogue.avatar && ( {dialogue.character} {dialogue.character} )} {/* 对话气泡 */}
{dialogue.text}
{/* 对话气泡箭头 - 指向左侧头像 */}
); })}
); }; export default DialogueContent;