var gameConfig = require('gameConfig'); var NetManage = require('NetManage'); const { UIBase } = require('../UIBase'); cc.Class({ extends: UIBase, properties: { lb_name: { default: null, type: cc.Label, }, lb_des: { default: null, type: cc.Label, }, lb_gold1: { default: null, type: cc.Label, }, lb_gold2: { default: null, type: cc.Label, }, lb_diamond1: { default: null, type: cc.Label, }, lb_diamond2: { default: null, type: cc.Label, }, spine_hero: { default: null, type: sp.Skeleton, }, }, // LIFE-CYCLE CALLBACKS: onLoad() { cc.Notifier.on('ongetHeroList', this, this.onclose.bind(this)); cc.Notifier.on('ongetSkinList', this, this.onclose.bind(this)); }, onDestroy() { cc.Notifier.off('ongetHeroList', this); cc.Notifier.off('ongetSkinList', this); }, init(v) { this.itemid = v; var itemcfg = gameConfig.all_ItemConfig[v]; var skinres; if (itemcfg.type == cc.playerData.itemtype.hero) { var skinid = cc.playerData.getskinarrbyId(v)[0]; skinres = gameConfig.all_ItemConfig[skinid].skinid; } else { skinres = itemcfg.skinid; } cc.loader.loadRes( 'spine/heropic/pic_hero' + skinres, sp.SkeletonData, function (err, sp) { this.spine_hero.skeletonData = sp; this.spine_hero._updateSkeletonData(); this.spine_hero.setAnimation(0, 'animation', true); }.bind(this) ); this.lb_diamond1.string = itemcfg.diamond; this.lb_gold1.string = itemcfg.gold; var zk = cc.playerData.getDiscount(v); this.lb_gold2.node.active = false; this.lb_diamond2.node.active = false; this.lb_name.string = itemcfg.name; this.lb_des.string = itemcfg.des; if (zk[0] < 100) { this.lb_gold2.node.active = true; this.lb_gold2.string = Math.floor((itemcfg.gold * zk[0]) / 100); } if (zk[1] < 100) { this.lb_diamond2.node.active = true; this.lb_diamond2.string = Math.floor( (itemcfg.diamond * zk[1]) / 100 ); } }, onclose() { this.node.destroy(); }, onbuygold() { NetManage.buyGood(this.itemid, 10001, 100, 1); }, onbuydiamond() { NetManage.buyGood(this.itemid, 10002, 100, 1); }, // update (dt) {}, });