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

109 lines
2.6 KiB
JavaScript

/******************************************************************
* Copyright(C) 2019 - 2020 Nx Studio
*
* 常驻悬停层
*
*
******************************************************************/
const BridgeWindow = require( "bridge.window" );
cc.Class( {
extends: BridgeWindow,
properties: {
nodBP: { default: null, type: cc.Node },
},
// 载入
onLoad: function() {
// 显隐
this.nodBP.active = false;
// 视图监听
this.vbind( [
[ "BPChanged", this.onBPChanged.bind( this ) ]
] );
},
// 销毁
onDestroy: function() {
// 视图监听解除
this.vunbind();
},
// 更新
update: function( _dt ) {
// BP更新
if( this.nodBP.active ) {
// 递进
if( this.bp ) {
let cur = Math.floor( this.bp.from + this.bp.step * _dt );
if( this.bp.step > 0 ) {
this.bp.from = Math.min( cur, this.bp.to );
} else {
this.bp.from = Math.max( cur, this.bp.to );
}
this.bp.now.string = this.bp.from.toString();
if( this.bp.from == this.bp.to ) {
this.bp = null;
}
}
// 延时关闭
this.bpTime -= _dt;
if( this.bpTime <= 0 ) {
this.bp = null;
this.nodBP.active = false;
}
}
},
// 战力改变
onBPChanged: function( _cur, _old, _init ) {
if( _init ) {
return;
}
// 无效
if( nx.dt.arrEmpty( _cur ) ||
_cur[0] == _cur[1] ) {
return;
}
// 参数配置
this.bp = {
ofs : _cur[0],
from : _cur[1],
to : _cur[0] + _cur[1],
step : _cur[0] * 2,
};
this.bp.now = nx.gui.setString( this.nodBP, "info/now", this.bp.from );
if( this.bp.ofs > 0 ) {
nx.gui.setActive( this.nodBP, "info/inc", true );
nx.gui.setActive( this.nodBP, "info/dec", false );
nx.gui.setString( this.nodBP, "info/inc", this.bp.ofs.toString() );
} else {
nx.gui.setActive( this.nodBP, "info/inc", false );
nx.gui.setActive( this.nodBP, "info/dec", true );
nx.gui.setString( this.nodBP, "info/dec", this.bp.ofs.toString() );
}
this.bpTime = 1.5;
this.nodBP.active = true;
},
} );