const StarApi = require('../net/StarApi'); const AlertManager = require('../utils/AlertManager'); const ArtistManager = require('../utils/ArtistManager'); const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey; const DWTool = require('../utils/DWTool'); const GameModule = require("../utils/GameModule"); cc.Class({ extends: cc.Component, properties: { content: cc.Node, scrollView: cc.Node, mask: cc.Node, getStarMask: cc.Prefab, /// 图鉴 albumNode: cc.Node, }, // LIFE-CYCLE CALLBACKS: onLoad () { this.node.height = Global.winSize.height; if (Global.winSize.height <= 1000) { this.content.height = 800; } this.scrollView.active = false; this._isShowGetStar = false; this.setUpNotification(); this.handelGuide(); this._isTimeAction = false; if (Global.isCheck) { this.albumNode.active = false; } }, start () { this.loadData(); }, onDestroy() { GameEvent.off("starAlert_done", this); GameEvent.off('Star_Buy_success_Alert', this); GameEvent.off('commAlert_BuyStar_hidden', this); GameEvent.off(GameNotificationKey.RefreshSignArtistList, this); this.mask.off(cc.Node.EventType.TOUCH_END, this); }, loadData() { this._isloadData = true; this.getSignStars().then((respondData) => { /// 防止重新加载数据 if (this._respondData !== undefined) { return; } this._isloadData = true; this._respondData = respondData; this.scrollView.active = true; this.scrollView.getComponent('StarScrollView').init(respondData); }).catch(({code, msg}) => { this._isloadData = false; cc.log(code, msg); }); }, setUpNotification() { this.mask.on(cc.Node.EventType.TOUCH_END, (event) => { this.hidden(); GameEvent.fire(GameNotificationKey.TabbarClickCat); }, this); GameEvent.on("starAlert_done", this, () => { if (this.node != null) { this.hidden(); } }); GameEvent.on('Star_Buy_success_Alert', this, ((starId, starName) => { this.showGetStar(starId, starName); })); GameEvent.on(GameNotificationKey.RefreshSignArtistList, this, () => { this.node.destroy(); Global.starContent = null; }); }, hidden() { // GameModule.audioMng.playClickButton(); // this.node.destroy(); this.node.active = false; let guide = GameModule.homeGuide.getComponent('HomeGuide'); if (guide.curState == 'state29') { guide.hideArrow(); } }, hiddenAction() { GameModule.audioMng.playClickButton(); this.hidden(); GameEvent.fire(GameNotificationKey.TabbarClickCat); }, show() { this.node.active = true; GameEvent.fire('StarItem_updateUI'); //// 如果网络请求没有请求下来数据 if (this._isloadData === false) { this.loadData(); } this.handelGuide(); }, handelGuide() { let homeGuide = GameModule.homeGuide.getComponent('HomeGuide'); this._showGuide = false; if (!homeGuide.isPassGuideState('state29')) { homeGuide.handleState('state29'); //显示箭头 var offsetY = 0; if (cc.view.getVisibleSize().height >= 1624) { offsetY = -140; } else if (cc.view.getVisibleSize().height >= 1500) { offsetY = -80; } homeGuide.showArrow(offsetY); this._showGuide = true; let scrollView = this.scrollView.getComponent(cc.ScrollView); scrollView.vertical = false; } else { GameEvent.off('commAlert_BuyStar_hidden', this); let scrollView = this.scrollView.getComponent(cc.ScrollView); scrollView.vertical = true; } }, /// 网络请求 getSignStars() { return new Promise((resolve, reject) => { StarApi.getSignStars((respondData) => { resolve(respondData); }, (code, msg) => { reject({code, msg}); }); }) }, timeAction() { if (this._isShowDone == false) { this.starSkeletonCompletion(); } }, //// 购买明星骨骼动画完成之后 starSkeletonCompletion() { this._isShowDone = true; let homeGuide = GameModule.homeGuide.getComponent('HomeGuide'); if (this.alertMask.getStarSkeleton != null) { this.alertMask.getStarSkeleton.setAnimation(0, 'run', false); } this.alertMask.node.active = false; this._isShowGetStar = false; GameModule.audioMng.playBgm(); this.alertMask.getStarAudio.pause(); let imageId = 50000 + this._starId; // let path = `./textures/star_handbook/${imageId}`; let desc = `签约奖励

每次点击产出金币提升200%
所有房间产出金币提升200%`; DWTool.loadResPrefab("./prefabs/common/commonAlert") .then((result) => { let alert = cc.instantiate(result); cc.find('Canvas').addChild(alert); alert.getComponent('commAlert').initBuyStar(imageId, desc, `${this._starName}`); if (this._showGuide) { GameEvent.on('commAlert_BuyStar_hidden',this, () => { homeGuide.updateGuideState() homeGuide.handlePass('state29'); homeGuide.handleState('state31'); homeGuide.node.emit(`Fire_state29`); GameEvent.fire(GameNotificationKey.TabbarClickCat); }); } }); }, showGetStar(starId, starName) { this._starName = starName; this._starId = starId; this._isShowDone = false; if (this._isTimeAction) { this.unschedule(this.timeAction, this); } this._isTimeAction = true; this.scheduleOnce(this.timeAction, 6); let homeGuide = GameModule.homeGuide.getComponent('HomeGuide'); homeGuide.hideArrow(); GameModule.audioMng.stopBgm(); if (this.alertMask == undefined) { let maskNode = cc.instantiate(this.getStarMask); this.alertMask = maskNode.getComponent('StarMask'); cc.find('Canvas').addChild(this.alertMask.node); } else { this.alertMask.node.active = true; } this.alertMask.getStarSkeleton.setCompleteListener(() => { this._isTimeAction = false; this.unschedule(this.timeAction, this); if (this._isShowDone === false) { this.starSkeletonCompletion(); } }); this._timeCount = 0; this._isChangeColor = false; this._isShowGetStar = true; this.alertMask.starSkeleton.node.color = cc.color(0, 0, 0, 255); // 根据明星id来加载不同骨骼 this.alertMask.getStarSkeleton.node.active = false; ArtistManager.loadStarSpine(starId) .then((skeletonData) => { this.alertMask.starSkeleton.skeletonData = skeletonData; var sd = skeletonData.getRuntimeData(true); if (sd) { /** * item: Animation {name: "stand1", timelines: Array(113), duration: 2} */ let walkAnimation = sd.animations.filter(item => item.name.indexOf('walk2') != -1).map(animation => animation.name) || []; if (walkAnimation.length === 0) { this.walkAnimation = sd.animations.filter(item => item.name.indexOf('stand') != -1).map(animation => animation.name) || []; } else { this.walkAnimation = walkAnimation; } } this.alertMask.starSkeleton.setAnimation(0, this.walkAnimation[0], true); this.alertMask.getStarSkeleton.node.active = true; }).catch((err) => { console.log(err); }); this.alertMask.getStarAudio.play(); }, update (dt) { if (this._isShowGetStar) { this._timeCount += dt; if (this._timeCount > 1.2 && this._isChangeColor == false) { this.alertMask.starSkeleton.node.color = cc.color(255, 255, 255, 255); GameEvent.fire(GameNotificationKey.PlaySuccessAnimation, true); this._isChangeColor = true; } } }, //显示明星图鉴 handleStarHandbook: _.debounce((event) => { AlertManager.showStarHandbookAlert(); }, 1000, true), });