import { _decorator, Component, instantiate, Node, Prefab } from 'cc'; import { att_ani_data, attributes_data } from '../../../data/data'; import { add_animation_item } from './add_animation_item'; import { tools } from '../../tools'; const { ccclass, property } = _decorator; @ccclass('select_animation') export class select_animation extends Component { @property(Node) content:Node = null; @property(Node) btn_close:Node = null; @property(Prefab) item_prefab:Prefab = null; private call_back = null; private m_list:att_ani_data[] = [] protected start(): void { this.btn_close.on(Node.EventType.TOUCH_END,()=>{ this.close() }) } public show(list:att_ani_data[],call,id:number=-1){ this.m_list = list; this.call_back = call; for (let index = 0; index < this.m_list.length; index++) { const element = this.m_list[index]; let item = instantiate(this.item_prefab) item.parent = this.content; item.getComponent(add_animation_item).initView(element,this.onItemClick.bind(this),index) if(id===element.ani_id){ item.getComponent(add_animation_item).selectStatus() } } } public showWithDelete(list:att_ani_data[],call,id:number=-1){ this.m_list = list; this.call_back = call; for (let index = 0; index < this.m_list.length; index++) { const element = this.m_list[index]; let item = instantiate(this.item_prefab) item.parent = this.content; item.getComponent(add_animation_item).initViewWithDelete(element,this.onItemClick.bind(this),this.onItemDeleteClick.bind(this),index) } } onItemClick(item:add_animation_item){ if(this.call_back!=null){ this.call_back(item.getData()) } this.close() } onItemDeleteClick(item:add_animation_item) { this.m_list.splice(item.getIndex(),1) this.content.removeAllChildren() for (let index = 0; index < this.m_list.length; index++) { const element = this.m_list[index]; let item = instantiate(this.item_prefab) item.parent = this.content; item.getComponent(add_animation_item).initViewWithDelete(element,this.onItemClick.bind(this),this.onItemDeleteClick.bind(this),index) } tools.requestSyncAnimationList(this.m_list) } close(){ this.node.destroy() } }