123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- 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
- },
- popupBgNode: cc.Node
- },
- onLoad () {
- if (Global.winSize.height <= 1000) {
- this.popupBgNode.height = 820;
- }
- this.isFirst = true;
- this.giftMap = ['diamond', 'coin', 'ticket'];
- this.tabList = [{
- wrap: this.questMain,
- init: () => {
- this._initMain();
- },
- }, {
- wrap: this.questDaily,
- init: () => {
- this._initDaily();
- }
- }];
- 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');
- if (i == 0) {
- this.tab[i].init(this, true);
- } else {
- this.tab[i].init(this, false);
- }
- }
- 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();
- }
- });
|