import { _decorator, Component, Node, Label, UITransform, Sprite, tween, Vec3, } from "cc"; import li_BaseView from "../../../Main/Common/li_BaseView"; import { GButton } from "../../../Main/Common/GButton"; import Utils from "../../../Main/Common/Utils"; import { DetailImageItem } from "../../uiitems/DetailImageItem"; import { GirlService } from "db://assets/Scripts/chat18x/network/services/GirlService"; import { DataManager, DataId } from "../../data/DataManager"; import { GirlData } from "../../data/GirlData"; import { WalletData } from "../../data/WalletData"; import { EnvData } from "../../data/EnvData"; import proto from "db://assets/Scripts/proto/proto.pb.js"; import LanguageUtils from "../../../Main/Common/LanguageUtils"; import { ImagePopup } from "../components/ImagePopup"; import { TipsPanel } from "./TipsPanel"; import ResManager from "../../../Main/Manager/ResManager"; import { logger } from "db://assets/Scripts/Main/Common/Logger"; import { NavigationManager } from "../../manager/NavigationManager"; const { ccclass, property } = _decorator; @ccclass("PopupGirlDetailPanel") export class PopupGirlDetailPanel extends li_BaseView { private _nodeTab: any = {}; private priceLabel: Label; private category: number; private girlId: number; private resId: number; private type: proto.cs.EnmResType; private base: DetailImageItem | ImagePopup; img: Sprite; uitransform: UITransform; openUIDataCT(data) { this.category = data.category; this.resId = data.resId; this.girlId = data.girlId; this.base = data.base; this.type = data.type; } onLoadCT() { this.node.scale = Vec3.ZERO; tween(this.node) .to(0.2, { scale: Vec3.ONE }, { easing: "quadOut" }) .start(); Utils.parseNode(this.node, this._nodeTab); this.uitransform = this._nodeTab.Img_Frame.getComponent(UITransform); this.img = this._nodeTab.img.getComponent(Sprite); this.refreshCoinNum(); const girlData = DataManager.I.getDataById(DataId.Girl); // 价格 this.priceLabel = this._nodeTab.Price.getComponent(Label); let url = ""; if (this.type === proto.cs.EnmResType.ERT_Image) { // 图片 this.priceLabel.string = girlData .getGrilPhotoOriginalPrice( this.category.toString(), this.girlId, this.resId ) .toString(); url = girlData.getGrilPhotoPic( this.category.toString(), this.girlId, this.resId ); } else if (this.type === proto.cs.EnmResType.ERT_Video) { // 视频 this.priceLabel.string = girlData .getGrilVideoOriginalPrice( this.category.toString(), this.girlId, this.resId ) .toString(); url = girlData.getGrilVideoPath( this.category.toString(), this.girlId, this.resId ); } // 加载远程资源 const envData = DataManager.I.getDataById(DataId.Env); const path = url + "_thumbnail_blur"; let newPath = envData.cdn + "/" + "Girls/" + path + ".jpg"; ResManager.I.changeRemoteSpriteFrame(this.img, newPath, () => { this.scaleToFillItem(); }); this.registerListener(); } registerListener() { GButton.BandClick(this._nodeTab.BuyBtn, this.buyAsset, this); GButton.BandClick(this._nodeTab.CloseBtn, this.Close, this); } Close() { NavigationManager.Instance.closePopupPanel(this.node); } async buyAsset() { // 购买id为girlId的女生 logger.log(this.girlId + "---" + this.resId); // 请求解锁 const reqData = { girlId: this.girlId, resId: this.resId, type: this.type, }; let res = await GirlService.I.reqUnlockGirlRes(reqData); logger.log("请求解锁资源响应数据:", res); if (res && res.code === proto.cs.EnmRetCode.SUCCESS) { const resData = res.data; // 保存数据 const girlData = DataManager.I.getDataById(DataId.Girl); if (this.type === proto.cs.EnmResType.ERT_Image) { // 图片 girlData.unlockImage(this.category.toString(), this.girlId, this.resId); } else if (this.type === proto.cs.EnmResType.ERT_Video) { // 视频 girlData.unlockVideo(this.category.toString(), this.girlId, this.resId); } const walletData = DataManager.I.getDataById(DataId.Wallet); walletData.balance = Number(resData.balance); walletData.vipExpire = Number(resData.vipExpire); // 刷新界面 if (this.base instanceof DetailImageItem) { this.base.refreshVideoBuy(true); } else { this.base.refreshSelf(); } TipsPanel.show(LanguageUtils.getText("releasepanel.releasesuccess")); } else { NavigationManager.Instance.openPopupPanel("ChargePopPanel"); } this.Close(); } // 刷新余额 private refreshCoinNum() { const walletData = DataManager.I.getDataById(DataId.Wallet); const balance = walletData.getOriginalBalance(); } 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, scaleX); // 设置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 ); } } }