104 lines
2.7 KiB
JavaScript
104 lines
2.7 KiB
JavaScript
|
|
"use strict";
|
||
|
|
cc._RF.push(module, '0c5bf5IR7ZJkqb2Obijk0k+', 'bridge.binder.attr.role.label');
|
||
|
|
// Scripts/zbridge/binder/bridge.binder.attr.role.label.js
|
||
|
|
|
||
|
|
"use strict";
|
||
|
|
|
||
|
|
/******************************************************************
|
||
|
|
* Copyright(C) 2019 - 2020 Nx Studio
|
||
|
|
*
|
||
|
|
* 数据绑定 --- 主角属性(文本)
|
||
|
|
*
|
||
|
|
*
|
||
|
|
******************************************************************/
|
||
|
|
|
||
|
|
var RoleController = require("role_controller");
|
||
|
|
cc.Class({
|
||
|
|
"extends": cc.Component,
|
||
|
|
properties: {
|
||
|
|
attKey: {
|
||
|
|
"default": "",
|
||
|
|
displayName: "属性名"
|
||
|
|
},
|
||
|
|
ndLabel: {
|
||
|
|
"default": null,
|
||
|
|
type: cc.Label,
|
||
|
|
displayName: "属性文本"
|
||
|
|
},
|
||
|
|
shortMoney: {
|
||
|
|
"default": false,
|
||
|
|
displayName: "货币简化支持"
|
||
|
|
}
|
||
|
|
},
|
||
|
|
// 编辑器特性
|
||
|
|
editor: {
|
||
|
|
// 允许当前组件在编辑器模式下运行
|
||
|
|
executeInEditMode: false,
|
||
|
|
// requireComponent 参数用来指定当前组件的依赖组件
|
||
|
|
requireComponent: cc.Label,
|
||
|
|
// 当本组件添加到节点上后,禁止同类型(含子类)的组件再添加到同一个节点,防止逻辑发生冲突
|
||
|
|
disallowMultiple: true,
|
||
|
|
// menu 用来将当前组件添加到组件菜单中,方便用户查找
|
||
|
|
menu: "老版桥接/主角属性"
|
||
|
|
},
|
||
|
|
// 加载
|
||
|
|
onLoad: function onLoad() {
|
||
|
|
if (!this.ndLabel) {
|
||
|
|
this.ndLabel = nx.gui.getComponent(this, "", cc.Label);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
// 显示
|
||
|
|
onEnable: function onEnable() {
|
||
|
|
if (nx.dt.strNEmpty(this.attKey)) {
|
||
|
|
this.bindAttr(this.attKey);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
// 隐藏
|
||
|
|
onDisable: function onDisable() {
|
||
|
|
if (this.binder && this.handler) {
|
||
|
|
this.binder.unbind(this.handler);
|
||
|
|
this.handler = null;
|
||
|
|
this.binder = null;
|
||
|
|
}
|
||
|
|
},
|
||
|
|
// 设置绑定值
|
||
|
|
bindAttr: function bindAttr(_key) {
|
||
|
|
if (nx.dt.strEmpty(_key)) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// if( nx.dt.strNEmpty( this.attKey ) ) {
|
||
|
|
// nx.warn( "[Binder]绑定失败,无法中途修改!" );
|
||
|
|
// return;
|
||
|
|
// }
|
||
|
|
|
||
|
|
this.attKey = _key;
|
||
|
|
this.binder = RoleController.getInstance().getRoleVo();
|
||
|
|
if (!this.binder) {
|
||
|
|
nx.error("[Binder]当前无主角,属性绑定失败!");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
var eid = EventId.UPDATE_ROLE_ATTRIBUTE;
|
||
|
|
this.handler = this.binder.bind(eid, this.onUpdate, this);
|
||
|
|
if (!this.handler) {
|
||
|
|
nx.error("[Binder]属性监听失败!");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 手动更新一次
|
||
|
|
this.onUpdate(this.attKey, this.binder[this.attKey]);
|
||
|
|
},
|
||
|
|
// 更新
|
||
|
|
onUpdate: function onUpdate(_key, _value) {
|
||
|
|
if (_key != this.attKey) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
var val = '' + _value;
|
||
|
|
if (this.shortMoney) {
|
||
|
|
val = Utils.getMoneyString(parseInt(_value), true, 2);
|
||
|
|
}
|
||
|
|
this.ndLabel.string = val;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
cc._RF.pop();
|