Files
fc/dev/project/library/imports/a8/a82a5191-6f29-46c7-b8c9-31033103125c.js
T
2026-05-24 10:21:26 +08:00

125 lines
3.0 KiB
JavaScript

"use strict";
cc._RF.push(module, 'a82a5GRbylGx7jJMQMxAxJc', 'bridge.condition.locker');
// Scripts/zbridge/cmps/bridge.condition.locker.js
"use strict";
/******************************************************************
* Copyright(C) 2019 - 2020 Nx Studio
*
* 视图绑定组件--锁定状态
*
* 2018.05.18
******************************************************************/
cc.Class({
"extends": cc.Component,
properties: {
nodRef: {
"default": null,
type: cc.Node,
displayName: "加锁节点"
},
nodExtra: {
"default": null,
type: cc.Node,
displayName: "互斥节点"
},
condID: {
"default": 0,
displayName: "条件编号"
},
showText: {
"default": true,
displayName: "显示文本"
},
touchTip: {
"default": true,
displayName: "点击提示"
}
},
// 编辑器特性
editor: {
// menu 用来将当前组件添加到组件菜单中,方便用户查找
menu: "老版桥接/条件锁定"
},
// 载入
onLoad: function onLoad() {
// 节点补全
if (!this.nodRef) {
this.nodRef = this.node;
}
// 初始化条件
this.setCondition(this.condID);
},
// 设置条件
setCondition: function setCondition(_id) {
// 条件编号判断
var id = parseInt(_id) || 0;
if (!nx.dt.numPositive(id, false)) {
if (this.nodRef) {
this.nodRef.active = false;
}
nx.gui.setActive(this.nodExtra, "", true);
return;
}
// 配置验证
var cfgs = game.configs.source_data.data_source_data[id];
if (!cfgs) {
if (this.nodRef) {
this.nodRef.active = false;
}
nx.gui.setActive(this.nodExtra, "", true);
nx.error("无效的锁定编号:", _id);
return;
}
// 没有限制
if (nx.dt.arrEmpty(cfgs.lev_limit)) {
if (this.nodRef) {
this.nodRef.active = false;
}
nx.gui.setActive(this.nodExtra, "", true);
return;
}
// 更新记录
this.condID = id;
this.config = nx.dt.objClone(cfgs);
// 触发更新
var fcon = cfgs.lev_limit[0];
this.updateLocker(fcon[0]);
},
// 更新锁定
updateLocker: function updateLocker(_key, _val) {
// 无效
if (nx.dt.strEmpty(_key) || nx.dt.objEmpty(this.config)) {
return;
}
var conds = this.config.lev_limit;
this.result = nx.bridge.checkConditions(conds);
if (this.nodRef) {
this.nodRef.active = nx.dt.objNEmpty(this.result);
nx.gui.setActive(this.nodExtra, "", !this.nodRef.active);
}
if (this.showText && this.nodRef && this.nodRef.active) {
nx.gui.setString(this.nodRef, "txt", nx.text.getKey(this.config.desc1));
}
},
// 点击提示
onTouch: function onTouch() {
if (nx.dt.objEmpty(this.result) || nx.dt.strEmpty(this.result.desc)) {
return;
}
var tip = this.config ? nx.text.getKey(this.config.desc1) : "";
if (nx.dt.strEmpty(tip)) {
tip = this.result.desc;
}
nx.tbox(tip);
}
});
cc._RF.pop();