From 770e38202c9b8f408b9ac7b4999fd13375311ba0 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Sun, 19 Nov 2023 23:37:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=87=AA=E5=AE=9A=E4=B9=89=E6=8C=89?= =?UTF-8?q?=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/colomn.vue | 12 +- src/core/main/init/hotkey.ts | 5 +- src/core/main/init/settings.tsx | 11 +- src/core/main/init/ui.ts | 3 +- src/core/main/setting.ts | 2 +- src/ui/hotkey.vue | 229 ++++++++++++++++++++++++++++++++ src/ui/index.ts | 1 + src/ui/settings.vue | 17 +-- 8 files changed, 258 insertions(+), 22 deletions(-) create mode 100644 src/ui/hotkey.vue diff --git a/src/components/colomn.vue b/src/components/colomn.vue index 584b237..4951586 100644 --- a/src/components/colomn.vue +++ b/src/components/colomn.vue @@ -59,22 +59,22 @@ function resize() { if (has(props.right)) right.style.flexBasis = `${props.right}%`; } -function key(e: KeyboardEvent) { - const c = keycode(e.keyCode); - if (c === KeyCode.Escape || c === KeyCode.KeyX) emits('close'); -} +// function key(e: KeyboardEvent) { +// const c = keycode(e.keyCode); +// if (c === KeyCode.Escape || c === KeyCode.KeyX) emits('close'); +// } onMounted(async () => { resize(); await sleep(50); // if (mota.plugin.ui.transition.value) await sleep(600); - document.addEventListener('keyup', key); + // document.addEventListener('keyup', key); }); onUpdated(resize); onUnmounted(() => { - document.removeEventListener('keyup', key); + // document.removeEventListener('keyup', key); }); diff --git a/src/core/main/init/hotkey.ts b/src/core/main/init/hotkey.ts index 2ed8b5e..630fe89 100644 --- a/src/core/main/init/hotkey.ts +++ b/src/core/main/init/hotkey.ts @@ -15,7 +15,10 @@ gameKey .register({ id: 'book', name: '怪物手册', - defaults: KeyCode.KeyX + defaults: KeyCode.KeyX, + ctrl: true, + shift: true, + alt: true }) .register({ id: 'save', diff --git a/src/core/main/init/settings.tsx b/src/core/main/init/settings.tsx index 5a66194..9bf462c 100644 --- a/src/core/main/init/settings.tsx +++ b/src/core/main/init/settings.tsx @@ -1,6 +1,7 @@ import type { SettingComponent, SettingComponentProps } from '../setting'; import { Button, InputNumber } from 'ant-design-vue'; import { mainUi } from './ui'; +import { gameKey } from './hotkey'; interface Components { DefaultSetting: SettingComponent; @@ -70,13 +71,13 @@ function NumberSetting(props: SettingComponentProps) { ); } -function showSpecialSetting(id: string) { +function showSpecialSetting(id: string, vBind?: any) { const ui = mainUi.get(id); mainUi.showEnd(); ui.once('close', () => { mainUi.showAll(); }); - mainUi.open(id); + mainUi.open(id, vBind); } function HotkeySetting(props: SettingComponentProps) { @@ -86,7 +87,11 @@ function HotkeySetting(props: SettingComponentProps) { diff --git a/src/core/main/init/ui.ts b/src/core/main/init/ui.ts index 2a4b7a1..7cdb1fb 100644 --- a/src/core/main/init/ui.ts +++ b/src/core/main/init/ui.ts @@ -15,7 +15,8 @@ mainUi.register( new GameUi('fixedDetail', UI.FixedDetail), new GameUi('shop', UI.Shop), new GameUi('achievement', UI.Achievement), - new GameUi('bgm', UI.BgmList) + new GameUi('bgm', UI.BgmList), + new GameUi('hotkey', UI.Hotkey) // todo: 把游戏主 div 加入到 mainUi 里面 ); mainUi.showAll(); diff --git a/src/core/main/setting.ts b/src/core/main/setting.ts index 874100f..501d53f 100644 --- a/src/core/main/setting.ts +++ b/src/core/main/setting.ts @@ -389,7 +389,7 @@ mainSetting new MotaSetting() .register('autoSkill', '自动切换技能', true, COM.BooleanSetting) .register('fixed', '定点查看', true, COM.BooleanSetting) - .register('hotkey', '快捷键', false, COM.BooleanSetting) + .register('hotkey', '快捷键', false, COM.HotkeySetting) .setDisplayFunc('hotkey', () => '') .register('toolbar', '自定义工具栏', false, COM.BooleanSetting) .setDisplayFunc('toolbar', () => '') diff --git a/src/ui/hotkey.vue b/src/ui/hotkey.vue new file mode 100644 index 0000000..87eb85a --- /dev/null +++ b/src/ui/hotkey.vue @@ -0,0 +1,229 @@ + + + + + diff --git a/src/ui/index.ts b/src/ui/index.ts index cb9c1a6..42472cc 100644 --- a/src/ui/index.ts +++ b/src/ui/index.ts @@ -19,3 +19,4 @@ export { default as StatusBar } from './statusBar.vue'; export { default as Studied } from './studied.vue'; export { default as Study } from './study.vue'; export { default as Toolbox } from './toolbox.vue'; +export { default as Hotkey } from './hotkey.vue'; diff --git a/src/ui/settings.vue b/src/ui/settings.vue index ee4bf96..25bc671 100644 --- a/src/ui/settings.vue +++ b/src/ui/settings.vue @@ -83,11 +83,14 @@ import Scroll from '../components/scroll.vue'; import { isMobile } from '../plugin/use'; import { sleep } from 'mutate-animate'; import { KeyCode } from '../plugin/keyCodes'; +import { gameKey } from '@/core/main/init/hotkey'; +import { GameUi } from '@/core/main/custom/ui'; const props = defineProps<{ info?: MotaSetting; text?: SettingText; num: number; + ui: GameUi; }>(); const setting = props.info ?? mainSetting; @@ -143,19 +146,13 @@ function exit() { mota.ui.main.close(props.num); } -function key(e: KeyboardEvent) { - const c = keycode(e.keyCode); - if (c === KeyCode.Escape || c === KeyCode.KeyX) exit(); -} - -onMounted(async () => { - await sleep(50); - // if (mota.plugin.ui.transition.value) await sleep(600); - document.addEventListener('keyup', key); +gameKey.use(props.ui.symbol); +gameKey.realize('exit', () => { + exit(); }); onUnmounted(() => { - document.removeEventListener('keyup', key); + gameKey.dispose(props.ui.symbol); });