const TagType = { HOT: 0, KINIFE: 100, // 匕首 HANDGUN: 200, // 手枪 SHOTGUN: 300, // 散弹枪 RIFLE: 400, // 步枪 PRINTING: 500, // 印花 LSTA: 600, // 轻机枪 GLOVE: 700, // 手套 OTHER: 99999, }; cc.Class({ extends: cc.Component, editor: { menu: 'Shop/ShopMain' }, properties: { goldNumText: cc.Label, shopView: cc.Node, itemPrefab: cc.Prefab, hotToggle: cc.Toggle, }, onLoad() { this.initData(); this.initUI(); }, initData() { this.goods = {}; let itemConfig = G.CfgMgr.resItemConfig.table; for (let config of itemConfig) { if (!config.inShop) { continue; } let itemname = config.name; let cost = config.price ? config.price : 0; let surface = config.surface; let surfaceConfig = G.CfgMgr.resItemSurfaceConfig.getByMainKey(surface); let surfaceStr = ""; if (surfaceConfig) { surfaceStr = surfaceConfig.name; } surface = surfaceStr == "" ? 0 : surface; let quality = config.quality; let model = config.model; let itemData = { name: itemname, cost: cost, surface: surface, surfaceStr: surfaceStr, quality: quality, model: model, itemConfig: config, cb: this.shopItemOnClicked } let tagType = TagType.OTHER; for (var temp in TagType) { if (TagType[temp] == config.type) { tagType = TagType[temp]; break; } } if (!this.goods[tagType]) { this.goods[tagType] = []; } this.goods[tagType].push(itemData); if (config.hot) { if (!this.goods[TagType.HOT]) { this.goods[TagType.HOT] = []; } this.goods[TagType.HOT].push(itemData); } } }, initUI() { let goldNum = G.BagMgr.getItemNumById(JMC.ITEM_ID.GOLD); this.goldNumText.string = goldNum; this.hotToggle.isChecked = true; this.showShopViewByTag(TagType.HOT); }, showShopViewByTag(tag) { let list = this.goods[tag]; this.shopView.removeAllChildren(); if (!list || list.length == 0) return; for (let i = 0; i < list.length; i++) { let data = list[i]; let itemNode = cc.instantiate(this.itemPrefab); let shopItemCtr = itemNode.getComponent('ShopItem'); shopItemCtr.reloadData(data); this.shopView.addChild(itemNode); } }, typeChooseToggleOnClicked(toggleData, eventKey) { this.showShopViewByTag(eventKey); }, shopItemOnClicked(data) { G.AppUtils.getSceneCtrl().showAlert( 'edt_prefab/Shop/ShopItemAlert', data ); } });