117 lines
3.1 KiB
JavaScript
117 lines
3.1 KiB
JavaScript
import SKUIUtil from "../ts/gear_2.3.4/util/SKUIUtil";
|
|
|
|
class CScreenNoticeMgr {
|
|
constructor() {
|
|
this.vecMsg = [];
|
|
this.goScreenNotice = null;
|
|
this.goRichText = null;
|
|
this.goRichTextBg = null;
|
|
this.bInUsing = false;
|
|
}
|
|
|
|
Reset() {
|
|
this.vecMsg = [];
|
|
this.goScreenNotice = null;
|
|
this.goRichText = null;
|
|
this.goRichTextBg = null;
|
|
this.bInUsing = false;
|
|
}
|
|
|
|
AddNotice(strRichText, bFront) {
|
|
if (bFront == 1) {
|
|
this.ShowOrHiden(false);
|
|
if (this.vecMsg.length > 0) {
|
|
this.vecMsg.splice(0, 0, strRichText);
|
|
}
|
|
}
|
|
else {
|
|
this.vecMsg.push(strRichText);
|
|
}
|
|
this.CheckAndShowNotice();
|
|
}
|
|
|
|
OnUpdate(nIndex) {
|
|
}
|
|
|
|
ShowOrHiden(bShow) {
|
|
this.bInUsing = bShow;
|
|
if (!SKUIUtil.isValid(this.goScreenNotice)) {
|
|
cc.warn(`$警告:屏幕通知節點無效!`);
|
|
return;
|
|
}
|
|
this.goScreenNotice.active = true;
|
|
this.goScreenNotice.y = this.bInUsing ? 156 : 2000;
|
|
}
|
|
|
|
CheckAndShowNotice() {
|
|
if (this.goScreenNotice == null) {
|
|
this.goScreenNotice = cc.find('Canvas/MainUI/Notice');
|
|
if (null == this.goScreenNotice)
|
|
return;
|
|
}
|
|
|
|
if (this.goRichText == null) {
|
|
this.goRichText = cc.find('Canvas/MainUI/Notice/Mask/bg/notice_label');
|
|
if (null == this.goRichText)
|
|
return;
|
|
}
|
|
|
|
if (this.goRichTextBg == null) {
|
|
this.goRichTextBg = cc.find('Canvas/MainUI/Notice/Mask/bg');
|
|
if (null == this.goRichTextBg)
|
|
return;
|
|
}
|
|
|
|
if (this.bInUsing == true)
|
|
return;
|
|
|
|
if (this.vecMsg.length <= 0)
|
|
return;
|
|
|
|
this.ShowOrHiden(true);
|
|
if (!SKUIUtil.isValid(this.goRichText)) {
|
|
cc.warn(`$警告:屏幕無效的富文本節點`);
|
|
this.bInUsing = false;
|
|
return;
|
|
}
|
|
|
|
if (!SKUIUtil.isValid(this.goRichTextBg)) {
|
|
cc.warn(`$警告:屏幕無效的富文本節點`);
|
|
this.bInUsing = false;
|
|
return;
|
|
}
|
|
var sss = this.vecMsg[0]
|
|
var hasColor = /\<color=#(?:[0-9]|[a-f]|[A-F]){6} \>/g;
|
|
var newStr = sss.replace(hasColor, "<color=#000000>")
|
|
var str = this.vecMsg.shift()
|
|
this.goRichTextBg.getComponent(cc.RichText).string = newStr
|
|
this.goRichText.getComponent(cc.RichText).string = str
|
|
this.goRichTextBg.stopAllActions();
|
|
this.goRichTextBg.x = 102;
|
|
let self = this;
|
|
this.goRichTextBg.runAction(cc.sequence(cc.moveTo(8, cc.v2(-1000, this.goRichText.y)), cc.callFunc(() => {
|
|
self.bInUsing = false;
|
|
if (self.vecMsg.length > 0) {
|
|
self.CheckAndShowNotice();
|
|
} else {
|
|
self.ShowOrHiden(false);
|
|
}
|
|
})));
|
|
}
|
|
}
|
|
|
|
|
|
//---------------------------
|
|
|
|
|
|
let pScreenNoticeMgr = null;
|
|
|
|
module.exports = (() => {
|
|
if (pScreenNoticeMgr == null) {
|
|
pScreenNoticeMgr = new CScreenNoticeMgr();
|
|
}
|
|
return pScreenNoticeMgr;
|
|
})();
|
|
|
|
|