123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- 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();
- 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);
- 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);
- }));
- },
- 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 = `<color=#fe4e00>签约奖励</c><br/><br/><img src='skill_click_coin'/><color=#540904>每次点击产出金币提升200%</c><br/><img src='userInfo_rate_coin'/><color=#540904>所有房间产出金币提升200%</c>`;
- 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;
- 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.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}
- */
- if (starId == 10 || starId == 19) {
- this.walkAnimation = sd.animations.filter(item => item.name.indexOf('walk2') != -1).map(animation => animation.name) || [];
- } else {
- this.walkAnimation = sd.animations.filter(item => item.name.indexOf('stand') != -1).map(animation => animation.name) || [];
- }
- }
- 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),
- });
|