2025-01-18 20:08:14 +08:00
|
|
|
<template>
|
2025-01-25 14:12:33 +08:00
|
|
|
<div class="ad" ref="rootEl" v-show="!picking" @contextmenu.prevent="onContextMenuRoot" @mouseleave="onMouseLeaveRoot" @mouseenter="onMouseEnterCocosLogo">
|
2025-01-23 12:26:55 +08:00
|
|
|
<div class="title">
|
|
|
|
<div class="btns" v-show="showBtns">
|
2025-01-25 14:12:33 +08:00
|
|
|
<div v-for="(item, index) in listArray" :key="index" class="list" @click="item.click($event, item)" :title="item.txt" v-show="item.visible">
|
|
|
|
<i class="iconfont icon" :class="item.icon" @contextmenu.prevent.stop="item.contextmenu"></i>
|
2025-01-22 21:39:23 +08:00
|
|
|
</div>
|
2025-01-18 20:08:14 +08:00
|
|
|
</div>
|
2025-01-25 14:12:33 +08:00
|
|
|
<i class="iconfont icon_cocos cocos" @mousedown="onMouseDown"></i>
|
2025-01-18 20:08:14 +08:00
|
|
|
</div>
|
2025-01-23 12:26:55 +08:00
|
|
|
<!-- <Memory></Memory> -->
|
2025-01-23 14:12:07 +08:00
|
|
|
<CCDialog></CCDialog>
|
2025-01-23 17:56:02 +08:00
|
|
|
<CCMenu></CCMenu>
|
2025-01-18 20:08:14 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script lang="ts">
|
2025-01-23 14:12:07 +08:00
|
|
|
import ccui from "@xuyanfeng/cc-ui";
|
2025-01-25 14:12:33 +08:00
|
|
|
import { IUiMenuItem } from "@xuyanfeng/cc-ui/types/cc-menu/const";
|
|
|
|
import { storeToRefs } from "pinia";
|
2025-01-23 12:26:55 +08:00
|
|
|
import { defineComponent, onMounted, ref, toRaw } from "vue";
|
2025-01-23 14:12:07 +08:00
|
|
|
import { GA_EventName } from "../../ga/type";
|
2025-01-23 17:56:02 +08:00
|
|
|
import { DocumentEvent } from "../const";
|
2025-01-25 14:12:33 +08:00
|
|
|
import { inspectTarget } from "../inject/inspect-list";
|
2025-01-23 14:12:07 +08:00
|
|
|
import Ad from "./ad.vue";
|
2025-01-18 20:08:14 +08:00
|
|
|
import Banner from "./banner.vue";
|
2025-01-23 12:26:55 +08:00
|
|
|
import Memory from "./memory.vue";
|
2025-01-25 14:12:33 +08:00
|
|
|
import { appStore } from "./store";
|
2025-01-23 14:12:07 +08:00
|
|
|
import { ga } from "./util";
|
2025-01-25 14:12:33 +08:00
|
|
|
declare const cc: any;
|
2025-01-23 17:56:02 +08:00
|
|
|
const { CCDialog, CCMenu } = ccui.components;
|
2025-01-23 12:26:55 +08:00
|
|
|
interface ListItem {
|
|
|
|
icon: string;
|
|
|
|
txt: string;
|
2025-01-25 14:12:33 +08:00
|
|
|
visible: boolean;
|
|
|
|
/**
|
|
|
|
* 点击回调
|
|
|
|
*/
|
|
|
|
click: (event: MouseEvent, item: ListItem) => void;
|
|
|
|
contextmenu: (event: MouseEvent) => void;
|
2025-01-23 12:26:55 +08:00
|
|
|
}
|
2025-01-18 20:08:14 +08:00
|
|
|
export default defineComponent({
|
|
|
|
name: "ad",
|
2025-01-23 17:56:02 +08:00
|
|
|
components: { CCDialog, Banner, Memory, CCMenu },
|
2025-01-18 20:08:14 +08:00
|
|
|
setup() {
|
2025-01-25 14:12:33 +08:00
|
|
|
const store = appStore();
|
|
|
|
store.init();
|
|
|
|
const { config } = storeToRefs(appStore());
|
2025-01-23 12:26:55 +08:00
|
|
|
const listArray = ref<ListItem[]>([
|
|
|
|
{
|
2025-01-23 14:12:07 +08:00
|
|
|
icon: "icon_shop_cart ani_shop_cart",
|
|
|
|
txt: "Recommended Plugins",
|
2025-01-25 14:12:33 +08:00
|
|
|
contextmenu: () => {},
|
|
|
|
visible: true,
|
|
|
|
click: () => {
|
2025-01-23 14:12:07 +08:00
|
|
|
ccui.dialog.showDialog({
|
|
|
|
title: "Recommended Plugins",
|
|
|
|
comp: Ad,
|
|
|
|
width: 310,
|
2025-01-23 17:56:02 +08:00
|
|
|
height: 500,
|
2025-01-23 14:12:07 +08:00
|
|
|
closeCB: () => {
|
|
|
|
ga(GA_EventName.CloseAd);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
2025-01-23 12:26:55 +08:00
|
|
|
},
|
2025-01-25 14:12:33 +08:00
|
|
|
{
|
|
|
|
icon: "icon_do_play",
|
|
|
|
click: (event: MouseEvent, item: ListItem) => {},
|
|
|
|
visible: true,
|
|
|
|
txt: "game play",
|
|
|
|
contextmenu: () => {
|
|
|
|
if (typeof cc !== "undefined") {
|
|
|
|
cc.game.resume();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: "icon_do_pause",
|
|
|
|
visible: true,
|
|
|
|
txt: "game pause",
|
|
|
|
click: () => {
|
|
|
|
if (typeof cc !== "undefined") {
|
|
|
|
cc.game.pause();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
contextmenu: () => {},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: "icon_do_step",
|
|
|
|
visible: true,
|
|
|
|
txt: "game step",
|
|
|
|
click: () => {
|
|
|
|
if (typeof cc !== "undefined") {
|
|
|
|
cc.game.step();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
contextmenu: () => {},
|
|
|
|
},
|
2025-01-23 12:26:55 +08:00
|
|
|
{
|
|
|
|
icon: "icon_target",
|
|
|
|
txt: "Inspect Game",
|
2025-01-25 14:12:33 +08:00
|
|
|
visible: true,
|
|
|
|
click: () => {
|
2025-01-23 14:12:07 +08:00
|
|
|
ga(GA_EventName.DoInspector);
|
2025-01-23 12:26:55 +08:00
|
|
|
showBtns.value = false;
|
|
|
|
picking.value = true;
|
2025-01-23 17:56:02 +08:00
|
|
|
if (false) {
|
|
|
|
testInspector();
|
|
|
|
} else {
|
|
|
|
const event = new CustomEvent(DocumentEvent.GameInspectorBegan);
|
|
|
|
document.dispatchEvent(event);
|
|
|
|
}
|
2025-01-23 12:26:55 +08:00
|
|
|
},
|
2025-01-25 14:12:33 +08:00
|
|
|
contextmenu: (event: MouseEvent) => {
|
|
|
|
const arr = [
|
|
|
|
{ name: "Inspect Label", type: typeof cc !== "undefined" ? cc.Label : "cc.Label" }, //
|
|
|
|
{ name: "Inspect Sprite", type: typeof cc !== "undefined" ? cc.Sprite : "cc.Sprite" },
|
|
|
|
{ name: "Inspect Button", type: typeof cc !== "undefined" ? cc.Button : "cc.Button" },
|
|
|
|
{ name: "Inspect RichText", type: typeof cc !== "undefined" ? cc.RichText : "cc.RichText" },
|
|
|
|
];
|
|
|
|
const compMenu: IUiMenuItem[] = arr.map((item) => {
|
|
|
|
return {
|
|
|
|
name: item.name,
|
|
|
|
enabled: inspectTarget.enabled,
|
|
|
|
selected: inspectTarget.isContainInspectType(item.type),
|
|
|
|
callback: (menu: IUiMenuItem) => {
|
|
|
|
if (menu.selected) {
|
|
|
|
inspectTarget.removeInspectType(item.type);
|
|
|
|
} else {
|
|
|
|
inspectTarget.addInspectType(item.type);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
ccui.menu.showMenuByMouseEvent(event, [
|
|
|
|
{
|
|
|
|
name: "Filter Enabled",
|
|
|
|
selected: inspectTarget.enabled,
|
|
|
|
callback: (menu: IUiMenuItem) => {
|
|
|
|
inspectTarget.enabled = !inspectTarget.enabled;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
...compMenu,
|
|
|
|
]);
|
|
|
|
},
|
2025-01-23 12:26:55 +08:00
|
|
|
},
|
|
|
|
]);
|
2025-01-23 17:56:02 +08:00
|
|
|
document.addEventListener(DocumentEvent.GameInspectorEnd, () => {
|
|
|
|
picking.value = false;
|
|
|
|
});
|
|
|
|
function testInspector() {
|
|
|
|
const cursor = document.body.style.cursor;
|
|
|
|
document.body.style.cursor = "zoom-in";
|
|
|
|
function test(event: MouseEvent) {
|
|
|
|
document.removeEventListener("mousedown", test, true);
|
|
|
|
document.body.style.cursor = cursor;
|
|
|
|
picking.value = false;
|
|
|
|
}
|
|
|
|
document.addEventListener("mousedown", test, true);
|
|
|
|
}
|
2025-01-23 12:26:55 +08:00
|
|
|
function recoverAssistantTop() {
|
2025-01-25 14:12:33 +08:00
|
|
|
const top = toRaw(config.value.pos);
|
2025-01-23 12:26:55 +08:00
|
|
|
updateAssistantTop(top);
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateAssistantTop(top: number) {
|
|
|
|
const root = toRaw(rootEl.value) as HTMLDivElement;
|
|
|
|
if (!root) {
|
2025-01-18 20:08:14 +08:00
|
|
|
return;
|
|
|
|
}
|
2025-01-23 12:26:55 +08:00
|
|
|
if (top < 0) {
|
|
|
|
top = 0;
|
2025-01-18 20:08:14 +08:00
|
|
|
}
|
2025-01-23 12:26:55 +08:00
|
|
|
const maxTop = document.body.clientHeight - root.clientHeight;
|
|
|
|
if (top > maxTop) {
|
|
|
|
top = maxTop;
|
2025-01-18 20:08:14 +08:00
|
|
|
}
|
2025-01-23 12:26:55 +08:00
|
|
|
root.style.top = `${top}px`;
|
2025-01-25 14:12:33 +08:00
|
|
|
config.value.pos = top;
|
|
|
|
appStore().save();
|
2025-01-19 10:30:37 +08:00
|
|
|
}
|
2025-01-23 12:26:55 +08:00
|
|
|
onMounted(async () => {
|
|
|
|
recoverAssistantTop();
|
|
|
|
window.addEventListener("resize", () => {
|
|
|
|
const root = toRaw(rootEl.value) as HTMLDivElement;
|
|
|
|
if (!root) {
|
|
|
|
return;
|
2025-01-22 10:46:38 +08:00
|
|
|
}
|
2025-01-23 12:26:55 +08:00
|
|
|
updateAssistantTop(root.offsetTop);
|
|
|
|
});
|
|
|
|
return;
|
2025-01-18 20:08:14 +08:00
|
|
|
});
|
2025-01-23 12:26:55 +08:00
|
|
|
|
2025-01-22 21:39:23 +08:00
|
|
|
const picking = ref(false);
|
|
|
|
const rootEl = ref<HTMLDivElement>(null);
|
2025-01-23 12:26:55 +08:00
|
|
|
const showBtns = ref(true);
|
|
|
|
let autoHideTimer = null;
|
2025-01-25 14:12:33 +08:00
|
|
|
let autoHide = toRaw(config.value.autoHide);
|
2025-01-23 12:26:55 +08:00
|
|
|
let isDraging = false;
|
2025-01-18 20:08:14 +08:00
|
|
|
return {
|
2025-01-23 12:26:55 +08:00
|
|
|
showBtns,
|
|
|
|
listArray,
|
2025-01-22 21:39:23 +08:00
|
|
|
rootEl,
|
|
|
|
picking,
|
2025-01-23 12:26:55 +08:00
|
|
|
onMouseEnterCocosLogo() {
|
|
|
|
clearTimeout(autoHideTimer);
|
|
|
|
showBtns.value = true;
|
2025-01-18 20:08:14 +08:00
|
|
|
},
|
2025-01-25 14:12:33 +08:00
|
|
|
onContextMenuRoot(event: MouseEvent) {
|
|
|
|
const arr: IUiMenuItem[] = [
|
|
|
|
{
|
|
|
|
name: "auto hide",
|
|
|
|
selected: autoHide,
|
|
|
|
callback: () => {
|
|
|
|
autoHide = !autoHide;
|
|
|
|
config.value.autoHide = autoHide;
|
|
|
|
appStore().save();
|
|
|
|
ga(GA_EventName.MouseMenu, "auto hide");
|
|
|
|
if (!autoHide) {
|
|
|
|
clearTimeout(autoHideTimer);
|
|
|
|
showBtns.value = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
ccui.menu.showMenuByMouseEvent(event, arr);
|
|
|
|
},
|
2025-01-23 12:26:55 +08:00
|
|
|
onMouseLeaveRoot(event: MouseEvent) {
|
|
|
|
if (isDraging) {
|
2025-01-18 20:08:14 +08:00
|
|
|
return;
|
|
|
|
}
|
2025-01-25 14:12:33 +08:00
|
|
|
if (!autoHide) {
|
|
|
|
return;
|
|
|
|
}
|
2025-01-23 12:26:55 +08:00
|
|
|
autoHideTimer = setTimeout(() => {
|
|
|
|
showBtns.value = false;
|
|
|
|
}, 500);
|
2025-01-18 20:08:14 +08:00
|
|
|
},
|
2025-01-22 21:39:23 +08:00
|
|
|
onMouseDown(event: MouseEvent) {
|
|
|
|
const root = toRaw(rootEl.value) as HTMLDivElement;
|
|
|
|
if (!root) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const startY = event.pageY;
|
|
|
|
const startTop = root.offsetTop;
|
|
|
|
function onMouseMove(e: MouseEvent) {
|
2025-01-23 12:26:55 +08:00
|
|
|
isDraging = true;
|
2025-01-22 21:39:23 +08:00
|
|
|
const dy = e.pageY - startY;
|
2025-01-23 12:26:55 +08:00
|
|
|
const top = startTop + dy;
|
|
|
|
updateAssistantTop(top);
|
2025-01-22 21:39:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function onMouseUp(e: MouseEvent) {
|
2025-01-23 12:26:55 +08:00
|
|
|
isDraging = false;
|
2025-01-22 21:39:23 +08:00
|
|
|
document.removeEventListener("mousemove", onMouseMove, true);
|
|
|
|
document.removeEventListener("mouseup", onMouseUp, true);
|
|
|
|
}
|
|
|
|
document.addEventListener("mousemove", onMouseMove, true);
|
|
|
|
document.addEventListener("mouseup", onMouseUp, true);
|
|
|
|
},
|
2025-01-18 20:08:14 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="less">
|
2025-01-23 14:12:07 +08:00
|
|
|
@keyframes color-change {
|
|
|
|
0% {
|
|
|
|
color: #f00;
|
|
|
|
}
|
|
|
|
50% {
|
|
|
|
color: #0f0;
|
|
|
|
}
|
|
|
|
100% {
|
|
|
|
color: #f00;
|
|
|
|
}
|
|
|
|
}
|
2025-01-18 20:08:14 +08:00
|
|
|
.ad {
|
2025-01-22 21:39:23 +08:00
|
|
|
position: fixed;
|
2025-01-25 14:12:33 +08:00
|
|
|
//z-index: 99999;
|
2025-01-22 21:39:23 +08:00
|
|
|
top: 0px;
|
|
|
|
right: 0px;
|
2025-01-18 20:08:14 +08:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
2025-01-22 21:39:23 +08:00
|
|
|
background-color: white;
|
|
|
|
border-top-left-radius: 5px;
|
|
|
|
border-bottom-left-radius: 5px;
|
|
|
|
// overflow: hidden;
|
|
|
|
.title {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
align-items: center;
|
|
|
|
font-size: 14px;
|
|
|
|
user-select: none;
|
|
|
|
background-color: rgb(0, 0, 0);
|
|
|
|
border: 1px solid black;
|
|
|
|
color: white;
|
2025-01-23 12:26:55 +08:00
|
|
|
padding: 2px 4px;
|
2025-01-22 21:39:23 +08:00
|
|
|
border-top-left-radius: 5px;
|
2025-01-23 12:26:55 +08:00
|
|
|
border-bottom-left-radius: 5px;
|
2025-01-18 20:08:14 +08:00
|
|
|
|
2025-01-23 12:26:55 +08:00
|
|
|
.btns {
|
|
|
|
color: white;
|
2025-01-18 20:08:14 +08:00
|
|
|
display: flex;
|
2025-01-23 12:26:55 +08:00
|
|
|
flex-direction: row;
|
|
|
|
.list {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
align-items: center;
|
|
|
|
color: white;
|
2025-01-19 13:22:26 +08:00
|
|
|
user-select: none;
|
2025-01-18 20:08:14 +08:00
|
|
|
&:hover {
|
2025-01-23 12:26:55 +08:00
|
|
|
color: rgb(101, 163, 249);
|
2025-01-18 20:08:14 +08:00
|
|
|
}
|
|
|
|
&:active {
|
2025-01-23 12:26:55 +08:00
|
|
|
color: rgb(255, 187, 0);
|
|
|
|
}
|
|
|
|
.icon {
|
|
|
|
font-size: 20px;
|
2025-01-18 20:08:14 +08:00
|
|
|
}
|
2025-01-23 14:12:07 +08:00
|
|
|
.ani_shop_cart {
|
|
|
|
animation: color-change 2s infinite;
|
|
|
|
}
|
2025-01-18 20:08:14 +08:00
|
|
|
}
|
|
|
|
}
|
2025-01-23 12:26:55 +08:00
|
|
|
.cocos {
|
|
|
|
cursor: move;
|
|
|
|
font-size: 20px;
|
|
|
|
color: rgb(85, 192, 224);
|
2025-01-18 20:08:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|