Files
fc/dev/project/assets/Scripts/mod/mainui/cmp/cmp.main.ui.top.js
T

219 lines
6.3 KiB
JavaScript
Raw Normal View History

2026-05-23 22:10:14 +08:00
/******************************************************************
* Copyright(C) 2019 - 2020 Nx Studio
*
* 主界面 --- 顶部栏
*
*
******************************************************************/
const RoleController = require( "role_controller" );
const ExchangeController = require( "exchange_controller" );
const ExchangeEvent = require( "exchange_event" );
const ActMod = require( "acts.mod" );
const ActDefine = require( "acts.define" );
const TDefine = require( "trace.define" );
const TTT = TDefine.TraceType;
const { SCENE_TAG } = require( "define" );
const FID = require( "bridge.function.ids" );
cc.Class( {
extends: cc.Component,
properties: {
nodAvatar: { default: null, type: cc.Node },
progExp: { default: null, type: cc.ProgressBar },
lstActs: { default: null, type: cc.Node },
},
// 加载
onLoad: function() {
// GM界面
if( nx.bridge.vget( "gm" ) ) {
var GmCmd = require( "gmcmd" );
GmCmd.show();
}
// 金币红点
let tipCoin = nx.gui.find( this, "coin/add/tip" );
if( tipCoin ) {
tipCoin.active = false;
this.handler_coin = gcore.GlobalEvent.bind( ExchangeEvent.Extra_Reward, function( data ) {
tipCoin.active = ExchangeController.getInstance().getModel().getRedStatus();
}.bind( this ) )
}
// 经验条
this.exp_bar = nx.gui.find( this, "infos/exp/bar" );
// 角色属性监听
this.role_vo = RoleController.getInstance().getRoleVo();
if( this.role_vo ) {
this.handler_role = this.role_vo.bind( EventId.UPDATE_ROLE_ATTRIBUTE, ( function( key, val ) {
switch( key ) {
case "face_id": this.updateRoleHead(); break;
case "avatar_base_id": this.updateRoleHeadFrame(); break;
case "exp": this.updateRoleExp(); break;
case "exp_max": this.updateRoleExp(); break;
// case "hero_exp": this.updateRoleExp(); break;
default: break;
}
} ), this );
}
this.onInit();
},
// 展示
onInit: function() {
this.updateRoleHead();
this.updateRoleHeadFrame();
this.updateRoleExp();
// 活动监听
ActMod.getInstance().vbind( this, [
[ "themes", this.onActThemesChanged.bind( this ) ],
[ "pushPopup", this.onActPushChanged.bind( this ) ],
] );
// 计时器
this.schedule( () => {
this.cdThemes();
}, 1, cc.macro.REPEAT_FOREVER );
// 今日推送
if( this.role_vo.lev >= game.configs.source_data.data_source_data[ FID.ActFirst ].lev_limit[1] ){
// ActMod.getInstance().reqPushPopup();
}
},
// 销毁
onDestroy: function() {
// 计时器
this.unscheduleAllCallbacks();
if( this.tween ) {
this.tween.stop();
}
// 监听解除
if( this.handler_coin ) {
gcore.GlobalEvent.unbind( this.handler_coin );
this.handler_coin = null;
}
// 监听解除
if( this.handler_role && this.role_vo ) {
this.role_vo.unbind( this.handler_role );
this.handler_role = null;
this.role_vo = null;
}
if( window.nx && nx.bridge.ui && nx.gui.find( nx.bridge.ui.getSceneNode( SCENE_TAG.msg ), "gm" ) ) {
let nod = nx.gui.find( nx.bridge.ui.getSceneNode( SCENE_TAG.msg ), "gm" );
nod.destroy();
}
// 活动监听解除
ActMod.getInstance().vunbind( this );
},
// 头像更新
updateRoleHead: function() {
nx.bridge.setIcon( this.nodAvatar, "mask/img", this.role_vo.face_id );
},
// 头像框更新
updateRoleHeadFrame: function() {
let path = cc.path.join( "resDB/aframes", this.role_vo.avatar_base_id );
nx.gui.setSpriteFrame( this.nodAvatar, "frame", path );
},
// 经验更新
updateRoleExp: function() {
let pro = 0;
if( this.role_vo &&
nx.dt.numGood( this.role_vo.exp ) &&
nx.dt.numGood( this.role_vo.exp_max ) ) {
pro = this.role_vo.exp / this.role_vo.exp_max;
}
this.progExp.progress = pro;
},
// ========================================================================
// 活动
// ========================================================================
// 活动主题刷新
onActThemesChanged: function( _themes ) {
// 重复过滤
if( nx.dt.strNEmpty( this.tsTheme ) ) {
let ids = [];
_themes.forEach( _tm => {
ids.push( _tm.theme_id );
} );
let ts = ids.toString();
if( ts == this.tsTheme ) {
return;
}
this.tsTheme = ts;
}
// 空主题
if( nx.dt.arrEmpty( _themes ) ) {
nx.gui.setActive( this.lstActs, "", false );
return;
}
let chds = this.lstActs.children;
nx.gui.setActive( this.lstActs, "", true );
nx.gui.gocChildren( this.lstActs, "", _themes.length, chds[ 0 ] );
for( let i = 0; i < _themes.length; ++i ) {
let entry = nx.gui.getComponent( chds[ i ], "", "cmp.main.theme.entry" );
if( entry ) {
if ( chds[ i ] ) { chds[ i ].active = true; }
entry.setTheme( _themes[ i ] );
} else {
nx.error( `Top:主题入口组件缺失!` );
if ( chds[ i ] ) { chds[ i ].active = false; }
}
}
},
// 主题活动时间刷新
cdThemes: function() {
let chds = this.lstActs.children;
chds.forEach( node => {
let entry = nx.gui.getComponent( node, "", "cmp.main.theme.entry" );
if( entry && node.active && entry.theme ) {
entry.tick();
}
} );
},
// 活动推送弹窗
onActPushChanged: function( _id ) {
if( !nx.dt.numPositive( _id, false ) ) {
return;
}
this.scheduleOnce( () => {
nx.bridge.createPanel( `WndActPop${ _id }`, { id: _id } );
}, 1 );
},
} );