Skip to content

Commit b002ecd

Browse files
author
linyuan.yang
committed
调整布局
1 parent d5c54ae commit b002ecd

8 files changed

Lines changed: 454 additions & 85 deletions

File tree

‎packages/ui/src/components/NesScreen.vue‎

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
const props = defineProps<{
3131
inputLocked?: boolean
3232
gamePaused?: boolean
33+
layoutEditing?: boolean
3334
/** 应用级快捷键修饰键:桌面(Tauri)传 'ctrl',浏览器传 'shift'(默认)。 */
3435
modifier?: 'ctrl' | 'shift'
3536
romKey?: string | null
@@ -83,24 +84,26 @@ async function quickSave() {
8384
}
8485
8586
// 快速新建存档:不覆盖 quick,而是往存档列表追加一条(自动编号 label)。
86-
async function quickNewSave() {
87+
async function quickNewSave(): Promise<boolean> {
8788
if (!runner?.loaded || !props.romKey) {
8889
showToast('请先载入游戏')
89-
return
90-
}
91-
const state = await runner.saveState()
92-
if (!state) {
93-
showToast('存档失败')
94-
return
90+
return false
9591
}
9692
try {
93+
const state = await runner.saveState()
94+
if (!state) {
95+
showToast('存档失败')
96+
return false
97+
}
9798
const list = await listSaveStates(props.romKey)
9899
const count = list.filter((r) => r.slot !== QUICK_SLOT).length
99100
await createSaveState(props.romKey, props.romName ?? props.romKey, `存档 ${count + 1}`, state)
100101
showToast('已新建存档')
102+
return true
101103
} catch (err) {
102104
console.error('[NES] 新建存档失败', err)
103105
showToast(`存档失败: ${describeError(err)}`)
106+
return false
104107
}
105108
}
106109
@@ -575,7 +578,7 @@ defineExpose({
575578
<template>
576579
<div
577580
class="screen-wrap"
578-
:class="{ 'without-controls': settings.misc.touchPad === 'never', 'always-controls': settings.misc.touchPad === 'always' }"
581+
:class="{ 'without-controls': !layoutEditing && settings.misc.touchPad === 'never', 'always-controls': layoutEditing || settings.misc.touchPad === 'always' }"
579582
:style="{ background: settings.display.bgColor }"
580583
>
581584
<div ref="displayRef" class="display-area">
@@ -591,6 +594,7 @@ defineExpose({
591594

592595
<!-- 触屏虚拟手柄(经典分离式,支持斜向与多点触控) -->
593596
<TouchControls
597+
:editing="layoutEditing"
594598
:disabled="inputLocked || gamePaused"
595599
:menu-disabled="inputLocked"
596600
:can-save="!!romKey && !inputLocked"
@@ -619,28 +623,12 @@ defineExpose({
619623
min-width: 0;
620624
overflow: hidden;
621625
}
622-
@media (pointer: coarse) and (orientation: landscape) {
623-
.screen-wrap:not(.without-controls) {
624-
grid-template-columns: clamp(156px, 22vw, 208px) minmax(0, 1fr) clamp(156px, 22vw, 208px);
625-
grid-template-rows: 56px minmax(0, 1fr) 56px;
626-
}
627-
.screen-wrap:not(.without-controls) .display-area {
628-
grid-column: 2;
629-
grid-row: 2;
630-
}
631-
}
626+
/* 横屏让画面使用完整区域,触屏按键通过绝对定位叠加。 */
632627
@media (pointer: coarse) and (orientation: portrait) {
633628
.screen-wrap:not(.without-controls) {
634629
grid-template-rows: repeat(2, minmax(0, 1fr));
635630
}
636631
}
637-
@media (orientation: landscape) {
638-
.screen-wrap.always-controls {
639-
grid-template-columns: clamp(156px, 22vw, 208px) minmax(0, 1fr) clamp(156px, 22vw, 208px);
640-
grid-template-rows: 56px minmax(0, 1fr) 56px;
641-
}
642-
.screen-wrap.always-controls .display-area { grid-column: 2; grid-row: 2; }
643-
}
644632
@media (orientation: portrait) {
645633
.screen-wrap.always-controls { grid-template-rows: repeat(2, minmax(0, 1fr)); }
646634
}

‎packages/ui/src/components/PlayerShell.vue‎

Lines changed: 85 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<script setup lang="ts">
22
import SButton from '@qingfeng346/ui-kit/components/button/SButton.vue'
3-
import { computed, onBeforeUnmount, ref, watch, watchEffect } from 'vue'
3+
import { computed, onBeforeUnmount, onMounted, ref, watch, watchEffect } from 'vue'
44
import {
55
isTauri,
66
pickRomFile,
77
setLastRomName,
88
} from '../emulator/platform'
9+
import { settings } from '../emulator/settings'
910
import { sha256Hex } from '../store/romDownloader'
1011
import { navEnabled, useRemoteNav } from '../composables/useRemoteNav'
1112
import { useFullscreen } from '../composables/useFullscreen'
1213
import NesScreen from './NesScreen.vue'
1314
import SettingsModal from './SettingsModal.vue'
1415
import ShortcutsPanel from './ShortcutsPanel.vue'
1516
import PlayerFooter from './PlayerFooter.vue'
16-
import ToolbarMenu from './ToolbarMenu.vue'
1717
import type { SaveState } from '../emulator/runner'
1818
1919
type ToolbarMode = 'app' | 'web'
@@ -57,6 +57,25 @@ const audioOn = ref(true)
5757
const loading = ref(false)
5858
const paused = ref(false)
5959
const settingsOpen = ref(false)
60+
const layoutEditing = ref(false)
61+
function editTouchLayout() {
62+
layoutEditing.value = true
63+
settingsOpen.value = false
64+
}
65+
function finishTouchLayout() {
66+
settingsOpen.value = true
67+
layoutEditing.value = false
68+
}
69+
function resetTouchLayout() {
70+
const orientation = window.matchMedia('(orientation: portrait)').matches ? 'portrait' : 'landscape'
71+
settings.touchLayout[orientation] = {}
72+
}
73+
function onLayoutKey(event: KeyboardEvent) {
74+
if (!layoutEditing.value || event.code !== 'Escape') return
75+
event.preventDefault()
76+
finishTouchLayout()
77+
}
78+
onMounted(() => window.addEventListener('keydown', onLayoutKey))
6079
const settingsTab = ref<'library' | 'saves' | 'keys' | 'display' | 'audio' | 'misc'>('library')
6180
function openSettings(tab: typeof settingsTab.value) {
6281
settingsTab.value = tab
@@ -68,7 +87,7 @@ let exitArmedAt = 0
6887
let exitHintTimer: ReturnType<typeof setTimeout> | null = null
6988
7089
const inputLocked = computed(
71-
() => settingsOpen.value || helpOpen.value,
90+
() => settingsOpen.value || helpOpen.value || layoutEditing.value,
7291
)
7392
7493
const toolbarRef = ref<HTMLElement | null>(null)
@@ -122,17 +141,26 @@ async function loadRomBytes(name: string, bytes: Uint8Array, key: string) {
122141
}
123142
}
124143
125-
function saveState() {
126-
screen.value?.quickSave()
127-
}
128-
129-
async function loadState() {
130-
await screen.value?.quickLoad()
131-
syncPlayback()
132-
}
133-
134-
function newSave() {
135-
screen.value?.quickNewSave()
144+
const settingsModal = ref<InstanceType<typeof SettingsModal> | null>(null)
145+
const creatingSave = ref(false)
146+
const saveMessage = ref('')
147+
watch(settingsOpen, (open) => { if (open) saveMessage.value = '' })
148+
async function newSave() {
149+
if (creatingSave.value) return
150+
creatingSave.value = true
151+
saveMessage.value = ''
152+
try {
153+
const saved = await screen.value?.quickNewSave()
154+
if (saved) {
155+
await settingsModal.value?.refreshSaves()
156+
saveMessage.value = '已新建存档'
157+
} else {
158+
saveMessage.value = '新建失败,请重试'
159+
}
160+
} finally {
161+
syncPlayback()
162+
creatingSave.value = false
163+
}
136164
}
137165
138166
async function onLoadSave(payload: {
@@ -187,6 +215,10 @@ function onSystemAction(action: string) {
187215
188216
const EXIT_CONFIRM_MS = 2000
189217
function handleBack(): BackResult {
218+
if (layoutEditing.value) {
219+
finishTouchLayout()
220+
return 'handled'
221+
}
190222
if (helpOpen.value) {
191223
helpOpen.value = false
192224
return 'handled'
@@ -230,6 +262,7 @@ defineExpose({
230262
})
231263
232264
onBeforeUnmount(() => {
265+
window.removeEventListener('keydown', onLayoutKey)
233266
if (exitHintTimer) clearTimeout(exitHintTimer)
234267
})
235268
</script>
@@ -241,59 +274,54 @@ onBeforeUnmount(() => {
241274
:class="shellClasses"
242275
>
243276
<header ref="toolbarRef" class="desktop-toolbar" aria-label="游戏功能区">
244-
<h1>{{ title }}</h1>
245-
<SButton :disabled="loading" @click="openRom">{{ loading ? openLoadingLabel : '打开 ROM' }}</SButton>
246-
<SButton @click="openSettings('library')">{{ libraryLabel }}</SButton>
247-
<ToolbarMenu label="存档">
248-
<SButton class="menu-item" :disabled="!romName || loading" @click="saveState">快速存档 <kbd>F8</kbd></SButton>
249-
<SButton class="menu-item" :disabled="!romName || loading" @click="loadState">快速读档</SButton>
250-
<SButton class="menu-item" :disabled="!romName || loading" @click="newSave">新建存档</SButton>
251-
<SButton class="menu-item" @click="openSettings('saves')">存档列表</SButton>
252-
</ToolbarMenu>
253-
<SButton :disabled="!romName || loading" @click="togglePause">{{ paused ? '继续' : '暂停' }}</SButton>
254-
<SButton :disabled="!romName || loading" @click="reset">复位</SButton>
255-
<SButton :disabled="!romName || loading" @click="stopRom">中止</SButton>
256-
<SButton @click="toggleAudio">{{ audioOn ? '静音' : '开启声音' }}</SButton>
277+
<SButton @click="openSettings('library')">ROM 库</SButton>
257278
<SButton @click="toggleFullscreen">{{ isFullscreen ? '退出全屏' : '全屏' }}</SButton>
258279
<SButton title="打开设置 (Esc)" @click="settingsOpen = true">菜单</SButton>
259280
</header>
260281
<SettingsModal
282+
ref="settingsModal"
261283
v-model:open="settingsOpen"
262284
v-model:tab="settingsTab"
263285
:current-rom-key="romKey"
264286
@load-rom="(p) => loadRomBytes(p.name, p.bytes, p.key)"
265287
@load-save="onLoadSave"
288+
@edit-touch-layout="editTouchLayout"
266289
>
267290
<template #actions="{ tab }">
268291
<template v-if="tab === 'library'">
269292
<SButton :disabled="loading" @click="openRom">{{ loading ? openLoadingLabel : '打开本地 ROM' }}</SButton>
270293
</template>
271294
<template v-else-if="tab === 'saves'">
272-
<SButton :disabled="!romName || loading" @click="saveState">快速存档 · F8</SButton>
273-
<SButton :disabled="!romName || loading" @click="loadState">快速读档</SButton>
274-
<SButton :disabled="!romName || loading" @click="newSave">新建存档</SButton>
295+
<SButton :disabled="!romName || loading || creatingSave" @click="newSave">{{ creatingSave ? '保存中…' : '新建存档' }}</SButton>
296+
<span v-if="saveMessage" role="status">{{ saveMessage }}</span>
275297
</template>
276298
<template v-else-if="tab === 'misc'">
277299
<SButton :disabled="!romName || loading" @click="reset">复位游戏</SButton>
278300
<SButton :disabled="!romName || loading" @click="stopRom">中止游戏</SButton>
279-
<SButton @click="toggleFullscreen">{{ isFullscreen ? '退出全屏' : '全屏' }}</SButton>
301+
<SButton class="desktop-only" @click="toggleFullscreen">{{ isFullscreen ? '退出全屏' : '全屏' }}</SButton>
280302
</template>
281303
<SButton v-else-if="tab === 'audio'" @click="toggleAudio">{{ audioOn ? '静音' : '开启声音' }}</SButton>
282304
</template>
283305
</SettingsModal>
284306
<ShortcutsPanel v-model:open="helpOpen" :modifier="modKey" />
285307

286308
<main class="stage">
309+
<div v-if="layoutEditing" class="layout-edit-tools">
310+
<span>拖动虚线区域调整位置 · 自动保存</span>
311+
<SButton @click="resetTouchLayout">重置当前方向</SButton>
312+
<SButton @click="finishTouchLayout">完成</SButton>
313+
</div>
287314
<NesScreen
288315
ref="screen"
289316
:input-locked="inputLocked"
317+
:layout-editing="layoutEditing"
290318
:game-paused="paused || loading"
291319
:modifier="modKey"
292320
:rom-key="romKey"
293321
:rom-name="romName"
294322
@system-action="onSystemAction"
295323
/>
296-
<div v-if="!romName" class="empty-state">
324+
<div v-if="!romName && !layoutEditing" class="empty-state">
297325
<p>通过菜单选择游戏或本地 ROM 开始游玩</p>
298326
<small>Esc 打开设置 · F8 快速存档</small>
299327
</div>
@@ -382,13 +410,6 @@ textarea,
382410
background: #242424;
383411
border-bottom: 1px solid #343434;
384412
}
385-
.desktop-toolbar h1 {
386-
flex: 1 0 auto;
387-
margin: 0 8px 0 0;
388-
font-size: 16px;
389-
font-weight: 600;
390-
white-space: nowrap;
391-
}
392413
.desktop-toolbar > :deep(.s-button) {
393414
flex-shrink: 0;
394415
white-space: nowrap;
@@ -403,6 +424,25 @@ textarea,
403424
padding: 16px;
404425
position: relative;
405426
}
427+
.layout-edit-tools {
428+
position: absolute;
429+
z-index: 10;
430+
top: max(8px, env(safe-area-inset-top));
431+
left: 50%;
432+
transform: translateX(-50%);
433+
display: flex;
434+
align-items: center;
435+
justify-content: center;
436+
flex-wrap: wrap;
437+
gap: 8px;
438+
width: max-content;
439+
max-width: calc(100% - 24px);
440+
padding: 8px;
441+
border-radius: 8px;
442+
background: #202328ee;
443+
font-size: 13px;
444+
}
445+
.layout-edit-tools :deep(.s-button) { min-height: 44px; }
406446
.empty-state {
407447
position: absolute;
408448
display: flex;
@@ -439,11 +479,17 @@ textarea,
439479
opacity: 0;
440480
}
441481
@media (pointer: coarse) {
482+
.desktop-only { display: none; }
442483
.desktop-toolbar { display: none; }
443484
.stage {
444485
padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
445486
}
446487
.empty-state { top: 8px; gap: 8px; padding: 8px; font-size: 13px; }
447488
.empty-state small { display: none; }
448489
}
490+
@media (pointer: coarse) and (orientation: landscape) {
491+
.stage {
492+
padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
493+
}
494+
}
449495
</style>

‎packages/ui/src/components/RomStorePanel.vue‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,4 +643,47 @@ function formatError(err: unknown): string {
643643
.store-tools { grid-template-columns: repeat(2, minmax(0, 1fr)); }
644644
.search { grid-column: 1 / -1; }
645645
}
646+
@media (orientation: landscape) and (max-height: 540px) {
647+
.store-tools {
648+
flex-shrink: 0;
649+
grid-template-columns: minmax(100px, 1fr) minmax(90px, 120px) minmax(100px, 130px) auto;
650+
padding: 4px 12px;
651+
gap: 6px;
652+
}
653+
.search { grid-column: auto; }
654+
.check { height: 44px; }
655+
.store-summary { flex-shrink: 0; }
656+
.store-pager { padding: 4px 12px; }
657+
.game-list { grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); }
658+
}
659+
@media (orientation: landscape) and (max-height: 540px) and (max-width: 640px) {
660+
.store-tools { grid-template-columns: minmax(0, 1fr) minmax(90px, 110px); }
661+
.search { grid-column: auto; }
662+
}
663+
</style>
664+
665+
<style scoped>
666+
@media (pointer: coarse) {
667+
.store-tools {
668+
flex-shrink: 0;
669+
gap: var(--player-control-gap);
670+
padding: var(--player-tools-padding) 12px;
671+
}
672+
.store-summary {
673+
flex-shrink: 0;
674+
min-height: 24px;
675+
padding: 4px 12px;
676+
gap: 4px;
677+
font-size: 12px;
678+
line-height: 1.3;
679+
}
680+
.game-list { padding: 8px 12px; gap: var(--player-control-gap); }
681+
.game-card { padding: var(--player-card-padding); gap: var(--player-control-gap); }
682+
.game-actions { gap: var(--player-control-gap); }
683+
.meta { margin-top: 3px; font-size: 12px; line-height: 1.3; }
684+
.store-pager { gap: var(--player-control-gap); padding: 4px 12px; }
685+
.pager-btn { min-width: var(--player-control-height); padding-inline: 8px; }
686+
.page-info { min-width: 48px; }
687+
.tags { margin-top: 4px; gap: 4px; }
688+
}
646689
</style>

0 commit comments

Comments
 (0)