115 lines
2.7 KiB
JavaScript
115 lines
2.7 KiB
JavaScript
|
|
"use strict";
|
||
|
|
cc._RF.push(module, '44f1e0luNlCQqq3ve1+B+fI', 'nx.vb.visible');
|
||
|
|
// Scripts/nx/cmp/vbs/nx.vb.visible.js
|
||
|
|
|
||
|
|
"use strict";
|
||
|
|
|
||
|
|
/******************************************************************
|
||
|
|
* Copyright(C) 2019 - 2020 Nx Studio
|
||
|
|
*
|
||
|
|
* 视图绑定组件--显示控件
|
||
|
|
*
|
||
|
|
* 2018.05.18
|
||
|
|
******************************************************************/
|
||
|
|
|
||
|
|
var VBBase = require("nx.vb.base");
|
||
|
|
|
||
|
|
// 可见判别类型
|
||
|
|
var ShowType = cc.Enum({
|
||
|
|
None: 0,
|
||
|
|
// 不显示
|
||
|
|
Role: 1,
|
||
|
|
// Role显示
|
||
|
|
Bool: 3,
|
||
|
|
// 布尔显示
|
||
|
|
EqualZero: 4,
|
||
|
|
// 为0显示
|
||
|
|
EqualNum: 5,
|
||
|
|
// 等于某个值
|
||
|
|
EmptyStr: 6 // 空字符串
|
||
|
|
});
|
||
|
|
|
||
|
|
cc.Class({
|
||
|
|
"extends": VBBase,
|
||
|
|
properties: {
|
||
|
|
bindKey: {
|
||
|
|
"default": "",
|
||
|
|
displayName: "参数名"
|
||
|
|
},
|
||
|
|
showType: {
|
||
|
|
"default": ShowType.None,
|
||
|
|
type: ShowType,
|
||
|
|
displayName: "显隐类型",
|
||
|
|
tooptip: "参照nx.vb.base中的showType支持类型"
|
||
|
|
},
|
||
|
|
isRevert: {
|
||
|
|
"default": false,
|
||
|
|
displayName: "判定反转"
|
||
|
|
},
|
||
|
|
equalValue: {
|
||
|
|
"default": "",
|
||
|
|
displayName: "EqualNum时有效"
|
||
|
|
}
|
||
|
|
},
|
||
|
|
// 编辑器特性
|
||
|
|
editor: {
|
||
|
|
// 允许当前组件在编辑器模式下运行
|
||
|
|
executeInEditMode: false,
|
||
|
|
// requireComponent 参数用来指定当前组件的依赖组件
|
||
|
|
requireComponent: null,
|
||
|
|
// 当本组件添加到节点上后,禁止同类型(含子类)的组件再添加到同一个节点,防止逻辑发生冲突
|
||
|
|
disallowMultiple: true,
|
||
|
|
// menu 用来将当前组件添加到组件菜单中,方便用户查找
|
||
|
|
menu: "Nx/视图|可视化"
|
||
|
|
},
|
||
|
|
// 设定目标
|
||
|
|
setTarget: function setTarget(_tar, _key) {
|
||
|
|
this._super(_tar);
|
||
|
|
this.bindKey = _key || this.bindKey;
|
||
|
|
if (this.target && nx.dt.strNEmpty(this.bindKey)) {
|
||
|
|
this.target.vbind(this, [[this.bindKey, this._onValueChanged.bind(this)]]);
|
||
|
|
} else {
|
||
|
|
this.node.active = false;
|
||
|
|
}
|
||
|
|
},
|
||
|
|
// 改变通知
|
||
|
|
_onValueChanged: function _onValueChanged(_now, _last) {
|
||
|
|
var visible = false;
|
||
|
|
switch (this.showType) {
|
||
|
|
case ShowType.Role:
|
||
|
|
{
|
||
|
|
visible = _now;
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
case ShowType.Bool:
|
||
|
|
{
|
||
|
|
visible = _now;
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
case ShowType.EqualZero:
|
||
|
|
{
|
||
|
|
visible = _now == 0;
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
case ShowType.EqualNum:
|
||
|
|
{
|
||
|
|
visible = _now == this.equalValue;
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
case ShowType.EmptyStr:
|
||
|
|
{
|
||
|
|
visible = nx.dt.strEmpty(_now);
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
default:
|
||
|
|
{}
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
if (this.isRevert) {
|
||
|
|
visible = !visible;
|
||
|
|
}
|
||
|
|
nx.gui.setActive(this.node, null, visible);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
cc._RF.pop();
|