const TaskConst = require( "task_const" ); const TaskEvent = require( "task_event" ); const TaskController = require( "task_controller" ); const RoleController = require( "role_controller" ); const { PlayerAction } = require( "define" ); cc.Class({ extends: cc.Component, properties: { awards:{ default:[], type:[cc.Node] }, score:{ default:null, type:cc.Label }, score_bar:{ default:null, type:cc.ProgressBar }, nodClose: { default:null, type:cc.Node } }, // LIFE-CYCLE CALLBACKS: onLoad () { this.cfg_list = []; this.role_vo = RoleController.getInstance().getRoleVo(); this.box_list = [109, 108, 108, 110]; //注册事件 if (this.role_vo != null) { if (this.role_assets_event == null) { this.role_assets_event = this.role_vo.bind(EventId.UPDATE_ROLE_ATTRIBUTE, function (key, value) { if (key == "activity") this.updateActivity(true); }.bind(this)) } } //更新活跃度以及激发活跃宝箱 if (this.update_activity_info == null) { this.update_activity_info = gcore.GlobalEvent.bind(TaskEvent.UpdateActivityInfo, function (_data) { this.updateActivityData(_data); }.bind(this)) } this.initCfg(); }, start () { this.updateActivity(false); }, onDestroy(){ this.tweens.forEach( _tween => { _tween.stop(); } ) if (this.role_assets_event != null) { if (this.role_vo != null) { this.role_vo.unbind(this.role_assets_event) } this.role_assets_event = null; } if(this.update_activity_info != null){ gcore.GlobalEvent.unbind(this.update_activity_info); this.update_activity_info = null; } }, onEnable: function(){ this.initCfg(); }, initCfg(){ let TM = TaskController.getInstance().getModel(); let rewards = []; this.tweens = []; if( TM ){ rewards = TM.getActivityData(); } this.rewards = rewards; // console.log( "領取相關" + JSON.stringify( rewards ) ); const dealShow = function( _nod, _data ){ // for (let j in rewards ) { // // nx.gui.setActive( _nod, "tip", parseInt( j ) >= _data ); // nx.gui.setActive( _nod, "got", parseInt( j ) >= _data ); // } } // nx.gui.setActive( this.awards[i], "got", false ); let len = this.awards.length; for(let i=0;i= config.activity && !this.rewards[config.activity] ){ TaskController.getInstance().requestGetActivityAwards(config.activity); return; } this.cfg_list.forEach( _item => { if( _item.index != ( parseInt( e ) + 1 ) ){ nx.gui.setActive( this.awards[ _item.index - 1 ], "show", false ); } }); let nod = nx.gui.find( this.awards[e], "show" ); nx.gui.setActive( this.awards[e], "show", !nod.active ); nx.gui.setActive( this.nodClose, "", nod.active == true ); }, updateActivity: function (need_update) { this.need_update = need_update if (this.role_vo != null) { var activity_config = gdata("activity_data", "data_get", [game.configs.activity_data.data_get_length]); var max_activity = 100; if (activity_config != null) max_activity = activity_config.activity; this.score.string = this.role_vo.activity + "/" + max_activity; this.score_bar.progress = this.role_vo.activity / max_activity; if (need_update) this.updateActivityData(TaskController.getInstance().getModel().getActivityData()); } }, updateActivityData (data) { if (this.role_vo == null)return; var data_list = data; //判断这个活跃度的宝箱是否已经领取了 var check_activity = (activity)=> { if (data_list == null) return false return data_list[activity]; } for (var i in this.awards) { var item = this.awards[i]; let cfg = this.cfg_list[i]; if (item && cfg) { if (check_activity(cfg.activity)) { item.is_show_tips = true; item.status = TaskConst.action_status.finish; } else { if (cfg.activity <= this.role_vo.activity) { item.is_show_tips = false; item.status = TaskConst.action_status.activity; } else { item.is_show_tips = true; item.status = TaskConst.action_status.un_activity; } } // var box_action = PlayerAction.action_1; // if (item.status == TaskConst.action_status.finish){ // box_action = PlayerAction.action_3; // }else if (item.status == TaskConst.action_status.activity){ // box_action = PlayerAction.action_2; // } nx.gui.setActive( item, "tip", !item.is_show_tips ); nx.gui.setActive( item, "icon", item.status != TaskConst.action_status.finish ); let nod = nx.gui.find( item, "tip" ); let cnod = nx.gui.find( item, "icon" ); if( nod.active ){ let tween = cc.tween( cnod ) .to( 0.5, { scale : 0.95, angle : 2 } ) .to( 0.5, { scale : 1, angle : -3 } ) .union() .repeatForever() .start(); this.tweens.push( tween ); }else{ cc.Tween.stopAllByTarget( cnod ); } nx.gui.setActive( item, "got", item.status == TaskConst.action_status.finish ); // //宝箱特效 // var effect_nd = nx.gui.find(item,"effect_container"); // let skel = nx.gui.getComponent(effect_nd,"",sp.Skeleton); // if(effect_nd){ // if (skel.skeletonData) { // if (item.box_action != box_action) { // skel.setAnimation(0, box_action, true); // item.box_action = box_action; // } // }else{ // var res_id = gdata("effect_data", "data_effect_info", this.box_list[i]); // var path = cc.js.formatStr("spine/%s/action.atlas", res_id) // this.createEffect(skel, path, box_action); // } // } } } }, //生成宝箱 createEffect(_skeleton, path, box_action) { cc.loader.loadRes(path,sp.SkeletonData, (res)=> { _skeleton.skeletonData = res; _skeleton.setAnimation(0, box_action, true); }) }, // update (dt) {}, });