Files
fc/dev/project/assets/Scripts/mod/acts/vipLevel/cmp.act.vipLevel.wnd.js
T
2026-05-23 22:10:14 +08:00

112 lines
2.9 KiB
JavaScript

/******************************************************************
*
* VIP升级
*
******************************************************************/
const ActPage = require( "act.page.base" );
const FxSVC = require( "nx.fx.sv.expand" );
const RoleController = require( "role_controller" );
cc.Class( {
extends: ActPage,
properties: {
lstTask: { default: null, type: FxSVC },
nodVIP: { default: null, type: cc.Node },
},
// 初始化
build: function( _data ) {
this._super( _data );
// 活动监听
this.mod.vbind( this, [
["VipTasks", this.freshTask.bind( this )],
] );
// 角色属性监听
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' ) {
this.scheduleOnce( () => {
this.freshVip();
}, 0.1 );
}
} ), this );
}
},
onEnable: function() {
this.mod.reqBaseData();
this.freshVip();
},
// 销毁
onDestroy: function() {
// 角色监听解除
if( this.handler_role && this.role_vo ) {
this.role_vo.unbind( this.handler_role );
this.handler_role = null;
this.role_vo = null;
}
// 活动监听解除
if( this.mod ) {
this.mod.vunbind( this );
}
this._super();
},
// VIP刷新
freshVip: function() {
if( !this.role_vo ) {
return;
}
let cfg = game.configs.vip_data.data_get_reward;
let lev = this.role_vo.vip_lev;
let now = this.role_vo.vip_exp;
let total = ( lev + 1 < 13 ) ? cfg[lev + 1].gold : cfg[lev].gold;
nx.gui.setString( this.nodVIP, "vip/num", lev );
nx.gui.setString( this.nodVIP, "exp", `${now}/${total}` );
let cmp = nx.gui.getComponent( this.nodVIP, "prog", cc.ProgressBar );
if( cmp ) {
cmp.progress = parseFloat( now / total );
}
},
// 任务刷新
freshTask: function( _task ) {
// 0不可领取 1可领取 2已领取
let PR = [2, 1, 3];
this.tasks = nx.dt.objClone( _task );
this.tasks.sort( ( a, b ) => {
if( a.status == b.status ) {
return a.id - b.id;
}
return PR[a.status] - PR[b.status];
} );
let cfg = game.configs.vip_data.data_lev_gift;
for( let i in this.tasks ) {
let task = this.tasks[i];
task.level = task.id;
task.rewards = cfg[task.id].reward;
task.mod = this.mod;
}
this.lstTask.rebuild( this.tasks );
},
} );