From 608cd15f76cbaeab05eb39744f8ac8525639c5a2 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Fri, 26 Sep 2025 12:46:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B5=8F=E8=A7=88=E5=9C=B0=E5=9B=BE?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E6=8C=89=20Esc=20=E9=80=80=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client-modules/src/render/ui/viewmap.tsx | 8 ++++- packages/system-action/src/hotkey.ts | 35 ++++++++++++++++--- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/packages-user/client-modules/src/render/ui/viewmap.tsx b/packages-user/client-modules/src/render/ui/viewmap.tsx index 82a7364..aab0567 100644 --- a/packages-user/client-modules/src/render/ui/viewmap.tsx +++ b/packages-user/client-modules/src/render/ui/viewmap.tsx @@ -112,7 +112,13 @@ export const ViewMap = defineComponent(props => { .realize('@viewMap_book', () => openBook()) .realize('@viewMap_fly', () => fly()) .realize('@viewMap_reset', () => resetCamera()) - .realize('confirm', () => close()); + .realize('confirm', () => close()) + .realize('exit', (_, code, assist) => { + // 如果按键不能触发怪物手册,则关闭界面,因为怪物手册和退出默认使用同一个按键,需要特判 + if (!key.willEmit(code, assist, 'book')) { + props.controller.close(props.instance); + } + }); //#region 功能函数 diff --git a/packages/system-action/src/hotkey.ts b/packages/system-action/src/hotkey.ts index c1da6d5..8fb5156 100644 --- a/packages/system-action/src/hotkey.ts +++ b/packages/system-action/src/hotkey.ts @@ -52,6 +52,7 @@ export interface HotkeyData extends Required { type HotkeyFunc = ( id: string, code: KeyCode, + assist: number, ev: KeyboardEvent ) => void | '@void'; @@ -223,6 +224,30 @@ export class Hotkey extends EventEmitter { if (emit) this.emit('set', id, key, assist); } + /** + * 判断指定按键和辅助按键是否可能会触发给定 id 的按键操作 + * @param key 按键 + * @param assist 辅助按键 + * @param id 注册的按键操作 id + */ + willEmit(key: KeyCode, assist: number, id: string) { + const emittable = this.keyMap.get(key); + if (!emittable) return false; + const { ctrl, shift, alt } = unwarpBinary(assist); + return emittable.some(v => { + if ( + v.id === id && + v.ctrl === ctrl && + v.shift === shift && + v.alt === alt + ) { + return true; + } else { + return false; + } + }); + } + /** * 触发一个按键 * @param key 要触发的按键 @@ -256,12 +281,12 @@ export class Hotkey extends EventEmitter { if (!data) return; if (type === 'up' && data.onUp) { - data.onUp(v.id, key, ev); + data.onUp(v.id, key, assist, ev); emitted = true; return; } if (!this.canEmit(v.id, key, type, data)) return; - const res = data.func(v.id, key, ev); + const res = data.func(v.id, key, assist, ev); if (res !== '@void') emitted = true; } }); @@ -453,12 +478,12 @@ document.addEventListener('keyup', e => { } } else { // polyfill样板 - if (main.dom.inputDiv.style.display == 'block') { - if (e.keyCode == 13) { + if (main.dom.inputDiv.style.display === 'block') { + if (e.keyCode === 13) { setTimeout(function () { main.dom.inputYes.click(); }, 50); - } else if (e.keyCode == 27) { + } else if (e.keyCode === 27) { setTimeout(function () { main.dom.inputNo.click(); }, 50);