feat: 浏览地图可以按 Esc 退出

This commit is contained in:
unanmed 2025-09-26 12:46:38 +08:00
parent f9bd3fc3b4
commit 608cd15f76
2 changed files with 37 additions and 6 deletions

View File

@ -112,7 +112,13 @@ export const ViewMap = defineComponent<ViewMapProps>(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 功能函数

View File

@ -52,6 +52,7 @@ export interface HotkeyData extends Required<RegisterHotkeyData> {
type HotkeyFunc = (
id: string,
code: KeyCode,
assist: number,
ev: KeyboardEvent
) => void | '@void';
@ -223,6 +224,30 @@ export class Hotkey extends EventEmitter<HotkeyEvent> {
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<HotkeyEvent> {
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);