const BridgeComponent = require( "bridge.component" ); const Mod = require( "act.dailytreasure.mod" ); const NxSpine = require( "nx.fx.spine" ); cc.Class({ extends: BridgeComponent, properties: { nodList : { default : null, type : cc.Node }, spRole: { default: null, type: NxSpine }, nodTip: { default : null, type : cc.Node } }, onLoad: function(){ this.mod = Mod.getInstance(); // 无效 if( !this.mod ) { this.delayClose(); return; } this.spRole.load( "resDB/models/H30061/show", ( _e ) => { if( !_e ) { this.spRole.action( "action1", true ); } else { this.spRole.stop(); } } ); this.mod.vbind( this, [ [ "dailySPrayTask", this.freshInfo.bind( this ) ], [ "freshDailyTask", this.freshTask.bind( this ) ], ] ); }, // 销毁 onDestroy: function() { // 活动监听解除 if( this.mod ) { this.mod.vunbind( this ); } delete this.mod; this._super(); }, freshInfo: function( _data ){ if( !_data || nx.dt.arrEmpty( _data.list ) ){ return; } /*** * {"cur_day":2,"end_time":1706543999, * "list":[{"id":60008,"type":13,"finish":0,"target_val":5,"value":0,"end_time":0}, * {"id":60007,"type":13,"finish":0,"target_val":4,"value":0,"end_time":0}, * {"id":60006,"type":13,"finish":0,"target_val":3,"value":0,"end_time":0}, * {"id":60005,"type":13,"finish":1,"target_val":1,"value":1,"end_time":0}]} * */ // let id = this.tasks let info = _data; let period = this.mod.vget( "dailySPrayTask" ); let cur = info.cur_day; info.list.sort( ( a, b )=>{ return a.id - b.id; } ) let tasks = gdata( this.mod.data.config, "data_day_task_list" )[period.period]; let taskshow = []; for (let i in tasks ) { let task = tasks[i]; if( task.day == cur ){ taskshow.push( task ); } } let show = 0; nx.gui.gocChildren( this.nodList, "", taskshow.length ); let chd = this.nodList.children; for (let t = 0; t < chd.length; t++) { let nod = chd[t]; let task = nx.dt.objClone( taskshow[t] ) ; task.cb = ()=>{ this.mod.reqTreasureTaskR( task.goal_id ); } let cmp = nx.gui.getComponent( nod, "", "act.dailytreasure.taskitem" ); if( cmp ){ cmp.rebind( t, task ); cmp.setExInfo( info.list[t] ); if( info.list[t].finish == 1 ){ show ++; } } } nx.gui.setActive( this.nodTip, "", show > 0 ); }, freshTask: function( _info ){ if( !_info || nx.dt.arrEmpty( _info.list ) ){ return; } let info = _info.list; let show = 0; // [31121]:{"list":[{"id":60005,"type":13,"finish":2,"target_val":1,"value":1,"end_time":0}]} let chd = this.nodList.children; for (let i = 0; i < info.length; i++) { let tinfo = info[i]; for (let t = 0; t < chd.length; t++) { let nod = chd[t]; let cmp = nx.gui.getComponent( nod, "", "act.dailytreasure.taskitem" ); if( cmp ){ if( cmp.mdata.goal_id == tinfo.id ){ cmp.setExInfo( tinfo ); if( tinfo.finish == 1 ){ show ++; } } } } } nx.gui.setActive( this.nodTip, "", show > 0 ); this.mod.openTip( "reward", show > 0 ); }, onEnable: function(){ }, });