import { useState, useEffect, useMemo, useCallback } from "react"; import { createPortal } from "react-dom"; import { AnimatePresence, motion } from "framer-motion"; import { cn, getStaticImage } from "@/lib/utils"; import { Image } from "@/components"; import { useScale } from "@/contexts/ScaleContext"; export interface ChoiceDialog1Props { /** 是否可见 */ visible?: boolean; /** 关闭回调 */ onClose?: () => void; /** 选择回调 */ onSelect?: (choice: "读书" | "没出息" | "女子不能上学") => void; } /** * 第一个选择弹窗:人物和三个选择 * - 使用蒙版遮罩作为背景 * - 显示人物10_004和三个选择选项 */ const ChoiceDialog1 = ({ visible = true, onClose, onSelect, }: ChoiceDialog1Props) => { const maskSrc = getStaticImage("components/蒙版遮罩"); const backSrc = getStaticImage("components/关闭"); const characterSrc = getStaticImage("huangyanpei/reflection/scene2/10_004"); const choice1Src = getStaticImage("huangyanpei/reflection/scene2/10_005"); const choice2Src = getStaticImage("huangyanpei/reflection/scene2/10_006"); const choice3Src = getStaticImage("huangyanpei/reflection/scene2/10_007"); const { scale, offsetX, offsetY, DESIGN_WIDTH, DESIGN_HEIGHT } = useScale(); const [mounted, setMounted] = useState(false); // SSR 兼容 useEffect(() => { setMounted(true); }, []); const handleClose = useCallback( (e: React.MouseEvent) => { e.stopPropagation(); onClose?.(); }, [onClose] ); const handleChoiceClick = useCallback( (choice: "读书" | "没出息" | "女子不能上学") => { onSelect?.(choice); onClose?.(); }, [onSelect, onClose] ); // 样式 const overlayStyle = useMemo( () => ({ position: "fixed", inset: 0, zIndex: 9999, pointerEvents: "none", }), [] ); const scaledContainerStyle = useMemo( () => ({ position: "absolute", width: `${DESIGN_WIDTH}px`, height: `${DESIGN_HEIGHT}px`, left: `${offsetX}px`, top: `${offsetY}px`, transform: `scale(${scale})`, transformOrigin: "top left", overflow: "hidden", }), [scale, offsetX, offsetY, DESIGN_WIDTH, DESIGN_HEIGHT] ); if (!mounted) return null; const content = ( {visible && (
{/* 背景蒙版 */} {maskSrc && ( )} {/* 返回按钮 */} {onClose && ( 返回 )} {/* 内容区域 */}
{/* 人物 - 左侧 */}
人物
{/* 三个选择选项 - 右侧水平排列 */}
{/* 选择A:读书 */}
handleChoiceClick("读书")} > {/* 标签A */}
A
{/* 图标 */} 读书 {/* 文字说明 */}
读书只为
升官发财
{/* 选择B:没出息 */}
handleChoiceClick("没出息")} > {/* 标签B */}
B
{/* 图标 */} 没出息 {/* 文字说明 */}
手工劳作
没出息
{/* 选择C:女子不能上学 */}
handleChoiceClick("女子不能上学")} > {/* 标签C */}
C
{/* 图标 */} 女子不能上学 {/* 文字说明 */}
女子
不能上学
)}
); return createPortal(content, document.body); }; export default ChoiceDialog1;