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; @property(Sprite) usdt: 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(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(); this.usdt.node.active = true; } //cash else { path += "ui/shop/cash/"; const price = shopData.getOriginalPriceById(this.goodId); this.price.string = "₹‌" + price.toString(); this.usdt.node.active = false; } path += this.goodId; ResManager.I.changeResourceSpriteFrame(this.icon, path); } async onClickThis() { this.baseView.purchaseGood( this.goodId, this.baseView.getDefaultNetworkType() ); } }