/****************************************************************** * * VIP页面 * ******************************************************************/ const MenuPage = require( "cmp.com.menu.page" ); const FXTog = require( "nx.fx.togs" ); const VipController = require( "vip_controller" ); const RoleController = require( "role_controller" ); cc.Class( { extends: MenuPage, properties: { nodVipLev: { default: null, type: cc.Node }, nodTogs: { default: null, type: FXTog }, nodShow: { default: null, type: cc.Node }, nodVipLst: { default: null, type: cc.Node }, }, onLoad: function() { this.alreadyBuy = []; this.onTouch = 0; this.nodTogs.posTog = this.onTouchChange.bind( this ); let cfg = game.configs.vip_data.data_get_reward; this.cfgs = cfg; let vip = RoleController.getInstance().getRoleVo().vip_lev; this.vip = vip; let count = Object.keys( cfg ).length; let cmp = nx.gui.getComponent( this.nodShow, "extItems", "cmp.common.itemlayout" ); let spcmp = nx.gui.getComponent( this.nodShow, "gift/view/spgift", "cmp.common.itemlayout" ); // 角色属性监听 this.role_vo = RoleController.getInstance().getRoleVo(); if( this.role_vo ) { this.handler_role = this.role_vo.bind( EventId.UPDATE_ROLE_ATTRIBUTE, ( function( key, val ) { // console.log( 'HERO ATTR: ', key, val ); if( key == 'vip_exp' || key == 'vip_lev' ) { this.scheduleOnce( () => { this.freshVip(); }, 0.1 ); } } ), this ); } cmp.rebuild( [] ); spcmp.rebuild( [] ); nx.gui.gocChildren( this.nodTogs, "", count ); for( let i in cfg ) { let vip = cfg[ i ]; let nod = this.nodTogs.node.children[ i ]; nx.gui.setStringRich( nod, "on/txt", vip.lev != 0 ? nx.text.format( "VIPTipRich", vip.lev ) : nx.text.format( "VIPTipRich", "" ) ); nx.gui.setString( nod, "off/txt", nx.text.format( "VIPTip", vip.lev ) ); } this.vbind( [ [ "VIPBuyGifts", this.onFreshBuyInfo.bind( this ) ], [ "VIPMMSp", this.onFreshGetExt.bind( this ) ], ] ); // this.nodTogs.rebuildTogs(); // this.togMenus.togTo( 0 ); // this.activeMenus( 1 ); // Tog监听 this.nodTogs.togTo( 0 ); this.onTogMenus( 0 ); }, freshVip: function(){ let vip = RoleController.getInstance().getRoleVo().vip_lev; this.vip = vip; nx.gui.setString( this.nodVipLev, "panel/level/txt", vip ); if(this.cfgs){ let total = vip + 1 < 13 ? this.cfgs[ vip + 1 ].gold : this.cfgs[ 13 ].gold; let now = RoleController.getInstance().getRoleVo().vip_exp; nx.gui.setString( this.nodVipLev, "panel/prog", now + "/" + total ); let cmp = nx.gui.getComponent( this.nodVipLev, "panel/bar", cc.ProgressBar ); if( cmp ) { cmp.progress = parseFloat( now / total ); } nx.gui.setStringRich( this.nodVipLev, "panel/tip", nx.text.format( "ChargeTip", ( vip + 1 ) <= 13 ? ( total - now ) : 0, ( vip + 1 ) <= 13 ? ( vip + 1 ) : 13 ) ); } }, onEnable: function() { this.freshVip(); VipController.getInstance().sender16707(); this.nodTogs.togTo( this.vip ); this.scv = nx.gui.getComponent( this.nodTogs.node.parent.parent, "", cc.ScrollView ); this.onTogMenus( this.vip ); if( this.vip <= 13 && this.vip >= 9 ) { this.scv.scrollToBottom( 0.01 ); } else { if( this.scv ) { let posp = cc.v2( 0, ( this.vip ) * 90 ); this.scv.setContentPosition( posp ); // scrollTo } } }, onDisable: function() { let cmp = nx.gui.getComponent( this.nodShow, "extItems", "cmp.common.itemlayout" ); let spcmp = nx.gui.getComponent( this.nodShow, "gift/view/spgift", "cmp.common.itemlayout" ); cmp.rebuild( [] ); spcmp.rebuild( [] ); }, onTouchChange: function( _index ) { let cmp = nx.gui.getComponent( this.nodShow, "extItems", "cmp.common.itemlayout" ); let spcmp = nx.gui.getComponent( this.nodShow, "gift/view/spgift", "cmp.common.itemlayout" ); cmp.rebuild( [] ); spcmp.rebuild( [] ); this.onTogMenus( _index ); }, onTogMenus: function( _index ) { let cmp = nx.gui.getComponent( this.nodShow, "extItems", "cmp.common.itemlayout" ); let spcmp = nx.gui.getComponent( this.nodShow, "gift/view/spgift", "cmp.common.itemlayout" ); // cmp.rebuild( [] ); // spcmp.rebuild( [] ); this.onTouch = _index; let extRewards = game.configs.charge_data.data_supre_reward_data; let vipExt = extRewards[ _index ]; let vfg = this.cfgs[ _index ]; if( cmp ) { cmp.rebuild( vipExt.reward ); } nx.gui.setStringRich( this.nodShow, "vip_title", nx.text.format( "VIPPrivilege", _index ) ); nx.gui.setStringRich( this.nodShow, "desc/view/content/txt", vfg.spe_desc ); nx.gui.setString( this.nodShow, "normal/cost", nx.text.getKey( "act_limit_buy1" ) + vfg.old_price[ 0 ][ 1 ] ); nx.gui.setString( this.nodShow, "op/price", vfg.price[ 0 ][ 1 ] == 0 ? nx.text.getKey( "Free" ) : vfg.price[ 0 ][ 1 ] ); nx.gui.setString( this.nodShow, "cannot/price", vfg.price[ 0 ][ 1 ] == 0 ? nx.text.getKey( "Free" ) : vfg.price[ 0 ][ 1 ] ); nx.bridge.setIconS( this.nodShow, "op/icon", vfg.price[ 0 ][ 0 ] ); nx.bridge.setIconS( this.nodShow, "cannot/icon", vfg.price[ 0 ][ 0 ] ); nx.bridge.setIconS( this.nodShow, "normal/icon", vfg.price[ 0 ][ 0 ] ); if( spcmp ) { spcmp.rebuild( vfg.items ); } nx.gui.setStringRich( this.nodShow, "desc_tip", nx.text.format( "lab_vipChargePrivilege", 3, vfg.gold ) ); nx.gui.setActive( this.nodShow, "op", !nx.dt.arrMember( this.alreadyBuy, _index ) && ( this.vip >= _index ) ); nx.gui.setActive( this.nodShow, "cannot", !nx.dt.arrMember( this.alreadyBuy, _index ) && this.vip < _index ); // let cmp = nx.gui.setActive( this.nodShow, "sold", nx.dt.arrMember( this.alreadyBuy, _index ) ); nx.gui.setActive( this.nodShow, "claim", this.vip == _index ); let btn = nx.gui.getComponent( this.nodShow, "claim", cc.Button ); if( btn ) { btn.interactable = ( this.vip == _index && this.status == 1 ); nx.gui.setString( this.nodShow, "claim/price", this.status != 2 ? nx.text.getKey( "Get" ) : nx.text.getKey( "Got" ) ); nx.gui.setOutlineColor( this.nodShow, "claim/price", ( this.vip == _index && this.status == 1 ) ? new cc.color( "#b85833" ) : cc.Color.BLACK ); } // nx.gui.setActive( this.nodShow, "got", this.status == 2 ); nx.gui.find( this.nodShow, "op" ).zIndex = vfg.lev; }, onFreshBuyInfo: function( _buyinfo ) { this.alreadyBuy = []; if( nx.dt.arrNEmpty( _buyinfo ) ) { _buyinfo.forEach( _info => { this.alreadyBuy.push( _info.lev ); } ); } this.onTogMenus( this.onTouch ); }, onFreshGetExt: function( _status ) { this.nodTogs.node.children.forEach( _nod => { nx.gui.setActive( _nod, "off/tip", false ); } ) this.status = _status; let vip = RoleController.getInstance().getRoleVo().vip_lev; let nod = this.nodTogs.node.children[ vip ]; nx.gui.setActive( nod, "off/tip", this.status == 1 ); this.onTogMenus( this.onTouch ); }, onTouchGet: function() { VipController.getInstance().sender16708(); // console.log( ); }, onTouchBuy: function( _btn ) { let vip = RoleController.getInstance().getRoleVo().vip_lev; if( vip < _btn.zIndex ) { nx.tbox( nx.text.format( "tips_vipBuy", _btn.zIndex ) ); return; } VipController.getInstance().sender16711( _btn.zIndex ); // console.log( ); }, } );