123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- 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
- );
- }
- });
|