feat: P22 merge chapter select and gallery into StoryGallery, i18n updates

This commit is contained in:
2026-06-10 16:01:26 +08:00
parent 0dec8a2376
commit d2dae38f05
8 changed files with 461 additions and 440 deletions

View File

@@ -1,209 +0,0 @@
<script setup lang="ts">
import { ref, watch, nextTick } from 'vue'
import type { ChapterInfo } from '@engine/types'
import { useI18n } from '@/composables/useI18n'
const props = defineProps<{
chapters: ChapterInfo[]
unlockedIds: Set<string>
}>()
const emit = defineEmits<{
select: [chapterId: string]
back: []
}>()
const { t } = useI18n()
const focusIdx = ref(0)
const cardRefs = ref<(HTMLDivElement | null)[]>([])
function setRef(el: HTMLDivElement | null, i: number) {
cardRefs.value[i] = el
}
// when shown, focus first unlocked
watch(() => props.chapters.length, async (len) => {
if (len > 0) {
const first = props.chapters.findIndex(ch => props.unlockedIds.has(ch.id))
focusIdx.value = first >= 0 ? first : 0
await nextTick()
cardRefs.value[focusIdx.value]?.focus()
}
})
function onKeydown(e: KeyboardEvent, index: number) {
if (e.key === 'ArrowRight' || e.key === 'ArrowLeft') {
e.preventDefault()
const dir = e.key === 'ArrowRight' ? 1 : -1
const len = props.chapters.length
let next = (index + dir + len) % len
// skip locked ones
let tries = 0
while (!props.unlockedIds.has(props.chapters[next].id) && tries < len) {
next = (next + dir + len) % len
tries++
}
focusIdx.value = next
cardRefs.value[next]?.focus()
}
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault()
if (props.unlockedIds.has(props.chapters[index].id)) {
emit('select', props.chapters[index].id)
}
}
if (e.key === 'Escape' || e.key === 'Backspace') {
e.preventDefault()
emit('back')
}
}
</script>
<template>
<div class="chapter-overlay" @keydown="(e: KeyboardEvent) => { if (e.key === 'Escape' || e.key === 'Backspace') { e.preventDefault(); emit('back'); } }">
<div class="chapter-panel">
<h2 class="chapter-title">{{ t('ui.chapters') }}</h2>
<div class="chapter-grid">
<div
v-for="(ch, i) in chapters"
:key="ch.id"
:ref="(el: any) => setRef(el, i)"
class="chapter-card"
:class="{ locked: !unlockedIds.has(ch.id) }"
:tabindex="unlockedIds.has(ch.id) ? 0 : -1"
@click="unlockedIds.has(ch.id) && emit('select', ch.id)"
@keydown="onKeydown($event, i)"
>
<div class="chapter-thumb">
<img v-if="ch.thumbnail" :src="ch.thumbnail" class="thumb-img" />
<div v-else class="thumb-placeholder">?</div>
</div>
<div class="chapter-label">{{ ch.label }}</div>
<div v-if="!unlockedIds.has(ch.id)" class="lock-icon">🔒</div>
</div>
</div>
<button class="back-btn" @click="emit('back')">{{ t('ui.back') }} (Esc)</button>
</div>
</div>
</template>
<style scoped>
.chapter-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.88);
display: flex;
align-items: center;
justify-content: center;
z-index: 200;
}
.chapter-panel {
background: #1a1a2e;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 10px;
padding: 36px 40px;
min-width: 520px;
max-width: 700px;
}
.chapter-title {
text-align: center;
font-size: 22px;
font-weight: 400;
color: #ddd;
letter-spacing: 3px;
margin-bottom: 28px;
}
.chapter-grid {
display: flex;
gap: 16px;
justify-content: center;
}
.chapter-card {
display: flex;
flex-direction: column;
align-items: center;
gap: 10px;
padding: 16px;
background: rgba(255, 255, 255, 0.04);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 8px;
cursor: pointer;
transition: background 0.2s, border-color 0.2s, transform 0.15s;
width: 150px;
outline: none;
}
.chapter-card:hover:not(.locked) {
background: rgba(255, 255, 255, 0.1);
border-color: rgba(255, 255, 255, 0.25);
transform: translateY(-2px);
}
.chapter-card:focus-visible {
background: rgba(255, 255, 255, 0.12);
border-color: rgba(255, 255, 255, 0.4);
box-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
transform: translateY(-2px);
}
.chapter-card.locked {
opacity: 0.4;
cursor: default;
}
.chapter-thumb {
width: 100px;
height: 56px;
background: rgba(0, 0, 0, 0.4);
border-radius: 4px;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
}
.thumb-img {
width: 100%;
height: 100%;
object-fit: cover;
}
.thumb-placeholder {
font-size: 24px;
color: #555;
}
.chapter-label {
font-size: 13px;
color: #ccc;
text-align: center;
}
.lock-icon {
font-size: 14px;
}
.back-btn {
display: block;
margin: 24px auto 0;
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;
}
.back-btn:hover {
background: rgba(255, 255, 255, 0.1);
color: #ccc;
}
</style>

