2025-09-18 14:06:53 +08:00
|
|
|
import { _decorator, Component, Label, Node, Sprite } from "cc";
|
2025-08-15 13:55:26 +08:00
|
|
|
import { PurchasePanel } from "../ui/panels/PurchasePanel";
|
2025-09-10 11:37:30 +08:00
|
|
|
import { DataManager, DataId } from "../data/DataManager";
|
|
|
|
|
import { ShopData } from "../data/ShopData";
|
2025-09-10 15:26:56 +08:00
|
|
|
import { GButton } from "db://assets/Scripts/Main/Common/GButton";
|
2025-09-18 14:06:53 +08:00
|
|
|
import ResManager from "../../Main/Manager/ResManager";
|
2025-09-10 15:26:56 +08:00
|
|
|
|
2025-08-15 13:55:26 +08:00
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
|
|
|
|
@ccclass("PurchasePanelItem")
|
|
|
|
|
export class PurchasePanelItem extends Component {
|
|
|
|
|
@property(Label)
|
|
|
|
|
count: Label;
|
|
|
|
|
@property(Label)
|
|
|
|
|
price: Label;
|
|
|
|
|
|
2025-09-18 14:06:53 +08:00
|
|
|
@property(Sprite)
|
|
|
|
|
icon: Sprite;
|
|
|
|
|
|
2025-08-15 13:55:26 +08:00
|
|
|
baseView: PurchasePanel;
|
2025-09-10 11:37:30 +08:00
|
|
|
goodId: number;
|
2025-09-18 14:06:53 +08:00
|
|
|
public init(base: PurchasePanel) {
|
2025-08-15 13:55:26 +08:00
|
|
|
this.baseView = base;
|
2025-09-10 15:26:56 +08:00
|
|
|
|
|
|
|
|
GButton.BandClick(this.node, this.onClickThis, this);
|
2025-08-15 13:55:26 +08:00
|
|
|
}
|
|
|
|
|
|
2025-09-22 14:13:18 +08:00
|
|
|
// 0:cash 1:web3
|
2025-09-18 22:27:02 +08:00
|
|
|
public refresh(type: number, goodId: number) {
|
2025-09-18 14:06:53 +08:00
|
|
|
this.goodId = goodId;
|
2025-09-18 22:27:02 +08:00
|
|
|
this.show(type);
|
2025-09-18 14:06:53 +08:00
|
|
|
}
|
|
|
|
|
|
2025-09-22 14:13:18 +08:00
|
|
|
// 0:cash 1:web3
|
2025-09-18 22:27:02 +08:00
|
|
|
public show(type: number) {
|
2025-09-10 11:37:30 +08:00
|
|
|
const shopData = DataManager.I.getDataById<ShopData>(DataId.Shop);
|
|
|
|
|
const count = shopData.getCountById(this.goodId);
|
|
|
|
|
this.count.string = count.toString();
|
2025-09-18 14:06:53 +08:00
|
|
|
|
|
|
|
|
let path = "";
|
2025-09-18 22:27:02 +08:00
|
|
|
if (type == 1) {
|
2025-09-18 14:06:53 +08:00
|
|
|
// web3币
|
|
|
|
|
path += "ui/shop/coin/";
|
2025-09-22 14:13:18 +08:00
|
|
|
const price = shopData.getOriginalUsdPriceById(this.goodId);
|
|
|
|
|
this.price.string = price.toString();
|
2025-09-18 14:06:53 +08:00
|
|
|
} //cash
|
|
|
|
|
else {
|
|
|
|
|
path += "ui/shop/cash/";
|
2025-09-22 14:13:18 +08:00
|
|
|
const price = shopData.getOriginalPriceById(this.goodId);
|
|
|
|
|
this.price.string = "₹" + price.toString();
|
2025-09-18 14:06:53 +08:00
|
|
|
}
|
|
|
|
|
path += this.goodId;
|
|
|
|
|
|
|
|
|
|
ResManager.I.changeResourceSpriteFrame(this.icon, path);
|
2025-08-15 13:55:26 +08:00
|
|
|
}
|
|
|
|
|
|
2025-09-10 15:26:56 +08:00
|
|
|
async onClickThis() {
|
2025-09-21 21:10:41 +08:00
|
|
|
this.baseView.purchaseGood(
|
|
|
|
|
this.goodId,
|
|
|
|
|
this.baseView.getDefaultNetworkType()
|
|
|
|
|
);
|
2025-08-15 13:55:26 +08:00
|
|
|
}
|
|
|
|
|
}
|