const ActPopup = require( "act.popup.base" ); const FxSVC = require( "nx.fx.sv.expand" ); const Mod = require( "act.wreckagecol.mod" ); const themeMod = require( "acts.mod" ); const FID = require( "bridge.function.ids" ); /*** * * 探宝活动 */ cc.Class({ extends: ActPopup, properties: { nodItems:{ default: null, type : FxSVC, }, nodTasklst:{ default: null, type : cc.Node, }, nodMat: {default: null, type : cc.Node, }, nodEndtime: {default: null, type : cc.Node, }, nodShow: {default: null, type : cc.Node, }, }, // 初始化 onOpenConfigs: function( _params ) { this._super( _params ); this.mod = Mod.getInstance(); if( !this.mod ){ this.delayClose(); return; } let cfgs = gdata( this.mod.data.config, "data_item_exchange" ); this.cfgs = nx.dt.objClone( cfgs ); let qfgs = gdata( this.mod.data.config, "data_quest_list" ); this.qfgs = nx.dt.objClone( qfgs ); let qls = []; let items = []; for (let i in cfgs ) { let item = cfgs[i]; items.push( item ); } items.sort( ( a, b ) =>{ return a.point - b.point; } ) for (let j in qfgs ) { let qitem = qfgs[j]; qls.push( qitem ); } nx.gui.gocChildren( this.nodTasklst, "", qls.length ); this.nodItems.rebuild( items ); this.mod.vbind( this, [ [ "wreckagecol", this.freshWreckagecolInfo.bind( this ) ], [ "wreckagecolTask", this.freshWreckagecolTask.bind( this ) ], [ "wreckagecolExchange", this.freshColExchange.bind( this ) ], [ "wreckagecolInfo", this.onShowInfo.bind( this ) ], ] ); this.mod.reqWreckageColData(); }, onEnable: function(){ }, onDisable: function(){ this.mod.vset( "wreckagecolInfo", null ) }, // 销毁 onDestroy: function() { // this.mod.vset( "wreckagecolInfo", null ); // 活动监听解除 if( this.mod ) { this.mod.vunbind( this ); } delete this.mod; this._super(); }, freshWreckagecolInfo : function( _data ){ if( !_data || nx.dt.objEmpty( _data ) ){ return; } // 材料顯示 nx.gui.setString( this.nodMat, "count", _data.num ); let time = _data.end_time - Math.floor( cc.sys.now() / 1000 ) > 0 ? _data.end_time - Math.floor( cc.sys.now() / 1000 ) : 0.1; nx.gui.setCdTxt( this.nodEndtime, "txt", ( time ), () => { nx.gui.setString( this.nodEndtime, "txt", nx.text.getKey( "lab_planesafk_main_have_over" ) ); } ); let taskLst = _data.list; let exchange = _data.reward_list; this.have = _data.num; this.freshExchangeInfo( exchange ); let chd = this.nodTasklst.children; // 刷新任務信息顯示 if( nx.dt.arrEmpty( taskLst ) ){ chd.forEach( _nod =>{ let cmp = _nod.getComponent( "cmp.act.wreckagecol.titem" ); if( cmp ){ let exInfo = { finish : -1, target_val : 0, value : 0, } cmp.setExInfo( exInfo ); } } ) }else{ taskLst.sort( ( a,b ) => { return b.sortid - a.sortid; } ) for (let i = 0; i < taskLst.length; i++) { let task = taskLst[i]; let nod = chd[i]; let baseinfo = this.qfgs[task.id]; baseinfo.cb = ( ()=>{ this.mod.reqFinishTask( baseinfo.id ); } ) if( nod ){ let cmp = nod.getComponent( "cmp.act.wreckagecol.titem" ); if( cmp ){ cmp.rebind( i, baseinfo ); let exInfo = { finish : task.finish, target_val : task.target_val, value : task.value, } cmp.setExInfo( exInfo ); } } } } // {"end_time":1695139199,"num":0,"list":[],"reward_list":[]} }, freshExchangeInfo: function( _info ){ let rhd = nx.gui.find( this.nodItems.bindSCV, "view/content" ).children; for (let r = 0; r < rhd.length; r++) { let rnod = rhd[r]; let rinfo = _info[r]; if( rinfo ){ let cmp = rnod.svItem; if( cmp ){ let exinfo = { buy_num : rinfo.buy_num, max_num : rinfo.max_num, } cmp.setExData( exinfo ); } } } }, freshWreckagecolTask: function( _data ){ }, freshColExchange: function( _exchange ){ if( !_exchange ){ return; } this.freshExchangeInfo( _exchange.reward_list ); this.have = _exchange.num; nx.gui.setString( this.nodMat, "count", _exchange.num ); }, onTouchExChange: function( _item ){ if( this.have < _item.mdata.point ){ nx.tbox( "SummonItemNotEnough" ); return; } this.mod.reqExchange( _item.mdata.id ); }, onShowInfo : function( _info ){ if( _info ){ let info = _info; nx.gui.setString( this.nodShow, "num", "x " + info.cfg.point ); nx.gui.setString( this.nodShow, "tip", info.tip ); nx.gui.setActive( this.nodShow, "", true ); }else{ this.hideInfo(); } }, hideInfo: function(){ nx.gui.setActive( this.nodShow, "", false ); }, onTouchClose: function(){ let theme = themeMod.getInstance().queryTheme( this.mod.data.theme_id ); nx.bridge.jumper.jump2Window( FID.ActOpenServer, theme ); this.close(); }, });