feat: P22 merge chapter select and gallery into StoryGallery, i18n updates
This commit is contained in:
407
src/components/StoryGallery.vue
Normal file
407
src/components/StoryGallery.vue
Normal file
@@ -0,0 +1,407 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import type { ChapterInfo, SceneNode, EndingDef } from '@engine/types'
|
||||
|
||||
const props = defineProps<{
|
||||
chapters: ChapterInfo[]
|
||||
endings: EndingDef[]
|
||||
scenes: Record<string, SceneNode>
|
||||
visitedIds: Set<string>
|
||||
unlockedChapterIds: Set<string>
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
startChapter: [chapterId: string]
|
||||
close: []
|
||||
}>()
|
||||
|
||||
const expandedChapterId = ref<string | null>(null)
|
||||
|
||||
function collectReachable(startId: string): Set<string> {
|
||||
const visited = new Set<string>()
|
||||
const queue = [startId]
|
||||
while (queue.length > 0) {
|
||||
const id = queue.shift()!
|
||||
if (visited.has(id)) continue
|
||||
const scene = props.scenes[id]
|
||||
if (!scene) continue
|
||||
visited.add(id)
|
||||
if (scene.choices) {
|
||||
for (const c of scene.choices) {
|
||||
if (c.targetScene && !visited.has(c.targetScene)) queue.push(c.targetScene)
|
||||
}
|
||||
}
|
||||
if (scene.nextScene && !visited.has(scene.nextScene)) queue.push(scene.nextScene)
|
||||
if (scene.qte) {
|
||||
if (scene.qte.successScene && !visited.has(scene.qte.successScene)) queue.push(scene.qte.successScene)
|
||||
if (scene.qte.failScene && !visited.has(scene.qte.failScene)) queue.push(scene.qte.failScene)
|
||||
}
|
||||
if (scene.hotspots) {
|
||||
for (const h of scene.hotspots) {
|
||||
if (h.targetScene && !visited.has(h.targetScene)) queue.push(h.targetScene)
|
||||
}
|
||||
}
|
||||
}
|
||||
return visited
|
||||
}
|
||||
|
||||
// For each chapter, precompute reachable set
|
||||
const chapterReachable = computed(() => {
|
||||
const result: Record<string, Set<string>> = {}
|
||||
for (const ch of props.chapters) {
|
||||
result[ch.id] = collectReachable(ch.startScene)
|
||||
}
|
||||
return result
|
||||
})
|
||||
|
||||
// Which endings belong to each chapter (BFS-based, no chapterId needed)
|
||||
const chapterEndings = computed(() => {
|
||||
const result: Record<string, EndingDef[]> = {}
|
||||
for (const ch of props.chapters) {
|
||||
result[ch.id] = props.endings.filter((e) => chapterReachable.value[ch.id]?.has(e.sceneId))
|
||||
}
|
||||
return result
|
||||
})
|
||||
|
||||
function endingStatus(endingId: string) {
|
||||
return props.visitedIds.has(props.endings.find(e => e.id === endingId)?.sceneId ?? '')
|
||||
}
|
||||
|
||||
function chapterProgress(chapterId: string) {
|
||||
const reachable = chapterReachable.value[chapterId]
|
||||
if (!reachable || reachable.size === 0) return { count: 0, total: 0, pct: 0 }
|
||||
let count = 0
|
||||
for (const id of reachable) {
|
||||
if (props.visitedIds.has(id)) count++
|
||||
}
|
||||
return { count, total: reachable.size, pct: Math.round((count / reachable.size) * 100) }
|
||||
}
|
||||
|
||||
function sceneListForChapter(chapterId: string) {
|
||||
const reachable = chapterReachable.value[chapterId]
|
||||
if (!reachable) return []
|
||||
return [...reachable].map((id) => {
|
||||
const scene = props.scenes[id]
|
||||
const isVisited = props.visitedIds.has(id)
|
||||
let hint = ''
|
||||
if (!isVisited) {
|
||||
for (const [, src] of Object.entries(props.scenes)) {
|
||||
if (src.choices) {
|
||||
for (const c of src.choices) {
|
||||
if (c.targetScene === id && c.conditions && c.conditions.length > 0) {
|
||||
hint = `${c.conditions[0].variable} ${c.conditions[0].op} ${c.conditions[0].value}`
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if (src.hotspots) {
|
||||
for (const h of src.hotspots) {
|
||||
if (h.targetScene === id && h.conditions && h.conditions.length > 0) {
|
||||
hint = `${h.conditions[0].variable} ${h.conditions[0].op} ${h.conditions[0].value}`
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hint) break
|
||||
}
|
||||
}
|
||||
return { id, label: scene?.id ?? id, isVisited, hint }
|
||||
})
|
||||
}
|
||||
|
||||
function toggleExpand(chapterId: string) {
|
||||
expandedChapterId.value = expandedChapterId.value === chapterId ? null : chapterId
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="story-overlay" @click.self="emit('close')" @keydown.escape="emit('close')">
|
||||
<div class="story-panel">
|
||||
<h2 class="story-title">故事进度</h2>
|
||||
|
||||
<div class="story-grid">
|
||||
<div
|
||||
v-for="ch in chapters"
|
||||
:key="ch.id"
|
||||
class="story-card"
|
||||
:class="{ locked: !unlockedChapterIds.has(ch.id), expanded: expandedChapterId === ch.id }"
|
||||
>
|
||||
<div class="card-main" @click="unlockedChapterIds.has(ch.id) && toggleExpand(ch.id)">
|
||||
<div class="card-thumb">
|
||||
<img v-if="ch.thumbnail" :src="ch.thumbnail" class="thumb-img" />
|
||||
<div v-else class="thumb-placeholder">?</div>
|
||||
</div>
|
||||
<div class="card-label">{{ ch.label }}</div>
|
||||
|
||||
<div class="card-progress" v-if="unlockedChapterIds.has(ch.id)">
|
||||
<div class="mini-progress-bar">
|
||||
<div class="mini-progress-fill" :style="{ width: chapterProgress(ch.id).pct + '%' }"></div>
|
||||
</div>
|
||||
<div class="mini-progress-text">{{ chapterProgress(ch.id).pct }}%</div>
|
||||
</div>
|
||||
|
||||
<div class="card-endings" v-if="chapterEndings[ch.id]?.length">
|
||||
<span
|
||||
v-for="end in chapterEndings[ch.id]"
|
||||
:key="end.id"
|
||||
class="ending-tag"
|
||||
:class="{ unlocked: endingStatus(end.id) }"
|
||||
>{{ endingStatus(end.id) ? '✅' : '🔒' }} {{ end.label }}</span>
|
||||
</div>
|
||||
|
||||
<button
|
||||
v-if="unlockedChapterIds.has(ch.id)"
|
||||
class="card-start-btn"
|
||||
@click.stop="emit('startChapter', ch.id)"
|
||||
>▶ 开始</button>
|
||||
</div>
|
||||
|
||||
<div class="card-recap" v-if="expandedChapterId === ch.id">
|
||||
<div class="recap-scene-list">
|
||||
<div
|
||||
v-for="item in sceneListForChapter(ch.id)"
|
||||
:key="item.id"
|
||||
class="recap-item"
|
||||
:class="{ visited: item.isVisited }"
|
||||
>
|
||||
<span class="recap-icon">{{ item.isVisited ? '✅' : '⬜' }}</span>
|
||||
<span class="recap-label">{{ item.label }}</span>
|
||||
<span v-if="!item.isVisited && item.hint" class="recap-hint">🔒 {{ item.hint }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button class="story-close" @click="emit('close')">关闭</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.story-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.88);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 200;
|
||||
}
|
||||
|
||||
.story-panel {
|
||||
background: #1a1a2e;
|
||||
border: 1px solid rgba(255, 255, 255, 0.12);
|
||||
border-radius: 10px;
|
||||
padding: 36px 40px;
|
||||
max-width: 800px;
|
||||
max-height: 85vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.story-title {
|
||||
text-align: center;
|
||||
font-size: 22px;
|
||||
font-weight: 400;
|
||||
color: #ddd;
|
||||
letter-spacing: 3px;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.story-grid {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
justify-content: center;
|
||||
overflow-y: auto;
|
||||
padding-right: 8px;
|
||||
}
|
||||
|
||||
.story-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: rgba(255, 255, 255, 0.04);
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
border-radius: 8px;
|
||||
width: 200px;
|
||||
overflow: hidden;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.story-card.locked {
|
||||
opacity: 0.4;
|
||||
}
|
||||
|
||||
.story-card.expanded {
|
||||
border-color: rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
|
||||
.card-main {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 16px 14px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.story-card.locked .card-main {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.card-thumb {
|
||||
width: 140px;
|
||||
height: 78px;
|
||||
background: rgba(0, 0, 0, 0.4);
|
||||
border-radius: 6px;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.thumb-img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.thumb-placeholder {
|
||||
font-size: 28px;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.card-label {
|
||||
font-size: 14px;
|
||||
color: #ddd;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.card-progress {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.mini-progress-bar {
|
||||
flex: 1;
|
||||
height: 4px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 2px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.mini-progress-fill {
|
||||
height: 100%;
|
||||
background: #4caf50;
|
||||
border-radius: 2px;
|
||||
transition: width 0.3s ease;
|
||||
}
|
||||
|
||||
.mini-progress-text {
|
||||
font-size: 11px;
|
||||
color: #888;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.card-endings {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.ending-tag {
|
||||
font-size: 11px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.ending-tag.unlocked {
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.card-start-btn {
|
||||
padding: 6px 20px;
|
||||
margin-top: 4px;
|
||||
font-size: 12px;
|
||||
color: #8cf;
|
||||
background: rgba(100, 200, 255, 0.08);
|
||||
border: 1px solid rgba(100, 200, 255, 0.2);
|
||||
border-radius: 3px;
|
||||
cursor: pointer;
|
||||
transition: background 0.15s;
|
||||
}
|
||||
|
||||
.card-start-btn:hover {
|
||||
background: rgba(100, 200, 255, 0.15);
|
||||
}
|
||||
|
||||
.card-recap {
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.06);
|
||||
padding: 12px 14px;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.recap-scene-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.recap-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 4px 6px;
|
||||
background: rgba(255, 255, 255, 0.02);
|
||||
border-radius: 3px;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.recap-item.visited {
|
||||
background: rgba(76, 175, 80, 0.06);
|
||||
}
|
||||
|
||||
.recap-icon {
|
||||
font-size: 11px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.recap-label {
|
||||
color: #aaa;
|
||||
flex: 1;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.recap-item.visited .recap-label {
|
||||
color: #ddd;
|
||||
}
|
||||
|
||||
.recap-hint {
|
||||
font-size: 10px;
|
||||
color: #ff9800;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.story-close {
|
||||
margin-top: 20px;
|
||||
padding: 10px 36px;
|
||||
font-size: 14px;
|
||||
color: #888;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border: 1px solid rgba(255, 255, 255, 0.12);
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
transition: background 0.15s, color 0.15s;
|
||||
align-self: center;
|
||||
}
|
||||
|
||||
.story-close:hover {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
color: #ccc;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user