/****************************************************************** * Copyright(C) 2019 - 2020 Nx Studio * * 主界面 --- 底部提示队列 * * ******************************************************************/ const BridgeComponent = require( "bridge.component" ); cc.Class( { extends: BridgeComponent, properties: { maxCount: { default: 4 }, spaceHor: { default: 100 }, nodTemp: { default: null, type: cc.Node }, nodList: { default: null, type: cc.Node }, }, // 显示 onEnable: function() { this.cur = null; // 视图监听 this.vbind( [ [ "Prompts", this.onPromptsUpdate.bind( this ) ], ] ); this.scheduleOnce( () => { this.popNext(); }, 2 ); // 全局支持 nx.bridge.prompt = this; }, // 关闭 onDisable: function() { // 全局支持 nx.bridge.prompt = null; // 视图监听释放 this.vunbind(); }, // 提示队列更变 onPromptsUpdate: function( _arr, _old, _init ) { if( _init ) { return; } // 清理 if( nx.dt.arrEmpty( _arr ) ) { this.nodList.removeAllChildren( true ); return; } this.popNext(); }, // 队列弹出 popNext: function() { // 无效跳过 let arr = nx.bridge.vget( "Prompts" ); if( this.cur || nx.dt.arrEmpty( arr ) ) { return; } // 满员跳过 if( this.nodList.childrenCount >= this.maxCount ) { return; } // 弹出 this.cur = arr.shift(); nx.bridge.vset( "Prompts", arr, false ); // 当前追加 let shows = nx.bridge.vget( "PromptsShow" ); shows.push( this.cur ); nx.bridge.vset( "PromptsShow", shows ); // 创建 let node = cc.instantiate( this.nodTemp ); node.info = nx.dt.objClone( this.cur ); node.parent = this.nodList; let path = cc.path.join( "prefab/mainui/ui", this.cur.icon ); nx.gui.setSpriteFrame( node, "icon", path ); node.position = cc.v2( 200, 0 ); let tpos = cc.v2( ( this.nodList.childrenCount - 1 ) * this.spaceHor, 0 ); nx.tween.fadeIn( node, "", 0.5 ); nx.tween.moveTo( node, "", 0.5, tpos, () => { this.cur = null; this.popNext(); } ); }, // 布局更新 autoMove: function( _cb ) { let chds = this.nodList.children; for( let i = 0; i < chds.length; ++i ) { let node = chds[ i ]; let pos = cc.v2( this.spaceHor * i, 0 ); nx.tween.moveTo( node, "", 0.2, pos ); }; this.scheduleOnce( _cb, 0.2 ); }, // 点击提示 onTouchTip: function( _tip ) { let ifo = _tip ? _tip.info : null; if( nx.dt.objEmpty( ifo ) ) { return; } // 执行命令 nx.bridge.cmd.doStr( ifo.cmd ); // 当前移除 let shows = nx.bridge.vget( "PromptsShow" ); nx.dt.arrDelete( shows, ( _m ) => { return _m && _m.id == ifo.id; } ); nx.bridge.vset( "PromptsShow", shows ); // 消除提示 _tip.removeFromParent( true ); this.autoMove( () => { this.popNext(); } ); }, // 下方提示关闭 delPrompt: function( _id ) { // 从当前提示列表中剔除 for( let i in this.nodList.children ) { let tip = this.nodList.children[i]; if( tip && tip.info && tip.info.id == _id ) { // 当前移除 let shows = nx.bridge.vget( "PromptsShow" ); nx.dt.arrDelete( shows, ( _m ) => { return _m && _m.id == _id; } ); nx.bridge.vset( "PromptsShow", shows ); tip.removeFromParent( true ); this.popNext(); return; } } // 从等待队列中剔除 let list = nx.bridge.vget( "Prompts" ); nx.dt.arrDelete( list, ( _m ) => { return _m && _m.id == _id; } ); nx.bridge.vset( "Prompts", list, false ); }, } );