cb/assets/shop/script/shop.ts
2025-07-01 19:39:23 +08:00

63 lines
2.1 KiB
TypeScript

import List from "../../Script/module/RankList/List";
import NumberToImage from "../../Script/NumberToImage";
const { ccclass, property } = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
//商店界面
@property(cc.Node)
shop: cc.Node = null;
//商品列表
@property(cc.Node)
itemList: cc.Node = null;
// onLoad () {}
//金币数量
@property(cc.Node)
coin: cc.Node = null;
start() {
this.openShop();
}
//打开商店界面
openShop() {
// 商品数据数组
const products = [
{ product_id: "gold_pack_1", name: "金币包1", price: 600, title: "3x2六档金币" },
{ product_id: "gold_pack_2", name: "金币包2", price: 3600, title: "" },
{ product_id: "gold_pack_3", name: "金币包3", price: 6800, title: "" },
{ product_id: "gold_pack_4", name: "金币包4", price: 12800, title: "" },
{ product_id: "gold_pack_5", name: "金币包5", price: 32800, title: "" },
{ product_id: "gold_pack_6", name: "金币包6", price: 64800, title: "" },
];
for (let i = 1; i <= 6 && i < this.itemList.children.length; i++) {
const spriteComp = this.itemList.children[i].children[0].getComponent(cc.Sprite);
const price = this.itemList.children[i].children[1];
const title = this.itemList.children[i].children[2];
const product = products[i - 1];
if (spriteComp && product) {
// TODO: 根据 product_id 或 name 设置 spriteComp.spriteFrame
}
if (price && product) {
NumberToImage.numberToImageNodes(product.price / 100, 25, 20, "cost_", price, false)
}
if (title && product) {
NumberToImage.numberToImageNodes(product.price / 100, 40, 25, "scoin_", title, false)
}
}
NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.coin, 30, 15, "coin_", this.coin, true);
}
//关闭商店界面
closeShop() {
//销毁预制体
this.shop.destroy();
}
// update (dt) {}
}