/****************************************************************** * 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() { // 节点补全 if( !this.nodRef ) { this.nodRef = this.node; } // 初始化条件 this.setCondition( this.condID ); }, // 设置条件 setCondition: function( _id ) { // 条件编号判断 let id = parseInt( _id ) || 0; if( !nx.dt.numPositive( id, false ) ) { if( this.nodRef ){ this.nodRef.active = false; } nx.gui.setActive( this.nodExtra, "", true ); return; } // 配置验证 let 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 ); // 触发更新 let fcon = cfgs.lev_limit[ 0 ]; this.updateLocker( fcon[ 0 ] ); }, // 更新锁定 updateLocker: function( _key, _val ) { // 无效 if( nx.dt.strEmpty( _key ) || nx.dt.objEmpty( this.config ) ) { return; } let 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() { if( nx.dt.objEmpty( this.result ) || nx.dt.strEmpty( this.result.desc ) ) { return; } let tip = this.config ? nx.text.getKey( this.config.desc1 ) : ""; if( nx.dt.strEmpty( tip ) ) { tip = this.result.desc; } nx.tbox( tip ); }, } );