import { _decorator, Component, Node, Sprite, Vec3, tween, UITransform, path, view, } from "cc"; import ResManager from "db://assets/Scripts/Main/Manager/ResManager"; import Utils from "db://assets/Scripts/Main/Common/Utils"; import { ViewManager } from "db://assets/Scripts/Main/Manager/ViewManager"; import { DataId, DataManager } from "../../data/DataManager"; import { GirlData } from "../../data/GirlData"; import { EnvData } from "../../data/EnvData"; import proto from "db://assets/Scripts/proto/proto.pb.js"; import { GButton } from "../../../Main/Common/GButton"; import { NavigationManager } from "../../manager/NavigationManager"; const { ccclass, property } = _decorator; @ccclass("ImagePopup") export class ImagePopup extends Component { @property(Sprite) image: Sprite; private isAnimating: boolean = false; start() { this.node.setPosition(this.getOffscreenPosition()); GButton.BandClick(this.image.node, this.openImage, this); this.node.active = false; } onDestroy() { //this.image.node.off(Node.EventType.TOUCH_START,this.openImage); } categoryId: string; girlId: number; resId: number; /** * 获取屏幕外位置(完全在左侧屏幕外) */ private getOffscreenPosition(): Vec3 { const visibleSize = view.getVisibleSize(); const x = -visibleSize.width; // 完全在屏幕左侧外 const y = visibleSize.height * 0.33; // 屏幕高度的1/3处 return new Vec3(x, y, 0); } /** * 获取屏幕内位置(左侧边缘内侧) */ private getOnscreenPosition(): Vec3 { const visibleSize = view.getVisibleSize(); const x = -visibleSize.width/2 + 100; // 从左边缘向内100像素 const y = visibleSize.height * 0.33; // 屏幕高度的1/3处 return new Vec3(x, y, 0); } //url: string; refresh(categoryId: string, girlId: number, resId: number, clear = false) { this.node.active = true; const girlData = DataManager.I.getDataById(DataId.Girl); this.categoryId = categoryId; this.girlId = girlId; this.resId = resId; const url = girlData.getGrilPhotoPic(categoryId, girlId, resId); //this.url = path; // 加载远程资源 const envData = DataManager.I.getDataById(DataId.Env); let oldPath = url + (clear ? "" : "_thumbnail_blur"); let suffix = clear ? ".png" : ".jpg"; let newPath = envData.cdn + "/" + "Girls/" + oldPath + suffix; ResManager.I.changeRemoteSpriteFrame( this.image, newPath, () => { let sizeTran = this.image.node.parent.getComponent(UITransform); Utils.adjustBgPixelRatioToSize( sizeTran.contentSize, this.image.node, 2 ); this.popUp(); } ); } refreshSelf() { this.refresh(this.categoryId, this.girlId, this.resId, true); } openImage() { const girlData = DataManager.I.getDataById(DataId.Girl); const isUnlock = girlData.isImageUnlock( this.categoryId, this.girlId, this.resId ); if (isUnlock) { let data = { url: girlData.getGrilPhotoPic(this.categoryId, this.girlId, this.resId), isImg: true, }; NavigationManager.Instance.openPopupPanel("ShowPanel", data); } else { NavigationManager.Instance.openPopupPanel("PopupGirlDetailPanel", { category: this.categoryId, resId: this.resId, girlId: this.girlId, base: this, type: proto.cs.EnmResType.ERT_Image, }); } // } popUp() { if (this.isAnimating) return; this.isAnimating = true; tween(this.node) .to(0.5, { position: this.getOnscreenPosition() }, { easing: "backOut" }) .call(() => { this.scheduleOnce(() => { this.popDown(); }, 3); }) .start(); } popDown() { tween(this.node) .to(0.5, { position: this.getOffscreenPosition() }, { easing: "backIn" }) .call(() => { this.isAnimating = false; }) .start(); } }