Files
fc/dev/project/assets/Scripts/mod/backpack/cmps/cmp.item.layout.js
T
2026-05-23 22:10:14 +08:00

70 lines
1.6 KiB
JavaScript

/******************************************************************
*
* 简单道具列表(id,数量)
*
* 2018.05.18
******************************************************************/
cc.Class( {
extends: cc.Component,
properties: {
maxCount: {
default: 10,
displayName: "上限"
},
fabItem: {
default: null,
type: cc.Prefab,
displayName: "道具预制"
},
},
// 编辑器特性
editor: {
// 允许当前组件在编辑器模式下运行
executeInEditMode: false,
// 当本组件添加到节点上后,禁止同类型(含子类)的组件再添加到同一个节点,防止逻辑发生冲突
disallowMultiple: false,
// requireComponent 参数用来指定当前组件的依赖组件
requireComponent: cc.Layout,
},
// 重建列表
// [[id,count]]
rebuild: function( _items ) {
// 清空
if( nx.dt.arrEmpty( _items ) ) {
nx.pools.putChildren( this.node );
return;
}
// 重建
let pool = nx.pools.getPool( this.fabItem.name, this.fabItem );
let max = Math.min( _items.length, this.maxCount );
for( let i = 0; i < max; ++i ) {
let node = this.node.children[ i ];
if( !node ) {
node = pool.get();
node.parent = this.node;
}
let item = _items[ i ];
let cmp = node.getComponent( "cmp.item.base" );
cmp.setData( item );
}
},
} );