From 035457fbdc8f1dba2e8763b20e6c3ca65e700428 Mon Sep 17 00:00:00 2001 From: xu_yanfeng Date: Thu, 6 Feb 2025 16:53:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=8D=E6=AC=A1=E6=8C=89=E4=B8=8Besc?= =?UTF-8?q?=E5=8F=96=E6=B6=88pick?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/scripts/inject-view/app.vue | 30 +++++++++++++++++++++--------- src/scripts/inject/hint/index.ts | 32 ++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/src/scripts/inject-view/app.vue b/src/scripts/inject-view/app.vue index f1aee23..bdd8378 100644 --- a/src/scripts/inject-view/app.vue +++ b/src/scripts/inject-view/app.vue @@ -20,6 +20,7 @@ import { storeToRefs } from "pinia"; import { defineComponent, onMounted, ref, toRaw } from "vue"; import { GA_EventName } from "../../ga/type"; import { DocumentEvent } from "../const"; +import { PickShortKey } from "../inject/hint"; import { inspectTarget } from "../inject/inspect-list"; import Ad from "./ad.vue"; import Banner from "./banner.vue"; @@ -51,20 +52,12 @@ export default defineComponent({ const idx = Math.floor(Math.random() * arr.length); return arr[idx]; } - document.addEventListener( - "keydown", - (e: KeyboardEvent) => { - if ((e.key === "Escape" || e.keyCode === 27) && picking.value === false) { - doInspector(); - } - }, - true - ); const store = appStore(); store.init(); const rnd = randomSupport(); const { config } = storeToRefs(appStore()); function doInspector() { + unregisterPickShortKey(); ga(GA_EventName.GameInspector); if (config.value.autoHide) { showBtns.value = false; @@ -194,6 +187,7 @@ export default defineComponent({ ]); document.addEventListener(DocumentEvent.GameInspectorEnd, () => { picking.value = false; + registerPickShortKey(); }); function testInspector() { const cursor = document.body.style.cursor; @@ -240,6 +234,24 @@ export default defineComponent({ }); const picking = ref(false); + + const pickShortFunc = (e: KeyboardEvent) => { + e.preventDefault(); + e.stopPropagation(); + if (e.key === PickShortKey && picking.value === false) { + doInspector(); + } + }; + function registerPickShortKey() { + if (picking.value === false) { + document.addEventListener("keydown", pickShortFunc, true); + } + } + function unregisterPickShortKey() { + document.removeEventListener("keydown", pickShortFunc, true); + } + registerPickShortKey(); + const rootEl = ref(null); const showBtns = ref(true); if (config.value.autoHide) { diff --git a/src/scripts/inject/hint/index.ts b/src/scripts/inject/hint/index.ts index cf3b2dd..dc02968 100644 --- a/src/scripts/inject/hint/index.ts +++ b/src/scripts/inject/hint/index.ts @@ -11,6 +11,8 @@ import { HintV2 } from "./hint-v2"; import { HintV3 } from "./hint-v3"; declare const cc: any; +export const PickShortKey = "Escape"; + /** * 只负责管理hint的流程 */ @@ -44,29 +46,43 @@ export class Hint { const mousedown = (event: MouseEvent) => { event.stopPropagation(); event.preventDefault(); - el.removeEventListener("mousedown", mousedown, true); - el.removeEventListener("mousemove", mousemove, true); - el.style.cursor = cursor; - const e = new CustomEvent(DocumentEvent.GameInspectorEnd); - document.dispatchEvent(e); + pickEnd(); if (event.button === 0) { // 左键拾取 this.updateHintDown(event, el); } else { - this.updateHitMoveThrottle.cancel(); // 其他按键取消 - this.cleanHover(); + this.pickCancel(); } }; + function pickEnd() { + document.removeEventListener("keydown", keydown, true); + el.removeEventListener("mousedown", mousedown, true); + el.removeEventListener("mousemove", mousemove, true); + el.style.cursor = cursor; + const e = new CustomEvent(DocumentEvent.GameInspectorEnd); + document.dispatchEvent(e); + } + const mousemove = (event: MouseEvent) => { this.updateHitMoveThrottle(event, el); }; - + const keydown = (event: KeyboardEvent) => { + if (event.key === PickShortKey) { + pickEnd(); + this.pickCancel(); + } + }; + document.addEventListener("keydown", keydown, true); el.addEventListener("mousemove", mousemove, true); el.addEventListener("mousedown", mousedown, true); }); } + private pickCancel() { + this.updateHitMoveThrottle.cancel(); + this.cleanHover(); + } private updateHitMoveThrottle = throttle(this.updateHintMove, 300); private updateHintMove(event: MouseEvent, canvas: HTMLCanvasElement) { const nodes = this.getMouseNodes(event, canvas);