import { useState, useEffect } from "react"; import { Image } from "@/components"; import { getBackgroundImage, getStaticImage } from "@/lib/utils"; import { cn } from "@/lib/utils"; import type { Clue } from "@/store/clueStore"; export interface ClueBookModalProps { visible: boolean; clues: Clue[]; onClose: () => void; getClueImage: (clueId: string) => string; getClueDetailImage: (clueId: string) => string; getClueHintImage?: (clueId: string) => string | null; } /** * 线索簿组件 - 显示已收集的线索和详情 */ export const ClueBookModal = ({ visible, clues, onClose, getClueImage, getClueDetailImage, getClueHintImage, }: ClueBookModalProps) => { const [selectedClueId, setSelectedClueId] = useState(null); const [showClueHint, setShowClueHint] = useState(false); // 默认选中第一个已收集的线索 useEffect(() => { if (visible && clues.length > 0 && !selectedClueId) { const firstCollected = clues.find((c) => c.collected); if (firstCollected) { setSelectedClueId(firstCollected.id); } } }, [visible, clues, selectedClueId]); // 当切换线索时,关闭线索提示 useEffect(() => { setShowClueHint(false); }, [selectedClueId]); // 检查当前线索是否有提示 const hasClueHint = (clueId: string): boolean => { if (!getClueHintImage) return false; const hintImage = getClueHintImage(clueId); return hintImage !== null && hintImage !== undefined; }; if (!visible) return null; const selectedClue = clues.find((c) => c.id === selectedClueId); return (
{/* 蒙版背景 */} {/*
*/} {/* 线索簿内容 */}
{/* 背景图片 - 线索簿 */}
{/* 内容区域 */}
{/* 左侧:线索列表 */}
{clues.length === 0 ? (
暂无线索
) : ( clues.map((clue) => { const isSelected = clue.id === selectedClueId; const isCollected = clue.collected; return (
{ if (isCollected) { setSelectedClueId(clue.id); } }} > {/* 线索缩略图 - 带倾斜效果 */}
); }) )}
{/* 右侧:线索详情或对话 */}
{selectedClue && selectedClue.collected ? (
{/* 显示线索详情图片 */}
{/* 线索提示描述(覆盖在详情图片上) */} {showClueHint && hasClueHint(selectedClue.id) && getClueHintImage && (
{/* 关闭按钮 */} setShowClueHint(false)} />
)} {/* 线索提示按钮(右下角) */} {hasClueHint(selectedClue.id) && (
setShowClueHint(true)} />
)}
) : (
{selectedClue ? "该线索尚未收集" : "请选择一个线索查看详情"}
)}
{/* 关闭按钮 */}
); };