mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-04-20 08:58:41 +00:00
鼠标右键取消Inspect,鼠标移动过程实时hover游戏节点,增加pick top的功能,优化小助手的点击折叠
This commit is contained in:
parent
fb0516506e
commit
3798d96b67
@ -79,6 +79,10 @@ export enum GA_EventName {
|
|||||||
Inspector = "Inspector",
|
Inspector = "Inspector",
|
||||||
EngineVersion = "engine_version",
|
EngineVersion = "engine_version",
|
||||||
AppVersion = "app_version",
|
AppVersion = "app_version",
|
||||||
|
GamePlayer = "game_player",
|
||||||
|
GamePause = "game_pause",
|
||||||
|
GameStep = "game_step",
|
||||||
|
GameInspectorFilter = "game_inspector_filter",
|
||||||
/**
|
/**
|
||||||
* 用户点击store广告链接
|
* 用户点击store广告链接
|
||||||
*/
|
*/
|
||||||
@ -94,7 +98,7 @@ export enum GA_EventName {
|
|||||||
/**
|
/**
|
||||||
* 用户主动使用inspector检查游戏节点
|
* 用户主动使用inspector检查游戏节点
|
||||||
*/
|
*/
|
||||||
DoInspector = "do_inspector",
|
GameInspector = "game_inspector",
|
||||||
}
|
}
|
||||||
export enum GA_Button {
|
export enum GA_Button {
|
||||||
Github = "github",
|
Github = "github",
|
||||||
|
@ -58,7 +58,7 @@ document.addEventListener(DocumentEvent.Inject2Content, (event: CustomEvent) =>
|
|||||||
connect.postMessage(data);
|
connect.postMessage(data);
|
||||||
} else {
|
} else {
|
||||||
debugLog && console.log(...terminal.log(`connect is null`));
|
debugLog && console.log(...terminal.log(`connect is null`));
|
||||||
throw new Error("connect is null");
|
console.log("connect is null");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`invalid data: ${event.detail}`);
|
throw new Error(`invalid data: ${event.detail}`);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<i class="iconfont icon" :class="item.icon" @contextmenu.prevent.stop="item.contextmenu"></i>
|
<i class="iconfont icon" :class="item.icon" @contextmenu.prevent.stop="item.contextmenu"></i>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<i class="iconfont icon_cocos cocos" @mousedown="onMouseDown"></i>
|
<i class="iconfont icon_cocos cocos" @mousedown="onMouseDown" @click="onCocosLogoClick"></i>
|
||||||
</div>
|
</div>
|
||||||
<!-- <Memory></Memory> -->
|
<!-- <Memory></Memory> -->
|
||||||
<CCDialog></CCDialog>
|
<CCDialog></CCDialog>
|
||||||
@ -65,20 +65,22 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: "icon_do_play",
|
icon: "icon_do_play",
|
||||||
click: (event: MouseEvent, item: ListItem) => {},
|
click: (event: MouseEvent, item: ListItem) => {
|
||||||
visible: true,
|
ga(GA_EventName.GamePlayer);
|
||||||
txt: "game play",
|
|
||||||
contextmenu: () => {
|
|
||||||
if (typeof cc !== "undefined") {
|
if (typeof cc !== "undefined") {
|
||||||
cc.game.resume();
|
cc.game.resume();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
visible: true,
|
||||||
|
txt: "game play",
|
||||||
|
contextmenu: () => {},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: "icon_do_pause",
|
icon: "icon_do_pause",
|
||||||
visible: true,
|
visible: true,
|
||||||
txt: "game pause",
|
txt: "game pause",
|
||||||
click: () => {
|
click: () => {
|
||||||
|
ga(GA_EventName.GamePause);
|
||||||
if (typeof cc !== "undefined") {
|
if (typeof cc !== "undefined") {
|
||||||
cc.game.pause();
|
cc.game.pause();
|
||||||
}
|
}
|
||||||
@ -90,6 +92,7 @@ export default defineComponent({
|
|||||||
visible: true,
|
visible: true,
|
||||||
txt: "game step",
|
txt: "game step",
|
||||||
click: () => {
|
click: () => {
|
||||||
|
ga(GA_EventName.GameStep);
|
||||||
if (typeof cc !== "undefined") {
|
if (typeof cc !== "undefined") {
|
||||||
cc.game.step();
|
cc.game.step();
|
||||||
}
|
}
|
||||||
@ -101,10 +104,12 @@ export default defineComponent({
|
|||||||
txt: "Inspect Game",
|
txt: "Inspect Game",
|
||||||
visible: true,
|
visible: true,
|
||||||
click: () => {
|
click: () => {
|
||||||
ga(GA_EventName.DoInspector);
|
ga(GA_EventName.GameInspector);
|
||||||
showBtns.value = false;
|
if (config.value.autoHide) {
|
||||||
|
showBtns.value = false;
|
||||||
|
}
|
||||||
picking.value = true;
|
picking.value = true;
|
||||||
if (false) {
|
if (typeof cc === "undefined") {
|
||||||
testInspector();
|
testInspector();
|
||||||
} else {
|
} else {
|
||||||
const event = new CustomEvent(DocumentEvent.GameInspectorBegan);
|
const event = new CustomEvent(DocumentEvent.GameInspectorBegan);
|
||||||
@ -133,10 +138,19 @@ export default defineComponent({
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
ccui.menu.showMenuByMouseEvent(event, [
|
ccui.menu.showMenuByMouseEvent(event, [
|
||||||
|
{
|
||||||
|
name: "Pick Top",
|
||||||
|
selected: config.value.pickTop,
|
||||||
|
callback: (menu: IUiMenuItem) => {
|
||||||
|
config.value.pickTop = !config.value.pickTop;
|
||||||
|
appStore().save();
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "Filter Enabled",
|
name: "Filter Enabled",
|
||||||
selected: inspectTarget.enabled,
|
selected: inspectTarget.enabled,
|
||||||
callback: (menu: IUiMenuItem) => {
|
callback: (menu: IUiMenuItem) => {
|
||||||
|
ga(GA_EventName.GameInspectorFilter);
|
||||||
inspectTarget.enabled = !inspectTarget.enabled;
|
inspectTarget.enabled = !inspectTarget.enabled;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -206,6 +220,9 @@ export default defineComponent({
|
|||||||
clearTimeout(autoHideTimer);
|
clearTimeout(autoHideTimer);
|
||||||
showBtns.value = true;
|
showBtns.value = true;
|
||||||
},
|
},
|
||||||
|
onCocosLogoClick() {
|
||||||
|
showBtns.value = !showBtns.value;
|
||||||
|
},
|
||||||
onContextMenuRoot(event: MouseEvent) {
|
onContextMenuRoot(event: MouseEvent) {
|
||||||
const arr: IUiMenuItem[] = [
|
const arr: IUiMenuItem[] = [
|
||||||
{
|
{
|
||||||
@ -264,19 +281,36 @@ export default defineComponent({
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="less">
|
<style scoped lang="less">
|
||||||
|
@x: 1px;
|
||||||
|
@r: 8deg;
|
||||||
@keyframes color-change {
|
@keyframes color-change {
|
||||||
0% {
|
0% {
|
||||||
color: #f00;
|
color: #f00;
|
||||||
|
transform: rotate(0) translateX(0px);
|
||||||
|
}
|
||||||
|
20% {
|
||||||
|
transform: rotate(-@r) translateX(-@x);
|
||||||
|
}
|
||||||
|
40% {
|
||||||
|
transform: rotate(@r) translateX(@x);
|
||||||
}
|
}
|
||||||
50% {
|
50% {
|
||||||
color: #0f0;
|
color: #0f0;
|
||||||
}
|
}
|
||||||
|
60% {
|
||||||
|
transform: rotate(-@r) translateX(-@x);
|
||||||
|
}
|
||||||
|
80% {
|
||||||
|
transform: rotate(@r) translateX(@x);
|
||||||
|
}
|
||||||
100% {
|
100% {
|
||||||
color: #f00;
|
color: #f00;
|
||||||
|
transform: rotate(0) translateX(0px);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.ad {
|
.ad {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
|
box-shadow: 0px 0px 6px 1px rgb(255, 255, 255);
|
||||||
//z-index: 99999;
|
//z-index: 99999;
|
||||||
top: 0px;
|
top: 0px;
|
||||||
right: 0px;
|
right: 0px;
|
||||||
|
@ -11,6 +11,10 @@ export class ConfigData {
|
|||||||
* 是否自动隐藏
|
* 是否自动隐藏
|
||||||
*/
|
*/
|
||||||
autoHide: boolean = true;
|
autoHide: boolean = true;
|
||||||
|
/**
|
||||||
|
* 是否只拾取顶部元素
|
||||||
|
*/
|
||||||
|
pickTop: boolean = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const appStore = defineStore("app", () => {
|
export const appStore = defineStore("app", () => {
|
||||||
@ -22,6 +26,7 @@ export const appStore = defineStore("app", () => {
|
|||||||
const data = profile.load(`${pluginConfig.manifest.name}-assistant.json`) as ConfigData;
|
const data = profile.load(`${pluginConfig.manifest.name}-assistant.json`) as ConfigData;
|
||||||
config.value.autoHide = data.autoHide;
|
config.value.autoHide = data.autoHide;
|
||||||
config.value.pos = data.pos;
|
config.value.pos = data.pos;
|
||||||
|
config.value.pickTop = data.pickTop;
|
||||||
},
|
},
|
||||||
save() {
|
save() {
|
||||||
const cfg = toRaw(config.value);
|
const cfg = toRaw(config.value);
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
import ccui from "@xuyanfeng/cc-ui";
|
import ccui from "@xuyanfeng/cc-ui";
|
||||||
import { IUiMenuItem } from "@xuyanfeng/cc-ui/types/cc-menu/const";
|
import { IUiMenuItem } from "@xuyanfeng/cc-ui/types/cc-menu/const";
|
||||||
|
import { throttle } from "lodash";
|
||||||
|
import { toRaw } from "vue";
|
||||||
import { Msg } from "../../../core/types";
|
import { Msg } from "../../../core/types";
|
||||||
import { DocumentEvent } from "../../const";
|
import { DocumentEvent } from "../../const";
|
||||||
|
import { appStore } from "../../inject-view/store";
|
||||||
import { Inspector } from "../inspector";
|
import { Inspector } from "../inspector";
|
||||||
import { DrawOptions, HintAdapter, RectPoints } from "./adapter";
|
import { DrawOptions, HintAdapter, RectPoints } from "./adapter";
|
||||||
import { HintV2 } from "./hint-v2";
|
import { HintV2 } from "./hint-v2";
|
||||||
@ -33,22 +36,42 @@ export class Hint {
|
|||||||
|
|
||||||
const cursor = el.style.cursor;
|
const cursor = el.style.cursor;
|
||||||
el.style.cursor = "zoom-in";
|
el.style.cursor = "zoom-in";
|
||||||
const test = (event: MouseEvent) => {
|
|
||||||
|
const mousedown = (event: MouseEvent) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
el.removeEventListener("mousedown", test, true);
|
el.removeEventListener("mousedown", mousedown, true);
|
||||||
|
el.removeEventListener("mousemove", mousemove, true);
|
||||||
el.style.cursor = cursor;
|
el.style.cursor = cursor;
|
||||||
const e = new CustomEvent(DocumentEvent.GameInspectorEnd);
|
const e = new CustomEvent(DocumentEvent.GameInspectorEnd);
|
||||||
document.dispatchEvent(e);
|
document.dispatchEvent(e);
|
||||||
this.updateHint(event, el);
|
|
||||||
|
if (event.button === 0) {
|
||||||
|
// 左键拾取
|
||||||
|
this.updateHintDown(event, el);
|
||||||
|
} else {
|
||||||
|
this.updateHitMoveThrottle.cancel();
|
||||||
|
// 其他按键取消
|
||||||
|
this.cleanHover();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
el.addEventListener("mousedown", test, true);
|
const mousemove = (event: MouseEvent) => {
|
||||||
|
this.updateHitMoveThrottle(event, el);
|
||||||
|
};
|
||||||
|
|
||||||
|
el.addEventListener("mousemove", mousemove, true);
|
||||||
|
el.addEventListener("mousedown", mousedown, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
private updateHitMoveThrottle = throttle(this.updateHintMove, 300);
|
||||||
private updateHint(event: MouseEvent, canvas: HTMLCanvasElement) {
|
private updateHintMove(event: MouseEvent, canvas: HTMLCanvasElement) {
|
||||||
this.cleanHover();
|
const nodes = this.getMouseNodes(event, canvas);
|
||||||
this.cleanSelected();
|
if (nodes.length) {
|
||||||
|
const node = nodes[0];
|
||||||
|
this.setHover(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private getMouseNodes(event: MouseEvent, canvas: HTMLCanvasElement): Array<any> {
|
||||||
this.inspector.updateTreeInfo(false);
|
this.inspector.updateTreeInfo(false);
|
||||||
const { x, y } = this.hintAdapter.convertMousePos(event, canvas);
|
const { x, y } = this.hintAdapter.convertMousePos(event, canvas);
|
||||||
const nodes = [];
|
const nodes = [];
|
||||||
@ -58,13 +81,20 @@ export class Hint {
|
|||||||
nodes.push(node);
|
nodes.push(node);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
nodes.reverse();
|
||||||
if (nodes.length === 1) {
|
return nodes;
|
||||||
|
}
|
||||||
|
private updateHintDown(event: MouseEvent, canvas: HTMLCanvasElement) {
|
||||||
|
this.cleanHover();
|
||||||
|
this.cleanSelected();
|
||||||
|
const nodes = this.getMouseNodes(event, canvas);
|
||||||
|
const pickTop = toRaw(appStore().config.pickTop);
|
||||||
|
if (nodes.length === 1 || pickTop) {
|
||||||
const item = nodes[0];
|
const item = nodes[0];
|
||||||
|
this.cleanHover();
|
||||||
this.setSelected(item);
|
this.setSelected(item);
|
||||||
this.sendInspectNodeMsg(item);
|
this.sendInspectNodeMsg(item);
|
||||||
} else {
|
} else {
|
||||||
nodes.reverse();
|
|
||||||
const menu = nodes.map((item) => {
|
const menu = nodes.map((item) => {
|
||||||
const path = this.getPath(item);
|
const path = this.getPath(item);
|
||||||
return {
|
return {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user