import ResMgr from "../base/ResMgr"; import SoundMgr from "../base/SoundMgr"; var baseLayer = require('BaseLayer'); cc.Class({ extends: baseLayer, properties: { atlasVIP: cc.SpriteAtlas, //vip图集 labVV: cc.Label, labV: cc.Label, labZai: cc.Label, labNextV: cc.Label, roleNode: cc.Node, daoNode: cc.Node, dao2Node: cc.Node, spCurV: cc.Sprite, spNextV: cc.Sprite, spBar: cc.Sprite, labBar: cc.Label, labDes: cc.Label, labCoin: cc.Label, labY: cc.Label, pageView:cc.PageView, pageConNodes: [cc.Node], }, // LIFE-CYCLE CALLBACKS: // onLoad () {}, start () { this.daoSpId = [121, 122, 123, 124, 125, 126, 127, 128, 129, 130]; this.selectVIP = 6; //当前选中的VIP this.labZai.string = `${78}元`; this.labNextV.string = `VIP${8}`; this.spCurV.spriteFrame = this.atlasVIP.getSpriteFrame('VIP2'); this.spNextV.spriteFrame = this.atlasVIP.getSpriteFrame('VIP3'); this.spBar.fillRange = 0.3; this.labBar.string = '12/21'; this.labDes.string = `VIP${21}限购礼包`; this.labCoin.string = `212万`; this.labY.string = `${121}元购买`; this.initData(); }, initData(){ this.onSetVIPIndex(); this.setPage(this.pageConNodes[1], this.selectVIP); this.pageView.scrollToPage(1, 0); this.pageView.node.on('scroll-ended', this.onScrollToPageEnd, this); }, onSetVIPIndex(){ this.labVV.string = `VIP${this.selectVIP}`; this.labV.string = `VIP${this.selectVIP}特权`; //人物和刀 for(let i=0; i < this.roleNode.childrenCount; i++){ this.roleNode.children[i].active = false; } this.roleNode.children[this.selectVIP-1].active = true; for(let i=0; i < this.daoNode.childrenCount; i++){ ResMgr.loadTexture(`texture/resIcon/${this.daoSpId[this.selectVIP-1]}`, (spFrame)=>{ this.daoNode.children[i].getComponent(cc.Sprite).spriteFrame = spFrame; this.dao2Node.children[i].getComponent(cc.Sprite).spriteFrame = spFrame; }); } }, setPage(node, vipLv){ if(vipLv < 1 || vipLv > 10) return; let layout = node.getChildByName('layout'); for(let i=0; i < layout.childrenCount; i++){ if(i == 0){ layout.children[i].getChildByName('sp').getComponent(cc.Sprite).spriteFrame = this.atlasVIP.getSpriteFrame(`VIPdi${vipLv}`); } if(i == 2){ ResMgr.loadTexture(`texture/resIcon/${this.daoSpId[vipLv-1]}`, (spFrame)=>{ layout.children[i].getChildByName('sp').getComponent(cc.Sprite).spriteFrame = spFrame; }); } if(i == 5){ layout.children[i].getChildByName('lab').getComponent(cc.Label).string = `暴击获得${vipLv}倍`; } } }, onScrollToPageEnd(){ this.setPage(this.pageConNodes[1], this.selectVIP); this.scheduleOnce(()=>{ this.pageView.scrollToPage(1, 0); console.log('xxx: ', this.pageView.getCurrentPageIndex()); }, 0); }, onClickLeft(){ SoundMgr.playClick(); if(this.selectVIP == 1) return; this.selectVIP -= 1; this.onSetVIPIndex(); this.setPage(this.pageConNodes[0], this.selectVIP); this.scheduleOnce(()=>{ this.pageView.scrollToPage(0, 1); }, 0); }, onClickRight(){ SoundMgr.playClick(); if(this.selectVIP == 10) return; this.selectVIP += 1; this.onSetVIPIndex(); this.setPage(this.pageConNodes[2], this.selectVIP); this.scheduleOnce(()=>{ this.pageView.scrollToPage(2, 1); }, 0); }, onClickShop(){ // SoundMgr.playClick(); this.onClose(); cc.find('Canvas').getComponent('HallScene').onClickShop(); }, onClickBuy(){ SoundMgr.playClick(); }, onClose(){ this.pageView.node.off('scroll-ended', this.onScrollToPageEnd, this); this._super(); }, });