From cf9c6b55d6c7fc2a927743b2c19d5af4867f05d6 Mon Sep 17 00:00:00 2001 From: xu_yanfeng Date: Sat, 8 Mar 2025 14:22:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E5=81=9C=E6=B8=B8=E6=88=8F=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=BD=BF=E7=94=A8=E5=BF=AB=E6=8D=B7=E9=94=AE=E6=93=8D?= =?UTF-8?q?=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/scripts/inject-view/app.vue | 83 +++++++++++++++++++++++++------- src/scripts/inject/hint/index.ts | 5 +- 2 files changed, 68 insertions(+), 20 deletions(-) diff --git a/src/scripts/inject-view/app.vue b/src/scripts/inject-view/app.vue index a854cab..e1d781d 100644 --- a/src/scripts/inject-view/app.vue +++ b/src/scripts/inject-view/app.vue @@ -2,7 +2,7 @@
-
+
@@ -20,18 +20,19 @@ 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 {} from "../inject/hint"; import { inspectTarget } from "../inject/inspect-list"; import Ad from "./ad.vue"; import Banner from "./banner.vue"; import Memory from "./memory.vue"; +import Shortkeys from "./shortkeys.vue"; import { appStore } from "./store"; import { sendGaEvent } from "./util"; declare const cc: any; const { CCDialog, CCMenu } = ccui.components; interface ListItem { icon: string; - txt: string; + txt: string | Function; visible: boolean; /** * 点击回调 @@ -57,7 +58,7 @@ export default defineComponent({ const rnd = randomSupport(); const { config } = storeToRefs(appStore()); function doInspector() { - unregisterPickShortKey(); + unregisterShortKey(); sendGaEvent(GA_EventName.GameInspector); if (config.value.autoHide) { showBtns.value = false; @@ -88,6 +89,21 @@ export default defineComponent({ }); }, }, + { + icon: "icon_settings", + txt: "Settings", + visible: true, + contextmenu: () => {}, + click: () => { + ccui.dialog.showDialog({ + title: "Settings", + comp: Shortkeys, + width: 400, + height: 150, + closeCB: () => {}, + }); + }, + }, { icon: "icon_book", txt: "插件完整功能介绍(Gif动画)", @@ -107,13 +123,17 @@ export default defineComponent({ } }, visible: true, - txt: "game play", + txt: () => { + return `game resume (${config.value.shortKeyGamePauseResume})`; + }, contextmenu: () => {}, }, { icon: "icon_do_pause", visible: true, - txt: "game pause", + txt: () => { + return `game pause (${config.value.shortKeyGamePauseResume})`; + }, click: () => { sendGaEvent(GA_EventName.GamePause); if (typeof cc !== "undefined") { @@ -125,7 +145,9 @@ export default defineComponent({ { icon: "icon_do_step", visible: true, - txt: "game step", + txt: () => { + return `game step (${config.value.shortKeyGameStep})`; + }, click: () => { sendGaEvent(GA_EventName.GameStep); if (typeof cc !== "undefined") { @@ -136,7 +158,9 @@ export default defineComponent({ }, { icon: "icon_target", - txt: "Inspect Game (esc)", + txt: () => { + return `Inspect Game (${config.value.shortKeyPick})`; + }, visible: true, click: () => { doInspector(); @@ -197,7 +221,7 @@ export default defineComponent({ ]); document.addEventListener(DocumentEvent.GameInspectorEnd, () => { picking.value = false; - registerPickShortKey(); + registerShortKey(); }); function testInspector() { const cursor = document.body.style.cursor; @@ -245,20 +269,38 @@ export default defineComponent({ const picking = ref(false); - const pickShortFunc = (e: KeyboardEvent) => { - if (e.key === PickShortKey && picking.value === false) { - doInspector(); + const keydownFunc = (e: KeyboardEvent) => { + const { shortKeyPick, shortKeyGameStep, shortKeyGamePauseResume } = config.value; + switch (e.code) { + case shortKeyPick: { + if (picking.value === false) { + doInspector(); + } + break; + } + case shortKeyGameStep: { + cc.game.step(); + break; + } + case shortKeyGamePauseResume: { + if (cc.game.isPaused()) { + cc.game.resume(); + } else { + cc.game.pause(); + } + break; + } } }; - function registerPickShortKey() { + function registerShortKey() { if (picking.value === false) { - document.addEventListener("keydown", pickShortFunc, true); + document.addEventListener("keydown", keydownFunc, true); } } - function unregisterPickShortKey() { - document.removeEventListener("keydown", pickShortFunc, true); + function unregisterShortKey() { + document.removeEventListener("keydown", keydownFunc, true); } - registerPickShortKey(); + registerShortKey(); const rootEl = ref(null); const showBtns = ref(true); @@ -272,6 +314,13 @@ export default defineComponent({ listArray, rootEl, picking, + getTitle(item: ListItem) { + if (typeof item.txt === "function") { + return item.txt(); + } else { + return item.txt; + } + }, onMouseEnterCocosLogo() { clearTimeout(autoHideTimer); showBtns.value = true; diff --git a/src/scripts/inject/hint/index.ts b/src/scripts/inject/hint/index.ts index dc02968..e501b6e 100644 --- a/src/scripts/inject/hint/index.ts +++ b/src/scripts/inject/hint/index.ts @@ -11,8 +11,6 @@ import { HintV2 } from "./hint-v2"; import { HintV3 } from "./hint-v3"; declare const cc: any; -export const PickShortKey = "Escape"; - /** * 只负责管理hint的流程 */ @@ -69,7 +67,8 @@ export class Hint { this.updateHitMoveThrottle(event, el); }; const keydown = (event: KeyboardEvent) => { - if (event.key === PickShortKey) { + const { shortKeyPick } = toRaw(appStore().config); + if (event.code === shortKeyPick) { pickEnd(); this.pickCancel(); }