const GameModule = require("../utils/GameModule"); const AlertManager = require('../utils/AlertManager'); const TapTapTool = require("../utils/TapTapTool"); 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 }, mask: { tooltip: '遮罩层', default: null, type: cc.Node }, wrap: { tooltip: '弹窗载体', default: null, type: cc.Node }, }, onLoad () { this.isFirst = true; this.giftMap = ['diamond', 'coin', 'ticket']; this.tabList = [{ wrap: this.questMain, init: () => { this._initMain(); }, }, { wrap: this.questDaily, init: () => { this._initDaily(); } }]; this.mask.zIndex = 10; this.wrap.zIndex = 11; this._initTab(); GameModule.homeGuide.on('Fire_state32', this.selectDailyTask, this); }, /** * 初始化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.handleTab(null, this.tabIndex); }, /** * 初始化每日任务 */ _initDaily () { if(!this.initDailyDone) { this.initDailyDone = true; this.questDaily = this.questDaily.getComponent('QuestDaily'); this.questDaily.init(this); } }, /** * 初始化主线任务 */ _initMain () { if(!this.initMainDone) { this.initMainDone = true; 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].wrap.active = true; this.tabList[index].init.apply(this); if (this.isFirst) { this.isFirst = false } else { GameModule.audioMng.playClickButton(); } } else { item.hide(); item.node.zIndex = 10; this.tabList[index].wrap.active = false; } }); }, selectDailyTask() { let tabIndex = 1; this.tab.forEach((item, index) => { if(tabIndex == index) { item.show(); item.node.zIndex = 30; this.tabList[index].wrap.active = true; this.tabList[index].init.apply(this); } else { item.hide(); item.node.zIndex = 10; this.tabList[index].wrap.active = false; } }) }, /** * 更新全局用户数据 * @param {number} coin 金币 * @param {number} diamond 钻石 * @param {number} ticket 艺人券 */ updateUserInfo (coin, diamond, ticket) { GameModule.userInfo.updateUserRes({ gold: coin, diamond: diamond, ticket: ticket }) }, /** * 显示领取活跃度奖励动画 * @param {object} giftObj {ticket: 艺人券, diamond: 钻石, coin: 金币} */ showActGift (giftObj) { let giftMap = { diamond: { showText: '钻石', count: giftObj.diamond }, coin: { showText: '金币', count: giftObj.coin }, ticket: { showText: '艺人券', count: giftObj.ticket }, } let showText, showType; for(let i in giftMap) { if(giftMap[i].count > 0) { showText = `${giftMap[i].showText} x ${giftMap[i].count}`; showType = i; } } AlertManager.showActGiftAlert(showType, showText); }, /** * 显示领取奖励动画 * @param {cc.SpriteFrame} showFrame 图片素材 * @param {string} showText 显示文案 */ showMainGift (showFrame, showText) { // GameModule.audioMng.playGift() AlertManager.showActGiftAlert('coin', showText, showFrame); }, close() { GameModule.audioMng.playClickButton(); GameModule.homeGuide.getComponent('HomeGuide').handleGuideState33(); this.node.destroy(); } });