Skip to content

Commit af48dcf

Browse files
author
linyuan.yang
committed
迁移 footer
1 parent 9ac41e6 commit af48dcf

8 files changed

Lines changed: 238 additions & 159 deletions

File tree

‎package-lock.json‎

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/app/src/App.vue‎

Lines changed: 17 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ import {
88
SettingsModal,
99
ShortcutsPanel,
1010
ToolbarMenu,
11-
settings,
11+
PlayerFooter,
1212
sha256Hex,
1313
navEnabled,
14-
hasGamepad,
1514
isTv,
1615
useAutoHideToolbar,
1716
useFullscreen,
18-
useInputMonitor,
1917
useRemoteNav,
2018
type SaveState,
2119
} from '@nes-emulator/player'
@@ -60,14 +58,10 @@ useRemoteNav({
6058
onBack: consumeBack, // 主界面返回键 → 分级返回(JS 侧路径,'exit' 时走 process.exit)
6159
})
6260
63-
// 游戏运行(已载入且未暂停)时自动隐藏顶部工具栏,鼠标移到顶部/触屏点顶部唤出;
61+
// 游戏运行(已载入且未暂停)时自动隐藏顶部工具栏,点击顶部热区/把手唤出(所有平台统一用点击);
6462
// TV/遥控无鼠标无触屏,靠暂停(paused → isPlaying 变假)调出工具栏。
6563
const isPlaying = computed(() => !!romName.value && !paused.value)
66-
const {
67-
visible: toolbarVisible,
68-
handlePointerMove: onToolbarPointerMove,
69-
toggle: toggleToolbar,
70-
} = useAutoHideToolbar(isPlaying)
64+
const { visible: toolbarVisible, toggle: toggleToolbar } = useAutoHideToolbar(isPlaying)
7165
7266
// 焦点环作用到全局(含 Teleport 到 body 的下拉菜单):TV 或已连手柄时给 <html> 标记 tv-nav。
7367
if (typeof document !== 'undefined') {
@@ -80,9 +74,6 @@ if (typeof document !== 'undefined') {
8074
const modKey: 'ctrl' | 'shift' = isTauri ? 'ctrl' : 'shift'
8175
const modLabel = isTauri ? 'Ctrl' : 'Shift'
8276
83-
// 调试:当前按下的按键(键盘/手柄/遥控),仅在设置开启时显示于状态栏。
84-
const { label: inputLabel } = useInputMonitor()
85-
8677
async function openRom() {
8778
const picked = await pickRomFile()
8879
if (!picked) return
@@ -251,16 +242,17 @@ onBeforeUnmount(() => {
251242
'is-fullscreen': isFullscreen,
252243
'is-pseudo-fullscreen': isFullscreen && usePseudo,
253244
}"
254-
@mousemove="onToolbarPointerMove"
255245
>
256-
<!-- 触屏顶部热区:工具栏隐藏时点此唤出(桌面用鼠标 hover) -->
257-
<div v-if="isPlaying" class="toolbar-hotzone" @click="toggleToolbar" />
246+
<!-- 触屏顶部热区:工具栏隐藏时点此唤出(桌面用鼠标 hover)。
247+
用 pointerup 而非 click:部分 WebView 对无 cursor:pointer 的 <div> 不派发 click,
248+
pointer 事件不受此限,配合下方 cursor:pointer 确保各平台都能点。 -->
249+
<div v-if="isPlaying" class="toolbar-hotzone" @pointerup="toggleToolbar" />
258250
<!-- 顶部唤出手柄:游戏时工具栏自动隐藏,点此(或桌面把鼠标移到顶部)滑出菜单栏。 -->
259251
<button
260252
v-if="isPlaying && !toolbarVisible"
261253
class="toolbar-handle"
262254
title="显示菜单栏"
263-
@click="toggleToolbar"
255+
@pointerup="toggleToolbar"
264256
>
265257
☰
266258
</button>
@@ -333,14 +325,11 @@ onBeforeUnmount(() => {
333325
<div v-if="exitHintVisible" class="exit-hint" role="status">再按一次返回键退出</div>
334326
</Transition>
335327

336-
<footer class="footer">
337-
<button class="link-btn" @click="helpOpen = true">查看所有快捷键</button>
338-
<span v-if="navEnabled && !hasGamepad" class="tv-tip">游戏操作需连接手柄;遥控器用于菜单导航,返回键退出</span>
339-
<span v-if="settings.misc.showInputDebug" class="input-debug">
340-
按键 <b>{{ inputLabel || '—' }}</b>
341-
</span>
342-
<span class="meta">{{ romName ?? '未载入' }} · {{ isTauri ? 'Tauri App' : '浏览器预览' }}</span>
343-
</footer>
328+
<PlayerFooter
329+
:rom-name="romName"
330+
:platform-label="isTauri ? 'Tauri App' : '浏览器预览'"
331+
@help="helpOpen = true"
332+
/>
344333
</div>
345334
</template>
346335

@@ -440,6 +429,10 @@ textarea,
440429
right: 0;
441430
height: 52px;
442431
z-index: 400;
432+
/* 部分 WebView 需 cursor:pointer 才把 <div> 视作可点击并派发点击;
433+
touch-action:manipulation 去掉双击缩放延迟,点顶部唤出更跟手。 */
434+
cursor: pointer;
435+
touch-action: manipulation;
443436
}
444437
/* 顶部唤出手柄:游戏时工具栏隐藏才出现,点击滑出菜单栏(所有平台可见,便于发现)。 */
445438
.toolbar-handle {
@@ -520,45 +513,6 @@ textarea,
520513
font-size: 13px;
521514
text-align: center;
522515
}
523-
.footer {
524-
display: flex;
525-
align-items: center;
526-
justify-content: space-between;
527-
flex-wrap: wrap;
528-
gap: 8px;
529-
padding: 8px 16px;
530-
background: #242424;
531-
border-top: 1px solid #343434;
532-
color: #aaa;
533-
font-size: 12px;
534-
}
535-
.footer .meta {
536-
color: #777;
537-
margin-left: auto;
538-
}
539-
/* 调试:当前按下的按键 */
540-
.footer .input-debug {
541-
color: #888;
542-
font-family: ui-monospace, 'Cascadia Code', monospace;
543-
}
544-
.footer .input-debug b {
545-
color: #6ab0ff;
546-
font-weight: 600;
547-
}
548-
.footer .tv-tip {
549-
color: #6ab0ff;
550-
}
551-
.link-btn {
552-
border: none;
553-
background: transparent;
554-
color: #6ab0ff;
555-
cursor: pointer;
556-
font-size: 12px;
557-
padding: 0;
558-
}
559-
.link-btn:hover {
560-
text-decoration: underline;
561-
}
562516
.exit-hint {
563517
position: fixed;
564518
left: 50%;

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,15 @@ onMounted(() => {
452452
runner = new NesRunner(canvasRef.value!)
453453
runner.setVolume(settings.audio.volume)
454454
runner.setSpeed(settings.misc.speed)
455+
// 防串键:Nostalgist/RetroArch 会给 canvas 设 tabindex 并在启动/点击时 focus(),
456+
// 而其内部键盘 handler 只要 event.target===canvas 就直接处理真实按键 —— 于是画面
457+
// 获得焦点后,真实键盘会绕过下面的自定义映射漏进引擎,且引擎虚拟键位(i/j/k/l)恰与
458+
// 玩家键冲突(如物理 J 被引擎当成"左"),表现为串键。我们所有输入都经 press/release
459+
// 以合成事件(显式带 target=canvas,不依赖焦点)喂引擎,引擎无需真实焦点,故让 canvas
460+
// 永不持有焦点:任何获得焦点的瞬间立即 blur,真实按键 target 便不再是 canvas 被引擎忽略。
461+
const canvas = canvasRef.value!
462+
canvas.addEventListener('focus', () => canvas.blur())
463+
canvas.blur()
455464
window.addEventListener('keydown', onKeyDown)
456465
window.addEventListener('keyup', onKeyUp)
457466
window.addEventListener('gamepadconnected', autoBindGamepad)
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<script setup lang="ts">
2+
import { settings } from '../emulator/settings'
3+
import { navEnabled, hasGamepad } from '../composables/useRemoteNav'
4+
import { useInputMonitor } from '../composables/useInputMonitor'
5+
6+
defineProps<{
7+
// 当前载入的 ROM 名,未载入时为 null(显示「未载入」)。
8+
romName: string | null
9+
// 右侧平台标注文案,由各宿主传入(如 'Tauri App' / '浏览器预览' / 'Web 模式')。
10+
platformLabel: string
11+
// 触屏设备隐藏 footer:键盘按键提示对手机无用,让出垂直空间。web 端开启。
12+
hideOnTouch?: boolean
13+
}>()
14+
15+
defineEmits<{
16+
// 点击「查看所有快捷键」:由宿主打开 ShortcutsPanel。
17+
(e: 'help'): void
18+
}>()
19+
20+
// 调试:当前按下的按键(键盘/手柄/遥控),仅在设置开启时显示。
21+
const { label: inputLabel } = useInputMonitor()
22+
</script>
23+
24+
<template>
25+
<footer class="footer" :class="{ 'hide-on-touch': hideOnTouch }">
26+
<button class="link-btn" @click="$emit('help')">查看所有快捷键</button>
27+
<span v-if="navEnabled && !hasGamepad" class="tv-tip">游戏操作需连接手柄;遥控器用于菜单导航,返回键退出</span>
28+
<span v-if="settings.misc.showInputDebug" class="input-debug">
29+
按键 <b>{{ inputLabel || '—' }}</b>
30+
</span>
31+
<span class="meta">{{ romName ?? '未载入' }} · {{ platformLabel }}</span>
32+
</footer>
33+
</template>
34+
35+
<style scoped>
36+
.footer {
37+
display: flex;
38+
align-items: center;
39+
justify-content: space-between;
40+
flex-wrap: wrap;
41+
gap: 8px;
42+
padding: 8px 16px;
43+
background: #242424;
44+
border-top: 1px solid #343434;
45+
color: #aaa;
46+
font-size: 12px;
47+
}
48+
.footer .meta {
49+
color: #777;
50+
margin-left: auto;
51+
}
52+
/* 调试:当前按下的按键 */
53+
.footer .input-debug {
54+
color: #888;
55+
font-family: ui-monospace, 'Cascadia Code', monospace;
56+
}
57+
.footer .input-debug b {
58+
color: #6ab0ff;
59+
font-weight: 600;
60+
}
61+
.footer .tv-tip {
62+
color: #6ab0ff;
63+
}
64+
.link-btn {
65+
border: none;
66+
background: transparent;
67+
color: #6ab0ff;
68+
cursor: pointer;
69+
font-size: 12px;
70+
padding: 0;
71+
}
72+
.link-btn:hover {
73+
text-decoration: underline;
74+
}
75+
/* 触屏设备:footer 的键盘按键提示对手机无用,直接隐藏让出垂直空间。 */
76+
@media (pointer: coarse) {
77+
.footer.hide-on-touch {
78+
display: none;
79+
}
80+
}
81+
</style>

‎packages/player/src/components/ToolbarMenu.vue‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@ async function toggle() {
2929
if (!open.value) return
3030
await nextTick()
3131
const r = btn.value?.getBoundingClientRect()
32-
if (r) pos.value = { top: r.bottom + 4, left: r.left }
32+
if (!r) return
33+
// 默认与按钮左对齐向右展开;但菜单按钮常在工具栏最右端,向右展开会溢出屏幕。
34+
// 测出下拉实际宽度后把 left 钳到视口内(右溢出即贴右边缘,等效右对齐),两侧留 8px 边距。
35+
const margin = 8
36+
const vw = window.innerWidth
37+
const ddW = dropdownRef.value?.offsetWidth ?? 168
38+
let left = r.left
39+
if (left + ddW + margin > vw) left = vw - ddW - margin
40+
if (left < margin) left = margin
41+
pos.value = { top: r.bottom + 4, left }
3342
}
3443
function close() {
3544
open.value = false

‎packages/player/src/composables/useAutoHideToolbar.ts‎

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,25 @@ import { computed, onBeforeUnmount, ref, watch, type Ref } from 'vue'
22

33
// ===== 游戏运行时自动隐藏顶部工具栏(沉浸式),需要时再唤出 =====
44
// active 为真(通常 = 已载入且未暂停)时进入自动隐藏模式:默认收起,
5-
// 鼠标移到屏幕顶部区域滑出、离开自动收起(像视频播放器);触屏点顶部热区切换。
5+
// 点击顶部热区 / 把手切换显示(所有平台统一用点击,不再用鼠标 hover),唤出后定时自动收起。
66
// active 为假(未载入 / 暂停 / 遥控暂停)时工具栏恒显示——TV 无鼠标无触屏,靠暂停调出。
77

88
export interface AutoHideToolbarApi {
99
/** 工具栏当前是否应显示 */
1010
visible: Ref<boolean>
11-
/** 绑到根容器 mousemove:据指针纵向位置控制顶部滑出/收起 */
12-
handlePointerMove: (e: MouseEvent) => void
13-
/** 触屏顶部热区点击:切换显示,唤出后定时自动收起 */
11+
/** 点击顶部热区 / 把手:切换显示,唤出后定时自动收起 */
1412
toggle: () => void
1513
}
1614

1715
export function useAutoHideToolbar(
1816
active: Ref<boolean>,
19-
opts?: { zone?: number; timeout?: number },
17+
opts?: { timeout?: number },
2018
): AutoHideToolbarApi {
21-
const zone = opts?.zone ?? 64 // 顶部感应区高度(px),略大于工具栏本身,便于指针停留
22-
const timeout = opts?.timeout ?? 3000 // 触屏唤出后自动收起延时(ms)
19+
const timeout = opts?.timeout ?? 3000 // 唤出后自动收起延时(ms)
2320
const revealed = ref(false)
2421
let hideTimer = 0
2522

26-
// 非自动隐藏模式恒显示;否则由交互控制。
23+
// 非自动隐藏模式恒显示;否则由点击控制。
2724
const visible = computed(() => !active.value || revealed.value)
2825

2926
function clearTimer(): void {
@@ -33,23 +30,10 @@ export function useAutoHideToolbar(
3330
}
3431
}
3532

36-
function handlePointerMove(e: MouseEvent): void {
37-
if (!active.value) return
38-
if (e.clientY <= zone) {
39-
// 指针在顶部:滑出并保持(清掉触屏的自动收起)。
40-
revealed.value = true
41-
clearTimer()
42-
} else if (revealed.value) {
43-
// 指针离开顶部:收起。
44-
revealed.value = false
45-
clearTimer()
46-
}
47-
}
48-
4933
function toggle(): void {
5034
clearTimer()
5135
revealed.value = !revealed.value
52-
// 触屏无 mousemove 收起,唤出后定时自动隐藏。
36+
// 唤出后定时自动隐藏:去掉 hover 后,这是唯一的自动收起路径(否则展开后无处收回)。
5337
if (revealed.value) {
5438
hideTimer = window.setTimeout(() => {
5539
revealed.value = false
@@ -68,5 +52,5 @@ export function useAutoHideToolbar(
6852

6953
onBeforeUnmount(clearTimer)
7054

71-
return { visible, handlePointerMove, toggle }
55+
return { visible, toggle }
7256
}

‎packages/player/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export { default as RomStorePanel } from './components/RomStorePanel.vue'
44
export { default as SaveStatePanel } from './components/SaveStatePanel.vue'
55
export { default as ShortcutsPanel } from './components/ShortcutsPanel.vue'
66
export { default as ToolbarMenu } from './components/ToolbarMenu.vue'
7+
export { default as PlayerFooter } from './components/PlayerFooter.vue'
78
export { isAndroid, isTv } from './emulator/platform'
89
export {
910
useRemoteNav,

0 commit comments

Comments
 (0)