Files
fc/dev/project/assets/Scripts/nx/cmp/vbs/nx.vb.base.js
T
2026-05-23 22:10:14 +08:00

114 lines
2.7 KiB
JavaScript

/******************************************************************
* Copyright(C) 2019 - 2020 Nx Studio
*
* 视图绑定组件--基类
*
* 2018.05.18
******************************************************************/
// 可绑定的类型
const BindType = cc.Enum( {
None : 0, // 无
Frame : 1, // 框架
// Account : 2, // 账号
// Role : 3, // Role
// Client : 4, // 客户端
// Game : 5, // 子游戏
DotTip : 11, // 点提示
Cd : 12, // 时间cd
} );
cc.Class( {
extends: cc.Component,
properties: {
bindType: {
default : BindType.None,
type : BindType,
displayName : "绑定对象(标准)",
tooptip : "该控件目前能监听全局存在的视图"
},
bindTypeEx: {
default : "",
displayName : "绑定对象(自定义)",
tooptip : "自定义视图指向"
},
},
// 展示
onLoad: function() {
// 设置扩展目标
if( !this.target ) {
this.setTargetEx( this.bindTypeEx );
}
},
// 关闭
onDestroy: function() {
// 清除监听
if( window.nx && nx.frame && this.target ) {
this.target.vunbind( this );
this.target = null;
}
},
// 设定目标
setTarget: function( _tar ) {
// 清除监听
if( this.target ) {
this.target.vunbind( this );
this.target = null;
}
// 目标更新
this.target = _tar;
},
// 设置扩展目标
setTargetEx: function( _tkey ) {
this.bindTypeEx = _tkey;
// 设定目标
let tar = this.getBindTarget( this.bindType, this.bindTypeEx );
this.setTarget( tar );
},
// 获取目标
getBindTarget: function( _btype, _vbd ) {
// 确认目标
let target = null;
switch( _btype ) {
case BindType.Frame: target = nx.frame; break;
case BindType.DotTip: target = nx.mTip; break;
case BindType.Cd: target = nx.mCd; break;
// case BindType.Client: target = hall; break;
// case BindType.Game: target = game; break;
// case BindType.Account: target = hall; break;
// case BindType.Role: target = hall.mRole; break;
default: break;
}
// VBD对象
if( !target &&
nx.dt.strNEmpty( _vbd ) ) {
target = nx.views.queryBindTarget( _vbd );
}
return target;
},
} );