Files
fc/dev/project/library/imports/00/00bbadd2-62e0-4dbe-80c8-04b6339ec125.js
2026-05-24 10:21:26 +08:00

109 lines
2.5 KiB
JavaScript

"use strict";
cc._RF.push(module, '00bba3SYuBNvoDIBLYznsEl', 'cmp.message.box');
// Scripts/nx/cmp/message/cmp.message.box.js
"use strict";
/*******************************************************************************
*
* 消息框
*
*
*
* 2021.12.10
******************************************************************************/
cc.Class({
"extends": cc.Component,
properties: {
nodContent: {
"default": null,
type: cc.Node,
displayName: "内容框"
},
btnClose: {
"default": null,
type: cc.Node,
displayName: "关闭按钮"
},
nodChoices: {
"default": null,
type: cc.Node,
displayName: "选择面板"
},
btnChoices: {
"default": [],
type: cc.Node,
displayName: "选项数组"
}
},
// 载入
onLoad: function onLoad() {
// Rich宽度限制修正
var rich = nx.gui.getComponent(this.nodContent, "rich", cc.RichText);
if (rich) {
rich.maxWidth = this.nodContent.width;
}
},
// 设置
show: function show(_text, _keys, _cb, _mgrcb) {
this.callback = _cb;
this.mgrCB = _mgrcb;
// 文本
if (this.nodContent) {
var txt = nx.text.getKey(_text);
var pos = Math.max(txt.search("/>"), txt.search("</"));
var rich = pos != -1;
nx.gui.setString(this.nodContent, "txt", rich ? "" : txt);
nx.gui.setStringRich(this.nodContent, "rich", rich ? txt : "");
}
// 没选择按钮只显示关闭
if (nx.dt.arrEmpty(_keys)) {
this.btnClose.active = true;
this.nodChoices.active = false;
return;
}
this.btnClose.active = _keys.length == 1;
this.nodChoices.active = true;
// 按钮重置
for (var i = 0; i < this.btnChoices.length; ++i) {
var key = _keys[i];
var btn = this.btnChoices[i];
if (nx.dt.strEmpty(key)) {
btn.active = false;
} else {
btn.active = true;
btn.key = key;
nx.gui.setString(btn, "panel/txt", nx.text.format(key));
}
}
},
// 点击选项
onTouchBtn: function onTouchBtn(_btn) {
this._notify(_btn.key);
},
// 关闭
onTouchClose: function onTouchClose() {
this._notify("close");
},
// 删除
close: function close() {
this.node.removeFromParent(true);
if (nx.dt.fnGood(this.mgrCB)) {
this.mgrCB();
}
},
// 通告
_notify: function _notify(_key) {
if (this.callback) {
this.callback(_key, this);
} else {
this.close();
}
}
});
cc._RF.pop();