83 lines
1.9 KiB
JavaScript
83 lines
1.9 KiB
JavaScript
|
|
/******************************************************************
|
||
|
|
*
|
||
|
|
* 引导改名
|
||
|
|
*
|
||
|
|
******************************************************************/
|
||
|
|
|
||
|
|
const BridgeWindow = require( "bridge.window" );
|
||
|
|
const FxButton = require( "nx.fx.button" );
|
||
|
|
const RoleController = require( "role_controller" );
|
||
|
|
|
||
|
|
cc.Class( {
|
||
|
|
|
||
|
|
extends: BridgeWindow,
|
||
|
|
|
||
|
|
properties: {
|
||
|
|
|
||
|
|
edtInput: { default: null, type: cc.EditBox },
|
||
|
|
btnComfirm: { default: null, type: FxButton },
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 重载:参数打开
|
||
|
|
onOpenConfigs: function( _params ) {
|
||
|
|
|
||
|
|
nx.gui.setString( this.edtInput, "", "" );
|
||
|
|
|
||
|
|
// 读取名字库
|
||
|
|
let path = cc.path.join( "locals", nx.getLocLanguage(), "names" );
|
||
|
|
nx.res.loadJson( path, ( _err, _data ) => {
|
||
|
|
if( _err ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
this.lib = _data;
|
||
|
|
this.onTouchRandom();
|
||
|
|
} );
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 随机名字
|
||
|
|
onTouchRandom: function() {
|
||
|
|
|
||
|
|
if( nx.dt.objEmpty( this.lib ) ) {
|
||
|
|
nx.warn( "$PlotRename:随机名字失败,空库!" );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
let name = "";
|
||
|
|
for( let i in this.lib.data_list ) {
|
||
|
|
let list = this.lib.data_list[i];
|
||
|
|
if( nx.dt.arrNEmpty( list ) ) {
|
||
|
|
let ridx = nx.dt.randomRange( 0, list.length - 1 );
|
||
|
|
name += list[ridx].name;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
nx.gui.setString( this.edtInput, "", name );
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 确定
|
||
|
|
onConfirm: function() {
|
||
|
|
|
||
|
|
let str = this.edtInput.string;
|
||
|
|
if( nx.dt.strEmpty( str ) ) {
|
||
|
|
nx.tbox( "PLRenameEmptyInput" );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
let rc = RoleController.getInstance();
|
||
|
|
rc.changeRoleName( str, 0, ( _ret, _data ) => {
|
||
|
|
|
||
|
|
if( !_ret ) {
|
||
|
|
nx.tbox( _data );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
this.close();
|
||
|
|
} );
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
} );
|