Files
echo-nexus/src/components/game/AchievementNotifier.tsx
T
Super_Z 44b94f9325 v0.9 工单修复: 4 bug + 4 玩法改进
Gitea Issue #2 修复:
Bug:
1. 探险只能一次 → 能量恢复 45→20s, 初始能量 3→5, 上限 5→8
   新增 lastExpeditionSummary 显示上次结果
   新增 dismissExpedition action
2. 元素偏移/遮挡 → 标签页 grid-cols-8 → 响应式 grid-cols-4/sm:8
3. 成就UI遮挡 → max-h 440→520, min-h 提高
4. 提示框遮挡 → toast top-0→top-14 避开 header, TOAST_LIMIT 1→3

玩法改进:
1. 中央晶体球 → 下方新增 4 指标收益面板(产能/脉冲/连击/仓库)
2. 技术树 12→20 节点 (每分支 3→5 级)
3. 成就解锁 → 全屏居中特效通知 (framer-motion 弹窗)
4. 叙事融入 → 新建 narrative.ts, 脉冲/技术树注入世界观文本
2026-06-24 00:41:16 +00:00

169 lines
6.8 KiB
TypeScript
Executable File

"use client";
// 回响星核 / Echo Nexus — 成就解锁通知(v0.9 全屏特效增强)
// 工单 Issue #2 反馈"成就系统没看出来有什么用",改为居中全息弹窗 + 奖励数字弹出
import { useEffect, useState } from "react";
import { AnimatePresence, motion } from "framer-motion";
import { useGameStore } from "@/store/gameStore";
import { useToast } from "@/hooks/use-toast";
import { sfx } from "@/hooks/useAudio";
import type { Achievement } from "@/lib/game/achievements";
interface NotificationItem {
achievement: Achievement;
id: number;
}
export function AchievementNotifier() {
const queue = useGameStore((s) => s._achievementQueue);
const consume = useGameStore((s) => s.consumeAchievementQueue);
const { toast } = useToast();
const [notifications, setNotifications] = useState<NotificationItem[]>([]);
useEffect(() => {
if (queue.length === 0) return;
const items = consume();
for (const a of items) {
sfx("achievement");
// v0.9:全屏居中特效通知
const id = Date.now() + Math.random();
// eslint-disable-next-line react-hooks/set-state-in-effect
setNotifications((prev) => [...prev, { achievement: a, id }]);
// 4 秒后自动移除
setTimeout(() => {
setNotifications((prev) => prev.filter((n) => n.id !== id));
}, 4000);
// 同时保留底部 toast 作为日志
toast({
title: `成就解锁:${a.name}`,
description: `${a.desc} 奖励:${a.rewardText}`,
});
}
}, [queue, consume, toast]);
if (notifications.length === 0) return null;
return (
<div className="fixed inset-0 z-[120] pointer-events-none flex items-center justify-center">
<AnimatePresence>
{notifications.map((n, idx) => {
const a = n.achievement;
// 多个同时出现时垂直堆叠偏移
const offset = (idx - (notifications.length - 1) / 2) * 140;
return (
<motion.div
key={n.id}
initial={{ opacity: 0, scale: 0.4, y: 40, rotateX: -30 }}
animate={{ opacity: 1, scale: 1, y: offset, rotateX: 0 }}
exit={{ opacity: 0, scale: 0.6, y: -60 }}
transition={{ type: "spring", stiffness: 280, damping: 22 }}
className="absolute"
style={{ transformOrigin: "center center" }}
>
<div
className="relative rounded-2xl border-2 px-8 py-5 backdrop-blur-xl overflow-hidden"
style={{
borderColor: a.color,
background: `linear-gradient(135deg, ${a.color}22, rgba(5,4,16,0.92))`,
boxShadow: `0 0 60px ${a.color}66, 0 0 120px ${a.color}33, inset 0 0 30px ${a.color}11`,
minWidth: 320,
maxWidth: 420,
}}
>
{/* 背景径向辉光 */}
<div
className="absolute -top-20 -right-20 h-40 w-40 rounded-full blur-3xl opacity-50"
style={{ background: a.color }}
/>
{/* 旋转光线 */}
<motion.div
className="absolute inset-0 rounded-2xl opacity-20"
style={{
background: `conic-gradient(from 0deg, transparent, ${a.color}, transparent, ${a.color}, transparent)`,
}}
animate={{ rotate: 360 }}
transition={{ duration: 8, repeat: Infinity, ease: "linear" }}
/>
<div className="relative flex items-center gap-4">
{/* 图标徽章 */}
<motion.div
className="shrink-0 h-16 w-16 rounded-2xl flex items-center justify-center text-3xl"
style={{
background: `${a.color}33`,
border: `2px solid ${a.color}`,
boxShadow: `0 0 20px ${a.color}88, inset 0 0 12px ${a.color}44`,
}}
animate={{
boxShadow: [
`0 0 20px ${a.color}88, inset 0 0 12px ${a.color}44`,
`0 0 40px ${a.color}cc, inset 0 0 20px ${a.color}66`,
`0 0 20px ${a.color}88, inset 0 0 12px ${a.color}44`,
],
}}
transition={{ duration: 2, repeat: Infinity }}
>
{a.icon}
</motion.div>
{/* 文本 */}
<div className="min-w-0 flex-1">
<motion.div
initial={{ opacity: 0, x: -10 }}
animate={{ opacity: 1, x: 0 }}
transition={{ delay: 0.15 }}
className="text-[10px] font-mono uppercase tracking-[0.2em] mb-0.5"
style={{ color: a.color }}
>
Achievement Unlocked
</motion.div>
<motion.h3
initial={{ opacity: 0, x: -10 }}
animate={{ opacity: 1, x: 0 }}
transition={{ delay: 0.2 }}
className="text-lg font-bold truncate"
style={{ color: a.color, textShadow: `0 0 12px ${a.color}66` }}
>
{a.name}
</motion.h3>
<motion.p
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ delay: 0.3 }}
className="text-[11px] text-muted-foreground/90 truncate"
>
{a.desc}
</motion.p>
{/* 奖励条 */}
<motion.div
initial={{ opacity: 0, y: 8 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.4 }}
className="mt-1.5 inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[10px] font-mono font-semibold"
style={{
background: `${a.color}22`,
border: `1px solid ${a.color}55`,
color: a.color,
}}
>
{a.rewardText}
</motion.div>
</div>
</div>
{/* 进度条(倒计时) */}
<motion.div
className="absolute bottom-0 left-0 h-0.5"
style={{ background: a.color }}
initial={{ width: "100%" }}
animate={{ width: "0%" }}
transition={{ duration: 4, ease: "linear" }}
/>
</div>
</motion.div>
);
})}
</AnimatePresence>
</div>
);
}