View File

@@ -1,154 +0,0 @@
<script setup lang="ts">
import type { EndingDef } from '@engine/types'
defineProps<{
endings: EndingDef[]
visitedIds: Set<string>
}>()
const emit = defineEmits<{
close: []
selectChapter: [chapterId: string]
}>()
function isUnlocked(ending: EndingDef, visitedIds: Set<string>): boolean {
return visitedIds.has(ending.sceneId)
}
</script>
<template>
<div class="ending-overlay" @click.self="emit('close')" @keydown.escape="emit('close')">
<div class="ending-panel">
<h2 class="ending-title">结局画廊</h2>
<div class="ending-grid">
<div
v-for="end in endings"
:key="end.id"
class="ending-card"
:class="{ locked: !isUnlocked(end, visitedIds), clickable: isUnlocked(end, visitedIds) && !!end.chapterId }"
@click="isUnlocked(end, visitedIds) && end.chapterId && emit('selectChapter', end.chapterId)"
>
<div class="ending-thumb">
<img v-if="end.thumbnail" :src="end.thumbnail" class="thumb-img" />
<div v-else class="thumb-placeholder">?</div>
</div>
<div class="ending-label">{{ isUnlocked(end, visitedIds) ? end.label : '???' }}</div>
<div v-if="!isUnlocked(end, visitedIds)" class="lock-icon">🔒</div>
</div>
</div>
<button class="end-close" @click="emit('close')">关闭</button>
</div>
</div>
</template>
<style scoped>
.ending-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.88);
display: flex;
align-items: center;
justify-content: center;
z-index: 200;
}
.ending-panel {
background: #1a1a2e;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 10px;
padding: 36px 40px;
min-width: 400px;
max-width: 560px;
}
.ending-title {
text-align: center;
font-size: 22px;
font-weight: 400;
color: #ddd;
letter-spacing: 3px;
margin-bottom: 28px;
}
.ending-grid {
display: flex;
gap: 16px;
justify-content: center;
flex-wrap: wrap;
}
.ending-card {
display: flex;
flex-direction: column;
align-items: center;
gap: 10px;
width: 140px;
}
.ending-card.locked {
opacity: 0.4;
}
.ending-card.clickable {
cursor: pointer;
}
.ending-card.clickable:hover {
opacity: 0.85;
transform: scale(1.05);
transition: transform 0.15s ease;
}
.ending-thumb {
width: 120px;
height: 68px;
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;
}
.ending-label {
font-size: 13px;
color: #ccc;
text-align: center;
}
.lock-icon {
font-size: 14px;
margin-top: -6px;
}
.end-close {
display: block;
margin: 24px auto 0;
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;
}
.end-close:hover {
background: rgba(255, 255, 255, 0.1);
color: #ccc;
}
</style>

View File

@@ -3,18 +3,16 @@ import { useI18n } from '@/composables/useI18n'
defineProps<{
showResume: boolean
showChapters: boolean
showStory: boolean
showAchievements: boolean
showGallery: boolean
isGameEnd: boolean
}>()
const emit = defineEmits<{
start: []
resume: []
chapters: []
story: []
achievements: []
gallery: []
settings: []
}>()
@@ -31,12 +29,10 @@ const { t } = useI18n()
<button v-if="showResume" class="menu-btn secondary" @click="emit('resume')">{{ t('ui.resume') }}</button>
<div class="menu-sub-row">
<button v-if="showChapters" class="menu-sub" @click="emit('chapters')">{{ t('ui.chapters') }}</button>
<span v-if="showChapters" class="sub-sep">·</span>
<button v-if="showStory" class="menu-sub" @click="emit('story')">{{ t('ui.story') }}</button>
<span v-if="showStory" class="sub-sep">·</span>
<button v-if="showAchievements" class="menu-sub" @click="emit('achievements')">{{ t('ui.achievements') }}</button>
<span v-if="showAchievements" class="sub-sep">·</span>
<button v-if="showGallery" class="menu-sub" @click="emit('gallery')">{{ t('ui.gallery') }}</button>
<span v-if="showGallery" class="sub-sep">·</span>
<button class="menu-sub" @click="emit('settings')">{{ t('ui.settings') }}</button>
</div>
</div>

View 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>