cc.Class({ extends: cc.Component, properties: { questDaily: { tooltip: '每日任务容器', default: null, type: cc.Node }, questMain: { tooltip: '主线任务容器', default: null, type: cc.Node }, tab: [cc.Node], tabFade: cc.Node, tabIndex: { tooltip: '默认显示的Tab', default: 0, type: cc.Integer } }, onLoad () { this._initDaily() this._initMain() this._initTab() }, start () { let space = 50; let upAction = cc.moveTo(0.25, cc.v2(0, space)); let downAction = cc.moveBy(0.1, cc.v2(0, -space)); let bouncesActionArray = [upAction, downAction]; this.node.runAction(cc.sequence(bouncesActionArray)); }, /** * 初始化Tab */ _initTab () { for(let i = 0; i < this.tab.length; i++) { this.tab[i] = this.tab[i].getComponent('QuestTab') this.tab[i].init(this) } this.tabFade.zIndex = 20 this.tabList = [this.questMain, this.questDaily] this.handleTab(null, this.tabIndex) }, /** * 初始化每日任务 */ _initDaily () { this.questDaily = this.questDaily.getComponent('QuestDaily') this.questDaily.init(this) }, /** * 初始化主线任务 */ _initMain () { this.questMain = this.questMain.getComponent('QuestMain') this.questMain.init(this) }, /** * Tab切换 * @param {number} tabIndex [1: 每日任务, 0: 完成目标] */ handleTab(event, tabIndex) { this.tab.forEach((item, index) => { if(tabIndex == index) { item.show() item.node.zIndex = 30 this.tabList[index].node.active = true } else { item.hide() item.node.zIndex = 10 this.tabList[index].node.active = false } }) }, close() { this.node.destroy(); } });