select_animation.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { _decorator, Component, instantiate, Node, Prefab } from 'cc';
  2. import { att_ani_data } from '../../../data/data';
  3. import { add_animation_item } from './add_animation_item';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('select_animation')
  6. export class select_animation extends Component {
  7. @property(Node) content:Node = null;
  8. @property(Node) btn_close:Node = null;
  9. @property(Prefab) item_prefab:Prefab = null;
  10. private call_back = null;
  11. private m_list:att_ani_data[] = []
  12. public show(list:att_ani_data[],call,id:number=-1){
  13. this.m_list = list;
  14. this.call_back = call;
  15. for (let index = 0; index < this.m_list.length; index++) {
  16. const element = this.m_list[index];
  17. let item = instantiate(this.item_prefab)
  18. item.parent = this.content;
  19. item.getComponent(add_animation_item).initView(element,this.onItemClick.bind(this),index)
  20. if(id===element.ani_id){
  21. item.getComponent(add_animation_item).selectStatus()
  22. }
  23. }
  24. this.btn_close.on(Node.EventType.TOUCH_END,()=>{
  25. this.close()
  26. })
  27. }
  28. onItemClick(item:add_animation_item){
  29. if(this.call_back!=null){
  30. this.call_back(item.getData())
  31. }
  32. this.close()
  33. }
  34. close(){
  35. this.node.destroy()
  36. }
  37. }