2025-01-18 20:08:14 +08:00
|
|
|
<template>
|
2025-01-23 17:56:02 +08:00
|
|
|
<div class="ad" ref="rootEl" v-show="!picking" @mouseleave="onMouseLeaveRoot" @mousedown="onMouseDown" @mouseenter="onMouseEnterCocosLogo">
|
2025-01-23 12:26:55 +08:00
|
|
|
<div class="title">
|
|
|
|
<div class="btns" v-show="showBtns">
|
|
|
|
<div v-for="(item, index) in listArray" :key="index" class="list" @click="item.cb" :title="item.txt">
|
|
|
|
<i class="iconfont icon" :class="item.icon"></i>
|
2025-01-22 21:39:23 +08:00
|
|
|
</div>
|
2025-01-18 20:08:14 +08:00
|
|
|
</div>
|
2025-01-23 17:56:02 +08:00
|
|
|
<i class="iconfont icon_cocos cocos"></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-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-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-23 14:12:07 +08:00
|
|
|
import { ga } from "./util";
|
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;
|
|
|
|
cb: (event: MouseEvent) => void;
|
|
|
|
}
|
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-23 12:26:55 +08:00
|
|
|
const keyAssistant = "assistant";
|
|
|
|
|
|
|
|
const listArray = ref<ListItem[]>([
|
|
|
|
{
|
2025-01-23 14:12:07 +08:00
|
|
|
icon: "icon_shop_cart ani_shop_cart",
|
|
|
|
txt: "Recommended Plugins",
|
|
|
|
cb: () => {
|
|
|
|
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
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: "icon_target",
|
|
|
|
txt: "Inspect Game",
|
|
|
|
cb: () => {
|
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-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() {
|
|
|
|
const top = Number(localStorage.getItem(keyAssistant) || "0");
|
|
|
|
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`;
|
|
|
|
localStorage.setItem(keyAssistant, top.toString());
|
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;
|
|
|
|
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-23 12:26:55 +08:00
|
|
|
onMouseLeaveRoot(event: MouseEvent) {
|
|
|
|
if (isDraging) {
|
2025-01-18 20:08:14 +08:00
|
|
|
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;
|
|
|
|
z-index: 99999;
|
|
|
|
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>
|