Files
fc/dev/project/assets/Scripts/nx/cmp/message/cmp.message.box.js
T
2026-05-23 22:10:14 +08:00

128 lines
2.8 KiB
JavaScript

/*******************************************************************************
*
* 消息框
*
*
*
* 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() {
// Rich宽度限制修正
let rich = nx.gui.getComponent( this.nodContent, "rich", cc.RichText );
if( rich ) {
rich.maxWidth = this.nodContent.width;
}
},
// 设置
show: function( _text, _keys, _cb, _mgrcb ) {
this.callback = _cb;
this.mgrCB = _mgrcb;
// 文本
if( this.nodContent ) {
let txt = nx.text.getKey( _text );
let pos = Math.max( txt.search( "/>" ), txt.search( "</" ) );
let 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( let 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( _btn ) {
this._notify( _btn.key );
},
// 关闭
onTouchClose: function() {
this._notify( "close" );
},
// 删除
close: function() {
this.node.removeFromParent( true );
if( nx.dt.fnGood( this.mgrCB ) ) {
this.mgrCB();
}
},
// 通告
_notify: function( _key ) {
if( this.callback ) {
this.callback( _key, this );
} else {
this.close();
}
},
} );