import { _decorator, Component, Label, math, Node, randomRange, Sprite, UITransform, View, } from "cc"; import { Config18x } from "db://assets/Scripts/Main/Config/Config18x"; import ResManager from "db://assets/Scripts/Main/Manager/ResManager"; import { ViewManager } from "db://assets/Scripts/Main/Manager/ViewManager"; import { GButton } from "db://assets/Scripts/Main/Common/GButton"; import { GirlDetailPanel } from "../ui/panels/GirlDetailPanel"; import proto from "db://assets/Scripts/proto/proto.pb.js"; import { DataManager, DataId } from "../data/DataManager"; import { GirlData } from "../data/GirlData"; const { ccclass, property } = _decorator; @ccclass("DetailImageItem") export class DetailImageItem extends Component { @property(Sprite) img: Sprite; @property(Node) question: Node; @property(Sprite) video: Sprite; @property(Node) priceFrame: Node; @property(Label) videoPrice: Label; base: GirlDetailPanel; url: string; isImage: boolean; uitransform: UITransform; category: number; girlId: number; resId: number; type: proto.cs.EnmResType; test_resID: Node; onLoad() { GButton.BandClick(this.node, this.onClickThis, this); this.uitransform = this.node.getComponent(UITransform); } isVisible: boolean; onClickThis() { let data = { url: this.url, isImg: this.isImage, closeFunc: () => { this.base.setVideEnable(true); }, }; // 数据 const girlData = DataManager.I.getDataById(DataId.Girl); // 是否可见,不可见代表需要解锁 if (this.isVisible) { if (this.url) { ViewManager.I.openBundlesView("ShowPanel", data); this.base.setVideEnable(false); } } else { ViewManager.I.openBundlesView("PopupGirlDetailPanel", { category: this.category, resId: this.resId, girlId: this.girlId, base: this, type: this.type, }); } // if (!this.isImage) { // //判断是否已经解锁此资源 // } else { // if (this.url) { // ViewManager.I.openBundlesView("ShowPanel", data); // this.base.setVideEnable(false); // } // } } scaleToFillItem() { if (!this.img || !this.img.spriteFrame) return; // 延迟一帧确保UI布局完成 this.doScaleToFill(); } doScaleToFill() { if (!this.img || !this.img.spriteFrame) return; if (!this.uitransform) this.uitransform = this.node.getComponent(UITransform); const itemSize = this.uitransform.contentSize; const imageSize = this.img.spriteFrame.originalSize; if ( itemSize.width === 0 || itemSize.height === 0 || imageSize.width === 0 || imageSize.height === 0 ) { return; } const scaleX = itemSize.width / imageSize.width; const scaleY = itemSize.height / imageSize.height; const scale = Math.max(scaleX, scaleY); // 设置Sprite的sizeMode为CUSTOM,允许自定义大小 this.img.sizeMode = Sprite.SizeMode.CUSTOM; // 获取图片节点的UITransform并设置大小 const imgTransform = this.img.node.getComponent(UITransform); if (imgTransform) { imgTransform.setContentSize( imageSize.width * scale, imageSize.height * scale ); } } refresh( base: GirlDetailPanel, type: proto.cs.EnmResType, category: number, id: number, resId: number ) { this.base = base; this.type = type; this.category = category; this.girlId = id; this.resId = resId; this.question.active = true; // 显示问号,表示加载中 this.test_resID = this.node.getChildByName("resID"); this.test_resID.getComponent(Label).string = this.girlId.toString() + this.resId; const girlData = DataManager.I.getDataById(DataId.Girl); let imgPath = ""; this.video.enabled = type === proto.cs.EnmResType.ERT_Video; this.priceFrame.active = type === proto.cs.EnmResType.ERT_Video; let price = 0; // 是否可见,不可见代表需要解锁 if (this.type === proto.cs.EnmResType.ERT_Image) { // 图片 this.isVisible = girlData.isGirlPhotoVisible( this.category.toString(), this.girlId, this.resId ); } else if (this.type === proto.cs.EnmResType.ERT_Video) { // 视频 this.isVisible = girlData.isGirlVideoVisible( this.category.toString(), this.girlId, this.resId ); } if (type === proto.cs.EnmResType.ERT_Image) { // 图片 price = girlData.getGrilPhotoOriginalPrice( this.category.toString(), this.girlId, this.resId ); this.url = girlData.getGrilPhotoPic( this.category.toString(), this.girlId, this.resId ); this.isImage = true; } else if (type === proto.cs.EnmResType.ERT_Video) { // 视频 price = girlData.getGrilVideoOriginalPrice( this.category.toString(), this.girlId, this.resId ); this.isImage = false; this.url = girlData.getGrilVideoPath( this.category.toString(), this.girlId, this.resId ); } if (this.isVisible) { imgPath = this.url + "_thumbnail"; } else { imgPath = this.url + "_thumbnail_blur"; } this.priceFrame.active = price > 0; this.videoPrice.string = price.toString(); ResManager.I.changeBundleSpriteFrame(this.img, imgPath, "Girls", () => { this.question.active = false; // 图片加载成功后隐藏问号 this.scaleToFillItem(); }); } refreshVideoBuy(success: boolean) { if (success) { const imgPath = this.url + "_thumbnail"; ResManager.I.changeBundleSpriteFrame(this.img, imgPath, "Girls", () => { this.question.active = false; // 图片加载成功后隐藏问号 this.scaleToFillItem(); }); } } }