/*-----------------------------------------------------+ * 桥接: 所有窗体的显示基类 +-----------------------------------------------------*/ const BridgeClass = require( "bridge.class" ); const { SCENE_TAG } = require( "define" ); const BridgeView = cc.Class( { extends: BridgeClass, ctor: function() { this.wname = ""; this.viewTag = SCENE_TAG.panel; this.cache = false; this.prefabPath = ""; this.root_wnd = null; this.is_loading = false; this.parent = null; }, // 设置父节点 setParent: function( parent ) { this.parent = parent; }, // 打开窗体的主入口 open: function( params, _cb ) { // 直接打开 if( this.root_wnd ) { this.openRootWndBridge( params ); nx.dt.fnInvoke( _cb, true ); return; }; // 载入中 if( this.is_loading ) { nx.error( "$UI:载入重复!", this.wname ); nx.dt.fnInvoke( _cb, false ); return; } // 加载 this.is_loading = true; nx.res.loadPrefab( this.prefabPath, ( _err, _fab ) => { this.is_loading = false; // 载入错误 if( _err ) { nx.error( "$UI:载入失败!", nx.fmtError( _err ) ); nx.dt.fnInvoke( _cb, false, nx.fmtError( _err ) ); return; } // 实例化 this.root_wnd = cc.instantiate( _fab ); this.root_wnd.name = this.wname; this.root_wnd.view = this; this.root_wnd.position = cc.Vec2.ZERO; if( this.parent != null ) { this.root_wnd.parent = this.parent; } else { this.bindWndBridge(); nx.bridge.ui.addToSceneNode( this.root_wnd, this.viewTag ); } // 数据设置 this.openRootWndBridge( params ); // 预制常驻 nx.assets.pushResident( this.prefabPath, _fab ); } ); }, /** * 关闭窗体 */ close: function( _fromBridgeWindow = false ) { // 如果不是通过BridgeWindow组件关闭的,那么走组件关闭的方式 if( !_fromBridgeWindow ) { this.unbindWndBridge(); return; } nx.debug( "$UI:窗体关闭:", this.wname ); nx.bridge.Tag2PanelClose(this.wname); // 节点销毁 if( this.root_wnd ) { this.root_wnd.destroy(); this.root_wnd = null; } }, // 桥接BaseView挂载 bindWndBridge: function() { let bridge = nx.bridge.getBridgeWindow( this.root_wnd, "" ); if( bridge ) { bridge.bindView( this ); } }, unbindWndBridge: function() { let bridge = nx.bridge.getBridgeWindow( this.root_wnd, "" ); if( bridge ) { bridge.close( this ); } }, // 桥接开启参数传递 openRootWndBridge: function( _params ) { // 开启失败 let bridge = nx.bridge.getBridgeWindow( this.root_wnd, "" ); if( !bridge ) { nx.error( "$UI:无效窗体,开启失败!", this.wname ); return; } nx.debug( "$UI:窗体打开:", this.wname ); // 层级提前 this.root_wnd.active = true; this.root_wnd.parent.nxOrder = this.root_wnd.parent.nxOrder || 0; this.root_wnd.zIndex = ++this.root_wnd.parent.nxOrder; // 参数打开 bridge.openConfigs( _params ); }, } ); module.exports = BridgeView;