mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-04-20 08:58:41 +00:00
再次按下esc取消pick
This commit is contained in:
parent
1d94f11ab4
commit
035457fbdc
@ -20,6 +20,7 @@ import { storeToRefs } from "pinia";
|
|||||||
import { defineComponent, onMounted, ref, toRaw } from "vue";
|
import { defineComponent, onMounted, ref, toRaw } from "vue";
|
||||||
import { GA_EventName } from "../../ga/type";
|
import { GA_EventName } from "../../ga/type";
|
||||||
import { DocumentEvent } from "../const";
|
import { DocumentEvent } from "../const";
|
||||||
|
import { PickShortKey } from "../inject/hint";
|
||||||
import { inspectTarget } from "../inject/inspect-list";
|
import { inspectTarget } from "../inject/inspect-list";
|
||||||
import Ad from "./ad.vue";
|
import Ad from "./ad.vue";
|
||||||
import Banner from "./banner.vue";
|
import Banner from "./banner.vue";
|
||||||
@ -51,20 +52,12 @@ export default defineComponent({
|
|||||||
const idx = Math.floor(Math.random() * arr.length);
|
const idx = Math.floor(Math.random() * arr.length);
|
||||||
return arr[idx];
|
return arr[idx];
|
||||||
}
|
}
|
||||||
document.addEventListener(
|
|
||||||
"keydown",
|
|
||||||
(e: KeyboardEvent) => {
|
|
||||||
if ((e.key === "Escape" || e.keyCode === 27) && picking.value === false) {
|
|
||||||
doInspector();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
true
|
|
||||||
);
|
|
||||||
const store = appStore();
|
const store = appStore();
|
||||||
store.init();
|
store.init();
|
||||||
const rnd = randomSupport();
|
const rnd = randomSupport();
|
||||||
const { config } = storeToRefs(appStore());
|
const { config } = storeToRefs(appStore());
|
||||||
function doInspector() {
|
function doInspector() {
|
||||||
|
unregisterPickShortKey();
|
||||||
ga(GA_EventName.GameInspector);
|
ga(GA_EventName.GameInspector);
|
||||||
if (config.value.autoHide) {
|
if (config.value.autoHide) {
|
||||||
showBtns.value = false;
|
showBtns.value = false;
|
||||||
@ -194,6 +187,7 @@ export default defineComponent({
|
|||||||
]);
|
]);
|
||||||
document.addEventListener(DocumentEvent.GameInspectorEnd, () => {
|
document.addEventListener(DocumentEvent.GameInspectorEnd, () => {
|
||||||
picking.value = false;
|
picking.value = false;
|
||||||
|
registerPickShortKey();
|
||||||
});
|
});
|
||||||
function testInspector() {
|
function testInspector() {
|
||||||
const cursor = document.body.style.cursor;
|
const cursor = document.body.style.cursor;
|
||||||
@ -240,6 +234,24 @@ export default defineComponent({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const picking = ref(false);
|
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 rootEl = ref<HTMLDivElement>(null);
|
||||||
const showBtns = ref(true);
|
const showBtns = ref(true);
|
||||||
if (config.value.autoHide) {
|
if (config.value.autoHide) {
|
||||||
|
@ -11,6 +11,8 @@ import { HintV2 } from "./hint-v2";
|
|||||||
import { HintV3 } from "./hint-v3";
|
import { HintV3 } from "./hint-v3";
|
||||||
declare const cc: any;
|
declare const cc: any;
|
||||||
|
|
||||||
|
export const PickShortKey = "Escape";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 只负责管理hint的流程
|
* 只负责管理hint的流程
|
||||||
*/
|
*/
|
||||||
@ -44,29 +46,43 @@ export class Hint {
|
|||||||
const mousedown = (event: MouseEvent) => {
|
const mousedown = (event: MouseEvent) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
el.removeEventListener("mousedown", mousedown, true);
|
pickEnd();
|
||||||
el.removeEventListener("mousemove", mousemove, true);
|
|
||||||
el.style.cursor = cursor;
|
|
||||||
const e = new CustomEvent(DocumentEvent.GameInspectorEnd);
|
|
||||||
document.dispatchEvent(e);
|
|
||||||
|
|
||||||
if (event.button === 0) {
|
if (event.button === 0) {
|
||||||
// 左键拾取
|
// 左键拾取
|
||||||
this.updateHintDown(event, el);
|
this.updateHintDown(event, el);
|
||||||
} else {
|
} 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) => {
|
const mousemove = (event: MouseEvent) => {
|
||||||
this.updateHitMoveThrottle(event, el);
|
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("mousemove", mousemove, true);
|
||||||
el.addEventListener("mousedown", mousedown, true);
|
el.addEventListener("mousedown", mousedown, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
private pickCancel() {
|
||||||
|
this.updateHitMoveThrottle.cancel();
|
||||||
|
this.cleanHover();
|
||||||
|
}
|
||||||
private updateHitMoveThrottle = throttle(this.updateHintMove, 300);
|
private updateHitMoveThrottle = throttle(this.updateHintMove, 300);
|
||||||
private updateHintMove(event: MouseEvent, canvas: HTMLCanvasElement) {
|
private updateHintMove(event: MouseEvent, canvas: HTMLCanvasElement) {
|
||||||
const nodes = this.getMouseNodes(event, canvas);
|
const nodes = this.getMouseNodes(event, canvas);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user