const SkillApi = require('../net/SkillApi'); // const DWTool = require("../utils/DWTool"); const GameModule = require("../utils/GameModule"); const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey; // const TapTapTool = require("../utils/TapTapTool"); cc.Class({ extends: cc.Component, properties: { content: cc.Node, topSkillItems:{ tooltip: '技能顶部的四个实时技能', default: [], type: [cc.Node] }, skillScrollView: cc.Node, mask: cc.Node, skillMask: cc.Prefab, }, // LIFE-CYCLE CALLBACKS: onLoad () { this.node.height = Global.winSize.height; if (Global.winSize.height <= 1000) { this.content.height = 800; } this.setUpNotification(); this.skillScrollView.active = false; this.handelGuide(); // if (Global.isCheck) { // this.topSkillItems[3].active = false; // } }, start () { this.loadData(); }, onDestroy() { GameEvent.off("skillAlert_done", this); GameEvent.off('skill_1_unlocked', this); GameEvent.off('Fire_state17', this); GameEvent.off('skill3_use_begain',this); GameEvent.off(GameNotificationKey.GameShowNotificationKey, this); }, loadData() { this._isLoadData = true; this.getAllSkills().then((respondData) => { console.log(respondData); /// 防止重新加载数据 if (this._respondData !== undefined) { return; } this._respondData = respondData; /// 初始化这个scrollView Global.rcdSkillLevel = respondData.skills2[2].skillLevel; this.skillScrollView.active = true; this.initTopSkillItem(respondData.skills1); this.schedule(this.timeAction, 1); this.skillScrollView.getComponent('SkillScrollView').init(respondData); this._isloadData = true; }).catch(({code, msg}) => { this._isloadData = false; console.log(code, msg); }); }, //// 初始化通知相关 setUpNotification() { /// 点击tabbar导致skill隐藏的通知 GameEvent.on("skillAlert_done", this, () => { this.hidden(); }); ///通过 最后一个新手引导 GameModule.homeGuide.on('Fire_state17', (event) => { this.hidden(); GameEvent.fire(GameNotificationKey.TabbarClickCat); }, this); this.mask.on(cc.Node.EventType.TOUCH_END, (event) => { this.hidden(); GameEvent.fire(GameNotificationKey.TabbarClickCat); }, this); GameEvent.on('skill3_use_begain', this, this.handelSkill1Unlocked); GameEvent.on(GameNotificationKey.GameShowNotificationKey, this, this.updateTopSkillData); }, updateTopSkillData() { this.getAllSkills().then((respondData) => { console.log(respondData); /// 初始化这个scrollView this.initTopSkillItem(respondData.skills1); let arr = respondData.skills1.concat(respondData.skills2); //// 说明第一个技能是重新进来的 arr[0].isShow = true; /// 说明第二个技能是重新进来刷新的 arr[2].isShow = true; GameModule.skill.skills = arr; GameModule.skill.getAllSkillInfo(); }).catch(({code, msg}) => { console.log(code, msg); }); }, /// 解锁第一个技能的时候需要的动画效果 handelSkill1Unlocked() { let SkillMask = cc.instantiate(this.skillMask).getComponent('SkillMask'); SkillMask.show(); }, /// 显示 单例显示 show() { this.node.setPosition(0, 0); this.skillScrollView.getComponent('SkillScrollView').updateUI(); let scrollView = this.skillScrollView.getComponent(cc.ScrollView); scrollView.vertical = true; this.handelGuide(); //// 如果网络请求没有请求下来数据 if (this._isloadData === false) { this.loadData(); } }, ///直接隐藏 hidden() { this.node.setPosition(10000, -100000); GameModule.homeGuide.getComponent('HomeGuide').changeGuideTask1315(false); }, //// 点击之后隐藏 hidenAction() { GameModule.audioMng.playClickButton(); this.hidden(); GameEvent.fire(GameNotificationKey.TabbarClickCat); }, /// 处理新手引导的显示 handelGuide() { let homeGuide = GameModule.homeGuide.getComponent('HomeGuide'); for (let i = 12; i <= 17; ++ i) { let state = 'state' + i; if (!homeGuide.isPassGuideState(state)) { homeGuide.handleState(state); if (i === 13 || i === 15) { homeGuide.changeGuideTask1315(true); } let scrollView = this.skillScrollView.getComponent(cc.ScrollView); scrollView.vertical = false; break; } } }, /// 初始化顶部的四个实时技能 initTopSkillItem(timeSkill) { var isAllLocked = true; for(let i = 0; i < 3; ++i) { let skillItemScript = this.topSkillItems[i].getComponent('SkillTopItem'); let timeSkillData = timeSkill[i]; if (timeSkillData.isHave == 1) { isAllLocked = false; } skillItemScript.init(timeSkillData); } let upDateItemScript = this.topSkillItems[3].getComponent('SkillTopItem'); upDateItemScript.initUpdateSkill(isAllLocked); }, timeAction() { for(let i = 0; i < 4; ++i) { let skillItemScript = this.topSkillItems[i].getComponent('SkillTopItem'); skillItemScript.updateTime(); } }, /// 网络请求 getAllSkills() { return new Promise((resolve, reject) => { // 获取目标用户的建筑 SkillApi.getAllSkills((respondData) => { resolve(respondData); }, (code, msg) => { reject({code, msg}); }); }) }, // update (dt) {}, });