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 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"; 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; private desc: Label; 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.desc = this._nodeTab.content.getComponent(Label); this.uitransform = this._nodeTab.Img_Frame.getComponent(UITransform); this.img = this._nodeTab.img.getComponent(Sprite); let descText = LanguageUtils.getText("popupgirldetailpanel.content"); 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 path = url + "_thumbnail_blur"; ResManager.I.changeBundleSpriteFrame(this.img, path, "Girls", () => { this.scaleToFillItem(); }); this.desc.string = descText.replace("{price}", this.priceLabel.string); this.registerListener(); } registerListener() { GButton.BandClick(this._nodeTab.BuyBtn, this.buyCharacter, this); GButton.BandClick(this._nodeTab.CloseBtn, this.Close, this); } Close() { this.close(); } async buyCharacter() { // 购买id为girlId的女生 console.log(this.girlId + "---" + this.resId); // 请求解锁 const reqData = { girlId: this.girlId, resId: this.resId, type: this.type, }; let res = await GirlService.I.reqUnlockGirlRes(reqData); console.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(); } this.close(); } else { TipsPanel.show("Insufficient balance, need to purchase"); } } 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(scaleY, 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 ); } } }