Files
fc/dev/project/library/imports/21/2127e2b0-167d-4c37-8bbe-fc60be1b5193.js
T
2026-05-24 10:21:26 +08:00

238 lines
5.7 KiB
JavaScript

"use strict";
cc._RF.push(module, '2127eKwFn1MN4u+/GC+G1GT', 'wnd.message');
// Scripts/nx/cmp/message/wnd.message.js
"use strict";
/*******************************************************************************
*
* 消息UI管理
*
*
*
* 2021.12.10
******************************************************************************/
var SEC_FadeIn = 0.3;
var SEC_Delay = 0.7;
var 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 onLoad() {
// 全局服务
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 onDestroy() {
if (window.nx) {
// 全局服务
nx.msgUI = null;
}
// 全部关闭
// this.closeAll();
},
// 全部关闭
closeAll: function closeAll() {
// 计时器销毁
this.unscheduleAllCallbacks();
this.tipCur = "";
this.boxQueue = [];
this.tipQueue = [];
this.rootBox.removeAllChildren();
this.rootTips.removeAllChildren();
},
/***
* *********************************************************************
* 弹窗
* *********************************************************************
*/
// 弹窗提示
popBox: function popBox(_text, _btns, _cb, _skey) {
if (_skey === void 0) {
_skey = "";
}
var boxes = this.rootBox.children;
// 唯一性查找
if (nx.dt.strNEmpty(_skey) && boxes.length > 0) {
for (var 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, function () {});
},
// 指定关闭弹框
closeBox: function closeBox(_skey) {
if (nx.dt.strEmpty(_skey)) {
return;
}
var boxes = this.rootBox.children;
for (var i in boxes) {
var box = boxes[i];
if (box && box.skey == _skey) {
box.removeFromParent(true);
break;
}
}
},
// 蒙版刷新
_onFreshMask: function _onFreshMask() {
var count = this.rootBox.childrenCount;
nx.gui.setActive(this.rootBox, "mask", count > 1);
},
/***
* *********************************************************************
* 轻态
* *********************************************************************
*/
// 轻态提示
popTip: function popTip(_text) {
// 空处理
if (nx.dt.strEmpty(_text)) {
nx.error("创建轻态提示失败,条件不足!");
return;
}
// 去重
var 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 _nextTip() {
var _this = this;
// 空结束
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")
};
}
// 弹出一条
var txt = this.tipQueue.shift();
if (nx.dt.strEmpty(txt)) {
this._nextTip();
return;
}
// 弹出有效 && 实例化
this.tipCur = txt;
// 弹窗处理
var pos = Math.max(txt.search("/>"), txt.search("</"));
var key = pos != -1 ? "tboxRc" : "tbox";
var temp = nx.gui.find(this.nodTmp, key);
// 文本设置
var tip = cc.instantiate(temp);
var 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(function () {
_this._nextTip();
}).to(SEC_FadeOut, {
position: this.popPath.end.position,
opacity: 0
}) //, { easing: "cubicOut" } )
.removeSelf().start();
},
/***
* *********************************************************************
* 跑马灯
* *********************************************************************
*/
marquee: function marquee(_msg, _times) {
// let cmp = nx.gui.getComponent( this.node.parent, "view/scenes/MainScene/marqueec", "cmp.message.marquee" );
var cmp = nx.gui.getComponent(this, "marquee", "cmp.message.marquee");
if (cmp) {
cmp.push(_msg, _times || 1);
}
}
});
cc._RF.pop();