146 lines
3.4 KiB
JavaScript
146 lines
3.4 KiB
JavaScript
/******************************************************************
|
|
*
|
|
* 道具选择界面
|
|
*
|
|
******************************************************************/
|
|
|
|
const BridgeWindow = require( "bridge.window" );
|
|
const FxSVC = require( "nx.fx.sv.expand" );
|
|
|
|
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 {
|
|
* items: 列表,
|
|
* count: 选择上限,
|
|
* selects: 已选择,
|
|
* fnSelector: 选择验证(默认空)
|
|
* fixed: 是否固定选择上限数(默认false)
|
|
* flag: 特殊标记 }
|
|
*/
|
|
// 参数判定
|
|
this.params = _params.params;
|
|
this.cb = _params.cb || [];
|
|
|
|
// 重建
|
|
this.rebuild();
|
|
},
|
|
|
|
// 重载:关闭前
|
|
onPreClosed: function() {
|
|
|
|
this.svcList.rebuild( [] );
|
|
},
|
|
|
|
// 重建
|
|
rebuild: function() {
|
|
|
|
// 空
|
|
let empty = nx.dt.arrEmpty( this.params.items );
|
|
nx.gui.setActive( this.nodRoot, "empty", empty );
|
|
nx.gui.setActive( this.nodRoot, "panel", !empty );
|
|
if( empty ) {
|
|
return;
|
|
}
|
|
|
|
// 重建
|
|
this.svcList.rebuild( this.params.items );
|
|
|
|
// 已选中
|
|
let selects = this.params.selects || [];
|
|
for( let i = 0; i < this.params.items.length; ++i ) {
|
|
let tm = this.params.items[ i ];
|
|
if( tm && nx.dt.arrMember( selects, null, ( _p ) => {
|
|
return _p.id == tm.id;
|
|
} ) ) {
|
|
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 );
|
|
|
|
},
|
|
|
|
// 选中切换
|
|
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.items[ _idx ] );
|
|
} );
|
|
|
|
// 返回
|
|
nx.dt.fnInvoke( this.cb, ret );
|
|
},
|
|
|
|
} );
|