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

58 lines
1.5 KiB
TypeScript

import { _decorator, Component, Label, Node, Sprite } from "cc";
import { PurchasePanel } from "../ui/panels/PurchasePanel";
import { PurchaseConfig } from "../../schema/schema";
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);
}
public refresh(type: number, goodId: number) {
this.goodId = goodId;
this.show(type);
}
public show(type: number) {
const shopData = DataManager.I.getDataById<ShopData>(DataId.Shop);
const count = shopData.getCountById(this.goodId);
this.count.string = count.toString();
const price = shopData.getOriginalPriceById(this.goodId);
this.price.string = price.toString();
let path = "";
if (type == 1) {
// web3币
path += "ui/shop/coin/";
} //cash
else {
path += "ui/shop/cash/";
}
path += this.goodId;
ResManager.I.changeResourceSpriteFrame(this.icon, path);
}
async onClickThis() {
this.baseView.purchaseGood(this.goodId,this.baseView.getDefaultNetworkType());
}
}