Files

139 lines
3.8 KiB
JavaScript
Raw Permalink Normal View History

2026-05-23 22:10:14 +08:00
/******************************************************************
*
* 召唤规则说明
*
******************************************************************/
const BridgeWindow = require( "bridge.window" );
const FxSVC = require( "nx.fx.sv.expand" );
const HEADER_ID = 1;
const LIST_IDS = [ 2, 5 ];
cc.Class( {
extends: BridgeWindow,
properties: {
nodHead: { default: null, type: cc.Node },
nodList: { default: null, type: cc.Node },
nodRates: { default: null, type: cc.Node },
svcList: { default: null, type: FxSVC },
},
// 重载:参数打开
onOpenConfigs: function( _params = {} ) {
let key = _params.key || 'recruit_data';
this.cfgs = game.configs[key];
if( nx.dt.objEmpty( this.cfgs ) ) {
return;
}
// 重建列表
this.rebuild();
this.nodRates.active = false;
},
// 重建列表
rebuild: function() {
// 表头
let data = this.cfgs ? this.cfgs.data_explain : null;
if( nx.dt.objEmpty( data ) ) {
return;
}
let head = data ? data[ HEADER_ID ] : null;
this.nodHead.active = nx.dt.objNEmpty( head );
if( this.nodHead.active ) {
nx.gui.setString( this.nodHead, "title/txt", nx.text.getKey( head.title ) );
nx.gui.setString( this.nodHead, "txt", nx.text.getKey( head.desc ) );
}
// 召唤明细
let build = function( _node, _data ) {
_node.active = nx.dt.objNEmpty( _data );
if( !_node.active ) {
return;
}
nx.gui.setString( _node, "title/txt", nx.text.getKey( _data.title ) );
let btn = nx.gui.find( _node, "title/detail" );
btn.sumInfos = _data;
let arr = _data.desc.split( "$" );
let cnt = Math.floor( arr.length / 2 );
let root = nx.gui.find( _node, "rates" );
nx.gui.gocChildren( root, "", cnt, root.children[ 0 ] );
for( let i = 0; i < cnt; ++i ) {
let idx = ( i * 2 );
let item = root.children[ i ];
nx.gui.setString( item, "name", nx.text.getKey( arr[ idx ] ) );
nx.gui.setString( item, "rate", arr[ idx + 1 ] );
}
};
// 循环创建
let chds = this.nodList.children;
let count = LIST_IDS[ 1 ] - LIST_IDS[ 0 ] + 1;
nx.gui.gocChildren( this.nodList, "", count, chds[ 0 ] );
for( let i = 0; i < count; ++i ) {
build( chds[ i ], data ? data[ ( i + LIST_IDS[ 0 ] ) ] : null );
};
},
// 具体掉落率
onTouchRate: function( _btn ) {
if( !_btn || nx.dt.objEmpty( _btn.sumInfos ) ) {
return;
}
let gid = 100;
switch( _btn.sumInfos.id ) {
case 2: gid = 100; break;
case 3: gid = 200; break;
case 4: gid = 300; break;
case 5: gid = 400; break;
default: break;
}
let data = this.cfgs ? this.cfgs.data_summon_data : null;
let list = data ? data[gid] : null;
if( nx.dt.objEmpty( data ) ) {
return;
}
let arr = [];
for( let i in list ) {
let t = list[i];
let rate = parseFloat( t.summon_desc ) || 0;
rate = Math.floor( rate * 1000) / 1000;
if( rate > 0 ) {
arr.push( { id: t.id, base_id: t.base_id, rate: rate } );
}
}
// 按几率排序
arr.sort( ( _a, _b ) => {
return _b.rate - _a.rate;
} );
this.svcList.rebuild( arr );
this.nodRates.active = true;
},
// 掉落界面关闭
onCloseRates: function() {
this.nodRates.active = false;
},
} );