/******************************************************************************* * * 老版本桥接过渡 --- BaseView过渡到组件化模式 * * ******************************************************************************/ cc.Class( { extends: cc.Component, properties: { BKEY: { default: "BRIDGE_WINDOW"}, }, // 重载:参数打开 onOpenConfigs: function( _params ) { }, // 重载:关闭前 onPreClosed: function() { }, // 不要重载 bindView: function( _baseView ) { this.baseView = _baseView; }, // 不要重载 openConfigs: function( _params ) { if( !this.baseView ) { nx.error( "缺少桥接绑定BaseView!" ); } // 统一关闭调用支持 this.cbClose = null; if( _params ) { this.cbClose = _params.cbClose || null; } this.onOpenConfigs( _params ); }, // 销毁 onDestroy: function() { // 视图监听释放 this.vunbind(); // 事件监听释放 this.unbindGEvents(); // 关闭通告 if( this.cbClose ) { nx.dt.fnInvoke( this.cbClose ); this.cbClose = null; } }, // 关闭 close: function() { // 关闭前 this.onPreClosed(); // 视图监听释放 this.vunbind(); // 事件监听释放 this.unbindGEvents(); // 关闭view if( this.baseView ) { this.baseView.close( true ); } }, // 延迟关闭 delayClose: function( _delay = 0.01 ) { this.scheduleOnce( ()=> { this.close(); }, _delay ); }, // 桥接视图监听 vbind: function( _lst ) { if( nx.bridge && nx.dt.arrNEmpty( _lst ) ) { nx.bridge.vbind( this, _lst ); } }, // 桥接监听视图解除 vunbind: function() { if( window.nx && nx.bridge ) { nx.bridge.vunbind( this ); } }, // 全局事件监听 bindGEvent: function( _id, _cb ) { this.eHandlers = this.eHandlers || []; // 重复性检查 if( CC_DEBUG ) { for( let i in this.eHandlers ) { let binder = this.eHandlers[i]; if( binder && binder.id == _id ) { nx.error( "[BridgeWindow]重复监听事件:", _id ); return; } } } let tag = gcore.GlobalEvent.bind( _id, _cb ); this.eHandlers.push( { id: _id, tag: tag, } ); }, // 全局监听解除(一次性) unbindGEvents: function() { if( window.nx ){ if( nx.dt.arrEmpty( this.eHandlers ) ) { return; } this.eHandlers.forEach( _binder => { gcore.GlobalEvent.unbind( _binder.tag ); } ); this.eHandlers = []; } }, });