Files
18xchat/assets/Scripts/chat18x/ui/panels/PopupGirlDetailPanel.ts
T

195 lines
6.0 KiB
TypeScript
Raw Normal View History

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