再次按下esc取消pick

This commit is contained in:
xu_yanfeng 2025-02-06 16:53:06 +08:00
parent 1d94f11ab4
commit 035457fbdc
2 changed files with 45 additions and 17 deletions

View File

@ -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<HTMLDivElement>(null);
const showBtns = ref(true);
if (config.value.autoHide) {

View File

@ -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);