Inspector增加esc快捷键

This commit is contained in:
xu_yanfeng 2025-02-06 15:48:49 +08:00
parent a7801cccd1
commit b6fe557408

View File

@ -51,11 +51,32 @@ 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() {
ga(GA_EventName.GameInspector);
if (config.value.autoHide) {
showBtns.value = false;
}
picking.value = true;
if (typeof cc === "undefined") {
testInspector();
} else {
const event = new CustomEvent(DocumentEvent.GameInspectorBegan);
document.dispatchEvent(event);
}
}
const listArray = ref<ListItem[]>([ const listArray = ref<ListItem[]>([
{ {
icon: `${rnd.icon} ani_shop_cart`, icon: `${rnd.icon} ani_shop_cart`,
@ -112,20 +133,10 @@ export default defineComponent({
}, },
{ {
icon: "icon_target", icon: "icon_target",
txt: "Inspect Game", txt: "Inspect Game (esc)",
visible: true, visible: true,
click: () => { click: () => {
ga(GA_EventName.GameInspector); doInspector();
if (config.value.autoHide) {
showBtns.value = false;
}
picking.value = true;
if (typeof cc === "undefined") {
testInspector();
} else {
const event = new CustomEvent(DocumentEvent.GameInspectorBegan);
document.dispatchEvent(event);
}
}, },
contextmenu: (event: MouseEvent) => { contextmenu: (event: MouseEvent) => {
const arr = [ const arr = [
@ -200,7 +211,8 @@ export default defineComponent({
} }
function updateAssistantTop(top: number) { function updateAssistantTop(top: number) {
const root = toRaw(rootEl.value) as HTMLDivElement; // @ts-ignore
const root = toRaw(rootEl.value) as HTMLDivElement | null;
if (!root) { if (!root) {
return; return;
} }
@ -277,7 +289,8 @@ export default defineComponent({
}, 500); }, 500);
}, },
onMouseDown(event: MouseEvent) { onMouseDown(event: MouseEvent) {
const root = toRaw(rootEl.value) as HTMLDivElement; // @ts-ignore
const root = toRaw(rootEl.value) as HTMLDivElement | null;
if (!root) { if (!root) {
return; return;
} }