220 lines
6.4 KiB
JavaScript
220 lines
6.4 KiB
JavaScript
/******************************************************************
|
|
*
|
|
* 伙伴选择界面
|
|
*
|
|
******************************************************************/
|
|
const BridgeWindow = require( "bridge.window" );
|
|
const FxSVC = require( "nx.fx.sv.expand" );
|
|
const BackPackConst = require( "backpack_const" );
|
|
|
|
|
|
cc.Class( {
|
|
|
|
extends: BridgeWindow,
|
|
|
|
properties: {
|
|
|
|
nodRoot: { default: null, type: cc.Node },
|
|
svcList: { default: null, type: FxSVC },
|
|
nodCount: { default: null, type: cc.Node },
|
|
|
|
},
|
|
|
|
// 重载:参数打开
|
|
onOpenConfigs: function( _params ) {
|
|
|
|
/**
|
|
* params {
|
|
* partners: 列表,
|
|
* count: 选择上限,
|
|
* selects: 已选择,
|
|
* fnSelector: 选择验证(默认空)
|
|
* fixed: 是否固定选择上限数(默认false)
|
|
* flag: 特殊标记 }
|
|
*/
|
|
// 参数判定
|
|
this.params = _params.params;
|
|
this.cb = _params.cb || [];
|
|
|
|
// 重建
|
|
this.rebuild();
|
|
},
|
|
|
|
// 重载:关闭前
|
|
onPreClosed: function() {
|
|
|
|
this.svcList.rebuild( [] );
|
|
},
|
|
|
|
// 重建
|
|
rebuild: function() {
|
|
|
|
if( this.params.flag ){
|
|
|
|
let path = cc.path.join( "coms/images", "star" + this.params.flag.star );
|
|
let color = BackPackConst.quality_color( this.params.flag.star );
|
|
let cur = nx.gui.find( this.nodRoot, "star/type" ).color;
|
|
cur.fromHEX( color );
|
|
nx.gui.find( this.nodRoot, "star/type" ).color = cur;
|
|
nx.gui.setSpriteFrame( this.nodRoot, "star/star", path );
|
|
nx.gui.setString( this.nodRoot, "star/type", nx.text.getKey( this.params.flag.type ) );
|
|
}
|
|
nx.gui.setActive( this.nodRoot, "star", this.params.flag );
|
|
|
|
// 空
|
|
let empty = nx.dt.arrEmpty( this.params.partners );
|
|
nx.gui.setActive( this.nodRoot, "empty", empty );
|
|
nx.gui.setActive( this.nodRoot, "panel", !empty );
|
|
if( empty ) {
|
|
nx.gui.setString( this.nodRoot, "star/count", `${0}/${this.params.count}` );
|
|
nx.gui.setActive( this.nodRoot, "star/count", empty );
|
|
return;
|
|
}
|
|
|
|
// 重建
|
|
this.svcList.rebuild( this.params.partners );
|
|
|
|
let num = 0;
|
|
// 已选中
|
|
let selects = this.params.selects || [];
|
|
for( let i = 0; i < this.params.partners.length; ++i ) {
|
|
let partner = this.params.partners[ i ];
|
|
if( partner && nx.dt.arrMember( selects, null, ( _p ) => {
|
|
return _p.partner_id == partner.partner_id;
|
|
} ) ) {
|
|
num++;
|
|
if( num <= selects.length ){
|
|
this.svcList.addFocus( i );
|
|
}
|
|
|
|
}
|
|
}
|
|
// 数量更新
|
|
this.freshCount();
|
|
|
|
|
|
|
|
},
|
|
|
|
// 数量更新
|
|
freshCount: function() {
|
|
|
|
let key = "";
|
|
let total = this.params.count;
|
|
if( total > 1 ) {
|
|
let cnt = this.svcList.focusList.length;
|
|
key = `${cnt}/${total}`;
|
|
}
|
|
nx.gui.setString( this.nodCount, "", key );
|
|
nx.gui.setString( this.nodRoot, "star/count", `${this.svcList.focusList.length}/${total}` );
|
|
nx.gui.setActive( this.nodRoot, "star/count", nx.dt.strEmpty( key ) );
|
|
},
|
|
|
|
// 选中切换
|
|
onFocusChanged: function( _item ) {
|
|
|
|
// 空
|
|
if( nx.dt.objEmpty( _item ) ||
|
|
nx.dt.objEmpty( _item.mdata ) ) {
|
|
return;
|
|
}
|
|
|
|
// 取消选中
|
|
if( this.svcList.isFocus( _item.index ) ) {
|
|
this.svcList.removeFocus( _item.index );
|
|
this.freshCount();
|
|
return;
|
|
}
|
|
|
|
// 选择验证
|
|
if( nx.dt.fnGood( this.params.fnSelector ) &&
|
|
!this.params.fnSelector( this, _item.mdata ) ) {
|
|
return;
|
|
}
|
|
|
|
// 是不是单选
|
|
let single = ( this.params.count == 1 );
|
|
if( single ) {
|
|
this.svcList.cleanFocus();
|
|
this.svcList.addFocus( _item.index );
|
|
this.freshCount();
|
|
return;
|
|
}
|
|
|
|
// 选中添加
|
|
if( this.svcList.focusList.length < this.params.count ) {
|
|
this.svcList.addFocus( _item.index );
|
|
this.freshCount();
|
|
return;
|
|
}
|
|
|
|
},
|
|
|
|
// 点击确认
|
|
onTouchConfirm: function() {
|
|
|
|
// 统计所选
|
|
let ret = [];
|
|
this.svcList.focusList.forEach( _idx => {
|
|
ret.push( this.params.partners[ _idx ] );
|
|
} );
|
|
|
|
// 返回
|
|
nx.dt.fnInvoke( this.cb, ret );
|
|
},
|
|
|
|
// // 根据Flag筛选伙伴列表
|
|
// fliterPartners: function( _flag ) {
|
|
|
|
// this.params.partners = [];
|
|
// let model = HeroController.getInstance().getModel();
|
|
|
|
// // 根据Flag确认不同的筛选方式
|
|
// // 0:升星标准参数 1:重生单选 2:复活单选
|
|
// switch( _flag ) {
|
|
|
|
// // 2:复活单选
|
|
// case 2: {
|
|
|
|
// let conds = {};
|
|
// let config = gconfig( "partner_data", "data_partner_const", "reborn_condition" );
|
|
// if( config && config.val ) {
|
|
// for( let i in config.val ) {
|
|
// let v = config.val[ i ];
|
|
// if( conds[ v[ 1 ] ] == null ) {
|
|
// conds[ v[ 1 ] ] = {}
|
|
// }
|
|
// conds[ v[ 1 ] ][ v[ 2 ] ] = true
|
|
// }
|
|
// }
|
|
// let all = model.getHeroList() || []
|
|
// for( let k in all ) {
|
|
// let partner = all[ k ];
|
|
// if( !conds[ partner.bid ] || !conds[ partner.bid ][ partner.star ] ) {
|
|
// continue;
|
|
// }
|
|
|
|
// // 非排除英雄
|
|
// // if( nx.dt.arrMember( this.excludes, null, ( _m ) => {
|
|
// // return _m.partner_id == partner_id;
|
|
// // } ) ) {
|
|
// // continue;
|
|
// // };
|
|
// this.params.partners.push( partner );
|
|
// }
|
|
// } break;
|
|
|
|
// // 0:升星标准参数
|
|
// default: {
|
|
// } break;
|
|
|
|
// };
|
|
|
|
// // 排序
|
|
// let sort_func = Utils.tableLowerSorter( [ "camp_type", "star", "bid" ] )
|
|
// this.params.partners.sort( sort_func );
|
|
|
|
// },
|
|
|
|
} );
|