263 lines
6.4 KiB
JavaScript
263 lines
6.4 KiB
JavaScript
/*******************************************************************************
|
|
*
|
|
* 消息UI管理
|
|
*
|
|
*
|
|
*
|
|
* 2021.12.10
|
|
******************************************************************************/
|
|
|
|
const SEC_FadeIn = 0.3;
|
|
const SEC_Delay = 0.7;
|
|
const SEC_FadeOut = 2;
|
|
|
|
cc.Class( {
|
|
|
|
extends: cc.Component,
|
|
|
|
properties: {
|
|
|
|
nodTmp: {
|
|
default : null,
|
|
type : cc.Node,
|
|
displayName : "样本层"
|
|
},
|
|
|
|
rootBox: {
|
|
default : null,
|
|
type : cc.Node,
|
|
displayName : "弹框层"
|
|
},
|
|
|
|
rootTips: {
|
|
default : null,
|
|
type : cc.Node,
|
|
displayName : "轻提示层"
|
|
},
|
|
|
|
maxTipWidth: {
|
|
default : 0.7,
|
|
displayName : "宽度限制"
|
|
},
|
|
|
|
},
|
|
|
|
// 载入
|
|
onLoad: function() {
|
|
|
|
// 全局服务
|
|
nx.msgUI = this;
|
|
|
|
// 界面初始化
|
|
this.nodTmp.active = false;
|
|
|
|
// 基本变量
|
|
this.tipCur = ""; // 当前轻提示
|
|
this.boxQueue = []; // 弹框队列
|
|
this.tipQueue = []; // 轻提示队列
|
|
|
|
// 蒙版控制
|
|
this.rootBox.on( "child-added", this._onFreshMask, this );
|
|
this.rootBox.on( "child-removed", this._onFreshMask, this );
|
|
this._onFreshMask();
|
|
|
|
},
|
|
|
|
// 销毁
|
|
onDestroy: function() {
|
|
|
|
if( window.nx ){
|
|
// 全局服务
|
|
nx.msgUI = null;
|
|
}
|
|
|
|
|
|
// 全部关闭
|
|
// this.closeAll();
|
|
},
|
|
|
|
// 全部关闭
|
|
closeAll: function() {
|
|
|
|
// 计时器销毁
|
|
this.unscheduleAllCallbacks();
|
|
|
|
this.tipCur = "";
|
|
this.boxQueue = [];
|
|
this.tipQueue = [];
|
|
this.rootBox.removeAllChildren();
|
|
this.rootTips.removeAllChildren();
|
|
|
|
},
|
|
|
|
/***
|
|
* *********************************************************************
|
|
* 弹窗
|
|
* *********************************************************************
|
|
*/
|
|
|
|
// 弹窗提示
|
|
popBox: function( _text, _btns, _cb, _skey = "" ) {
|
|
|
|
var boxes = this.rootBox.children;
|
|
|
|
// 唯一性查找
|
|
if( nx.dt.strNEmpty( _skey ) && boxes.length > 0 ) {
|
|
|
|
for( let i in boxes ) {
|
|
if( boxes[i].skey == _skey ) {
|
|
nx.warn( "重复弹窗:" + _skey );
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 新建
|
|
var temp = nx.gui.find( this.nodTmp, "mbox" );
|
|
if( !temp || nx.dt.strEmpty( _text + '' ) ) {
|
|
nx.error( "创建弹窗提示失败,条件不足!" );
|
|
return;
|
|
}
|
|
|
|
var box = cc.instantiate( temp );
|
|
if( !box ) {
|
|
nx.error( "创建弹窗提示失败!" );
|
|
return;
|
|
}
|
|
|
|
box.position = cc.Vec2.ZERO;
|
|
box.parent = this.rootBox;
|
|
box.skey = _skey;
|
|
|
|
var cmp = box.getComponent( "cmp.message.box" );
|
|
cmp.show( _text + '', _btns, _cb, ()=> {
|
|
} );
|
|
|
|
},
|
|
|
|
// 指定关闭弹框
|
|
closeBox: function( _skey ) {
|
|
|
|
if( nx.dt.strEmpty( _skey ) ) {
|
|
return;
|
|
}
|
|
|
|
var boxes = this.rootBox.children;
|
|
for( let i in boxes ) {
|
|
let box = boxes[i];
|
|
if( box && box.skey == _skey ) {
|
|
box.removeFromParent( true );
|
|
break;
|
|
}
|
|
}
|
|
|
|
},
|
|
|
|
// 蒙版刷新
|
|
_onFreshMask: function() {
|
|
let count = this.rootBox.childrenCount;
|
|
nx.gui.setActive( this.rootBox, "mask", count > 1 );
|
|
},
|
|
|
|
/***
|
|
* *********************************************************************
|
|
* 轻态
|
|
* *********************************************************************
|
|
*/
|
|
|
|
// 轻态提示
|
|
popTip: function( _text ) {
|
|
|
|
// 空处理
|
|
if( nx.dt.strEmpty( _text ) ) {
|
|
nx.error( "创建轻态提示失败,条件不足!" );
|
|
return;
|
|
}
|
|
|
|
// 去重
|
|
let txt = nx.text.getKey( _text );
|
|
if( nx.dt.arrMember( this.tipQueue, txt ) ) {
|
|
nx.warn( "提示去重:", txt );
|
|
return;
|
|
}
|
|
|
|
// 压入队列
|
|
this.tipQueue.push( txt );
|
|
if( nx.dt.strEmpty( this.tipCur ) ) {
|
|
this._nextTip();
|
|
}
|
|
|
|
},
|
|
|
|
// 弹出提示
|
|
_nextTip: function( ) {
|
|
|
|
// 空结束
|
|
if( nx.dt.arrEmpty( this.tipQueue ) ) {
|
|
this.tipCur = "";
|
|
this.tipQueue = [];
|
|
return;
|
|
}
|
|
|
|
// 位置规划
|
|
if( !this.popPath ) {
|
|
this.popPath = {
|
|
start : this.rootTips.getChildByName( "start" ),
|
|
stay : this.rootTips.getChildByName( "stay" ),
|
|
end : this.rootTips.getChildByName( "end" ),
|
|
}
|
|
}
|
|
|
|
// 弹出一条
|
|
let txt = this.tipQueue.shift();
|
|
if( nx.dt.strEmpty( txt ) ) {
|
|
this._nextTip( );
|
|
return;
|
|
}
|
|
|
|
// 弹出有效 && 实例化
|
|
this.tipCur = txt;
|
|
|
|
// 弹窗处理
|
|
let pos = Math.max( txt.search( "/>" ), txt.search( "</" ) );
|
|
let key = ( pos != -1 ) ? "tboxRc" : "tbox";
|
|
let temp = nx.gui.find( this.nodTmp, key );
|
|
|
|
// 文本设置
|
|
let tip = cc.instantiate( temp );
|
|
let cmp = tip.getComponent( "cmp.message.tip" );
|
|
cmp.setText( txt, this.node.width * this.maxTipWidth );
|
|
|
|
// 显示&位置初始化
|
|
tip.parent = this.rootTips;
|
|
tip.position = this.popPath.start.position;
|
|
|
|
tip.opacity = 0;
|
|
cc.tween( tip )
|
|
.to( SEC_FadeIn, { position: this.popPath.stay.position, opacity: 255 }, { easing: "cubicOut" } )
|
|
.delay( SEC_Delay )
|
|
.call( () => { this._nextTip(); } )
|
|
.to( SEC_FadeOut, { position: this.popPath.end.position, opacity: 0 } ) //, { easing: "cubicOut" } )
|
|
.removeSelf()
|
|
.start();
|
|
|
|
},
|
|
|
|
/***
|
|
* *********************************************************************
|
|
* 跑马灯
|
|
* *********************************************************************
|
|
*/
|
|
|
|
marquee: function( _msg, _times ) {
|
|
|
|
// let cmp = nx.gui.getComponent( this.node.parent, "view/scenes/MainScene/marqueec", "cmp.message.marquee" );
|
|
let cmp = nx.gui.getComponent( this, "marquee", "cmp.message.marquee" );
|
|
if( cmp ) {
|
|
cmp.push( _msg, _times || 1 );
|
|
}
|
|
|
|
},
|
|
|
|
});
|