import { ItemList } from "../../../../ItemList/ItemList" ; import { Item } from "../../../../ItemList/Item" ; import BattleFiledItem from "./BattleFiledItem" ; import { BattleFiledData } from "./BattleFiledData" ; import { Debug } from "../../../../Common/Debug" ; const { ccclass , property } = cc . _decorator ; @ ccclass export default class BattleFiledList extends ItemList < BattleFiledData > { private _datas : Array < BattleFiledData > = new Array ( ) ; @ property ( cc . Prefab ) public BattleFiledItem ; public ApplyData ( datas ) { if ( datas == null || datas . length == 0 ) { return ; } this . _datas = new Array ( ) ; for ( let index = 0 ; index < datas . length ; index ++ ) { const element = datas [ index ] ; this . _datas . push ( element ) ; } this . selectEmpty ( ) ; this . refreshContent ( ) ; this . DestroyItemOnDisable ( ) ; } slotCount ( ) { return this . _datas . length ; } createItem ( ) { let prefab = window . appContext . Pool . requestInstant ( this . BattleFiledItem ) ; if ( prefab == null ) { return null ; } let item = prefab . getComponent ( "BattleFiledItem" ) ; return item ; } dataUpdateTime ( ) { return 0 ; } dataCount ( ) { return this . _datas . length ; } getData ( index ) { if ( index < 0 || index > this . slotCount ( ) ) { return null ; } return this . _datas [ index ] ; } onItemSelected ( item ) { Debug . log ( "onItemSelected" ) ; return ; } public GetParentBattleFieldItems ( battleFiledItem ) { let data = battleFiledItem . getData ( ) ; let parentIds = data . parents ; let parentBattleFiledItems = new Array < BattleFiledItem > ( ) ; if ( parentIds == null || parentIds . length == 0 ) { return parentBattleFiledItems ; } for ( let i = 0 ; i < this . _datas . length ; i ++ ) { let item = this . getItem ( i ) as BattleFiledItem ; let currentData = item . getData ( ) ; for ( let j = 0 ; j < parentIds . length ; j ++ ) { if ( currentData . key == parentIds [ j ] ) { parentBattleFiledItems . push ( item ) ; continue ; } } } return parentBattleFiledItems ; } }