/****************************************************************** * * 点金 活动 * ******************************************************************/ const BasePage = require( "act.page.base" ); const NxSpine = require( "nx.fx.spine" ); const TipsController = require( "tips_controller" ); cc.Class( { extends: BasePage, properties: { nodContent : { type: cc.Node, default: null }, spRole: { default: null, type: NxSpine }, nodEndTime : { default: null, type: cc.Node }, nodScore : { default: null, type: cc.Node }, nodCloseIco : { default: null, type: cc.Node }, }, // 初始化 build: function( _data ) { this.spRole.load( "resDB/models/H30091/show", ( _e ) => { if( !_e ) { this.spRole.action( "action1", true ); } else { this.spRole.stop(); } } ); this._super( _data ); this.rfgs = gdata( this.data.config, "data_get_info1" ); let len = Object.keys( this.rfgs ).length; nx.gui.gocChildren( this.nodContent, "", len ); // 无效 if( !this.mod ) { return; } nx.gui.setActive( this.nodCloseIco, "", false ); // 活动监听 this.mod.vbind( this, [ [ "touchcoin", this.freshInfo.bind( this ) ], [ "activepoints", this.freshActivePoints.bind( this ) ] ] ); // 请求信息 this.mod.reqGetActivePoints(); }, onEnable: function(){ this.mod.reqTouchCoinData(); this.mod.reqGetActivePoints(); }, // 销毁 onDestroy: function() { // 活动监听解除 if( this.mod ) { this.mod.vunbind( this ); } this._super(); }, freshInfo: function( _data ){ /**** * "aim_args":[ * {"aim_args_key":4,"aim_args_val":56,"aim_args_str":""}, * {"aim_args_key":5,"aim_args_val":0,"aim_args_str":""} * ] */ if( !_data ){ let chd = this.nodContent.children; for (let i = 0; i < chd.length; i++) { let nod = chd[i]; let info = this.rfgs[i+10000]; nx.gui.setString( nod, "descs/desc/title", info.desc ); let cmp = nx.gui.getComponent( nod, "lst", "cmp.common.itemlayout" ); if( cmp ){ cmp.rebuild( info.reward ); } nx.gui.setActive( nod, "go", false ); nx.gui.setActive( nod, "get", false ); nx.gui.setActive( nod, "finish", false ); nx.gui.setActive( nod, "descs/leftdesc", false ); } return; } let aim_list = _data.aim_list; if( aim_list ){ this.touchcoin = _data; aim_list.sort( ( a ,b ) => { return a.sortid - b.sortid; } ) this.aims = aim_list; let chd = this.nodContent.children; for (let i = 0; i < chd.length; i++) { let nod = chd[i]; let sinfo = aim_list[i]; let info = this.rfgs[sinfo.aim]; nx.gui.setString( nod, "descs/desc/title", info.desc ); let cmp = nx.gui.getComponent( nod, "lst", "cmp.common.itemlayout" ); if( cmp ){ cmp.rebuild( info.reward ); } let target = 0; let value = 0; nx.gui.find( nod, "go" ).zIndex = info.source_id; nx.gui.find( nod, "get" ).aim = sinfo.aim; sinfo.aim_args.forEach( _aim => { if( _aim && _aim.aim_args_key == 4 ){ target = _aim.aim_args_val; } if( _aim && _aim.aim_args_key == 5 ){ value = _aim.aim_args_val; } } ) nx.gui.setActive( nod, "go", sinfo.status == 0 ); nx.gui.setActive( nod, "get", sinfo.status == 1 ); nx.gui.setActive( nod, "finish", sinfo.status == 2 ); nx.gui.setString( nod, "descs/leftdesc/prog", value + "/" + target ); nx.gui.setActive( nod, "descs/leftdesc", sinfo.status != 2 ); } let left = _data.remain_sec > 0 ? _data.remain_sec : 0.1; nx.gui.setCdTxt( this.nodEndTime, "txt", left, () => { nx.gui.setString( this.nodEndTime, "txt", nx.text.getKey( "lab_recruit_hero_window_tip_6" ) ); } ); }else{ } }, freshActivePoints: function( _actinfo ){ let point = _actinfo.point; nx.gui.setString( this.nodScore, "title/points/point", point ); this.rfg = gdata( this.data.config, "data_get_reward" ); let len = gdata( this.data.config, "data_get_reward_length" ); let prog = nx.gui.getComponent( this.nodScore, "prog", cc.ProgressBar ); let total = this.rfg[len].need_point; let percent = parseFloat( point / total ); if( prog ){ prog.progress = percent; } let rewards = _actinfo.reward_list; let chd = nx.gui.find( this.nodScore, "rewards" ).children; for (let i = 0; i < chd.length; i++) { let nod = chd[i]; let item = this.rfg[i+1]; let showcmp = nx.gui.getComponent( nod, "show", "cmp.common.itemlayout" ); if( showcmp ){ showcmp.rebuild( item.reward ); } nx.gui.setString( nod, "point", nx.text.format( "ActPoint", item.need_point ) ); nx.gui.find( nod, "touch" ).zIndex = i + 1; nx.gui.find( nod, "get" ).zIndex = i + 1; nx.gui.setActive( nod, "ico_close", true ); nx.gui.setActive( nod, "ico_open", false ); nx.gui.setActive( nod, "get", point >= item.need_point ); rewards.forEach( _get => { if( _get && _get.id == ( i + 1 ) ){ nx.gui.setActive( nod, "ico_open", true ); nx.gui.setActive( nod, "get", false ); } } ) nx.gui.setActive( nod, "show", false ); } }, onTouchHideAllDesc: function(){ let chd = nx.gui.find( this.nodScore, "rewards" ).children; for (let i = 0; i < chd.length; i++) { let nod = chd[i]; nx.gui.setActive( nod, "show", false ); } nx.gui.setActive( this.nodCloseIco, "", false ); }, onTouchGetActiveReward: function( _btn ){ let id = this.rfg[_btn.zIndex].id; this.mod.reqGetActiveReward( id ); }, onTouchGet: function( _btn ){ let id = _btn.aim; this.mod.reqGetTouchCoinGift( id ); }, onTouchGoto: function( _btn ){ let source = _btn.zIndex; nx.bridge.jumper.jump2Window( source ); }, onTouchShow: function( _btn ){ let index = parseInt( _btn.zIndex - 1); let chd = nx.gui.find( this.nodScore, "rewards" ).children; for (let i = 0; i < chd.length; i++) { let nod = chd[i]; if( i != index ){ nx.gui.setActive( nod, "show", false ); } } let nodShow = nx.gui.find( chd[index], "show" ); nx.gui.setActive( nodShow, "", !nodShow.active ); nx.gui.setActive( this.nodCloseIco, "", nodShow.active == true ); }, onTouchHelp: function(){ let TC = TipsController.getInstance(); let explain = gdata( this.data.config, "data_explain" ); TC.showDetailPanel( explain ); }, } );