180 lines
5.8 KiB
TypeScript
180 lines
5.8 KiB
TypeScript
import {
|
|
_decorator,
|
|
Button,
|
|
Component,
|
|
Node,
|
|
Label,
|
|
View,
|
|
Sprite,
|
|
UITransform,
|
|
Vec3,
|
|
tween,
|
|
} from "cc";
|
|
import li_BaseView from "../../../Main/Common/li_BaseView";
|
|
import Utils from "../../../Main/Common/Utils";
|
|
import { GButton } from "../../../Main/Common/GButton";
|
|
import { PopupGirlDetailPanel } from "./PopupGirlDetailPanel";
|
|
import { GirlListItem } from "../../uiitems/GirlListItem";
|
|
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 { ViewManager } from "../../../Main/Manager/ViewManager";
|
|
import { TipsPanel } from "./TipsPanel";
|
|
import ResManager from "../../../Main/Manager/ResManager";
|
|
import { InnerMsgCode } from "../../../Main/Config/InnerMsgCode";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass("GirlListPopupPanel")
|
|
export class GirlListPopupPanel extends li_BaseView {
|
|
private _nodeTab: any = {};
|
|
private priceLabel: Label;
|
|
private category: number;
|
|
private girlId: number;
|
|
|
|
private girlName: Label;
|
|
private girlTag: Label;
|
|
private balanceCount: Label;
|
|
|
|
base: GirlListItem;
|
|
img: Sprite;
|
|
uitransform: UITransform;
|
|
openUIDataCT(data) {
|
|
this.category = data.category;
|
|
this.girlId = data.id;
|
|
this.base = data.base;
|
|
}
|
|
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.img = this._nodeTab.img.getComponent(Sprite);
|
|
this.uitransform = this._nodeTab.Img_Frame.getComponent(UITransform);
|
|
this.girlName = this._nodeTab.Name.getComponent(Label);
|
|
this.girlTag = this._nodeTab.Tag.getComponent(Label);
|
|
this.balanceCount = this._nodeTab.balanceCount.getComponent(Label);
|
|
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
|
// 价格
|
|
this.priceLabel = this._nodeTab.Price.getComponent(Label);
|
|
this.priceLabel.string = girlData
|
|
.getGrilOriginalPrice(this.category.toString(), this.girlId)
|
|
.toString();
|
|
this.registerListener();
|
|
|
|
this.girlName.string = LanguageUtils.getText(
|
|
girlData.getGrilName(this.category.toString(), this.girlId)
|
|
);
|
|
const tagContent = girlData.getGrilTagKey(
|
|
this.category.toString(),
|
|
this.girlId
|
|
);
|
|
|
|
this.girlTag.string = LanguageUtils.getText(tagContent.replace("|", "\n"));
|
|
|
|
const path = girlData.getGrilAvatar(this.category.toString(), this.girlId);
|
|
this.refreshCoinNum();
|
|
//console.log(path);
|
|
// 加载远程资源
|
|
const envData = DataManager.I.getDataById<EnvData>(DataId.Env);
|
|
let newPath = envData.cdn + "/" + "Girls/" + path + ".png";
|
|
ResManager.I.changeRemoteSpriteFrame(this.img, newPath, () => {
|
|
this.scaleToFillItem();
|
|
});
|
|
}
|
|
registerListener() {
|
|
GButton.BandClick(this._nodeTab.BuyBtn, this.buyCharacter, this);
|
|
GButton.BandClick(this._nodeTab.CloseBtn, this.Close, this);
|
|
|
|
Utils.addInnerEL(InnerMsgCode.BalanceChange, this, this.onBalanceChange);
|
|
}
|
|
Close() {
|
|
this.close();
|
|
}
|
|
onDestroy(): void {
|
|
Utils.removeInnerEL(InnerMsgCode.BalanceChange, this, this.onBalanceChange);
|
|
}
|
|
async buyCharacter() {
|
|
// 购买id为girlId的女生
|
|
console.log(this.girlId);
|
|
// 请求解锁
|
|
const reqData = {
|
|
id: this.girlId,
|
|
};
|
|
let res = await GirlService.I.reqUnlockGirl(reqData);
|
|
console.log("请求解锁技师响应数据:", res);
|
|
if (res && res.code === proto.cs.EnmRetCode.SUCCESS) {
|
|
const resData = res.data;
|
|
// 保存数据
|
|
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
|
|
girlData.setIsRelease(this.category.toString(), this.girlId, true);
|
|
const walletData = DataManager.I.getDataById<WalletData>(DataId.Wallet);
|
|
walletData.balance = Number(resData.balance);
|
|
walletData.vipExpire = Number(resData.vipExpire);
|
|
// 刷新界面
|
|
this.base.refreshBuy(true);
|
|
this.close();
|
|
TipsPanel.show("Buy Succeed");
|
|
} else {
|
|
//ViewManager.I.openBundlesView("PurchasePanel");
|
|
this.close();
|
|
TipsPanel.show("Insufficient balance, need to purchase");
|
|
}
|
|
// TipsPanel.show("Insufficient balance, need to purchase");
|
|
}
|
|
|
|
// 刷新余额
|
|
private refreshCoinNum() {
|
|
const walletData = DataManager.I.getDataById<WalletData>(DataId.Wallet);
|
|
const balance = walletData.getOriginalBalance();
|
|
this.balanceCount.string = balance.toString();
|
|
}
|
|
onBalanceChange = () => {
|
|
this.refreshCoinNum();
|
|
};
|
|
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
|
|
);
|
|
}
|
|
}
|
|
}
|