Files
18xchat/assets/Scripts/chat18x/uiitems/PurchasePanelItem.ts
T
2025-09-25 18:11:27 +08:00

64 lines
1.7 KiB
TypeScript

import { _decorator, Component, Label, Node, Sprite } from "cc";
import { PurchasePanel } from "../ui/panels/PurchasePanel";
import { DataManager, DataId } from "../data/DataManager";
import { ShopData } from "../data/ShopData";
import { GButton } from "db://assets/Scripts/Main/Common/GButton";
import ResManager from "../../Main/Manager/ResManager";
const { ccclass, property } = _decorator;
@ccclass("PurchasePanelItem")
export class PurchasePanelItem extends Component {
@property(Label)
count: Label;
@property(Label)
price: Label;
@property(Sprite)
icon: Sprite;
baseView: PurchasePanel;
goodId: number;
public init(base: PurchasePanel) {
this.baseView = base;
GButton.BandClick(this.node, this.onClickThis, this);
}
// 0:cash 1:web3
public refresh(type: number, goodId: number) {
this.goodId = goodId;
this.show(type);
}
// 0:cash 1:web3
public show(type: number) {
const shopData = DataManager.I.getDataById<ShopData>(DataId.Shop);
const count = shopData.getCountById(this.goodId);
this.count.string = count.toString();
let path = "";
if (type == 1) {
// web3币
path += "ui/shop/coin/";
const price = shopData.getOriginalUsdPriceById(this.goodId);
this.price.string = price.toString();
} //cash
else {
path += "ui/shop/cash/";
const price = shopData.getOriginalPriceById(this.goodId);
this.price.string = "₹‌" + price.toString();
}
path += this.goodId;
ResManager.I.changeResourceSpriteFrame(this.icon, path);
}
async onClickThis() {
this.baseView.purchaseGood(
this.goodId,
this.baseView.getDefaultNetworkType()
);
}
}