select_animation.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { _decorator, Component, instantiate, Node, Prefab } from 'cc';
  2. import { att_ani_data, attributes_data } from '../../../data/data';
  3. import { add_animation_item } from './add_animation_item';
  4. import { tools } from '../../tools';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('select_animation')
  7. export class select_animation extends Component {
  8. @property(Node) content:Node = null;
  9. @property(Node) btn_close:Node = null;
  10. @property(Prefab) item_prefab:Prefab = null;
  11. private call_back = null;
  12. private m_list:att_ani_data[] = []
  13. protected start(): void {
  14. this.btn_close.on(Node.EventType.TOUCH_END,()=>{
  15. this.close()
  16. })
  17. }
  18. public show(list:att_ani_data[],call,id:number=-1){
  19. this.m_list = list;
  20. this.call_back = call;
  21. for (let index = 0; index < this.m_list.length; index++) {
  22. const element = this.m_list[index];
  23. let item = instantiate(this.item_prefab)
  24. item.parent = this.content;
  25. item.getComponent(add_animation_item).initView(element,this.onItemClick.bind(this),index)
  26. if(id===element.ani_id){
  27. item.getComponent(add_animation_item).selectStatus()
  28. }
  29. }
  30. }
  31. public showWithDelete(list:att_ani_data[],call,id:number=-1){
  32. this.m_list = list;
  33. this.call_back = call;
  34. for (let index = 0; index < this.m_list.length; index++) {
  35. const element = this.m_list[index];
  36. let item = instantiate(this.item_prefab)
  37. item.parent = this.content;
  38. item.getComponent(add_animation_item).initViewWithDelete(element,this.onItemClick.bind(this),this.onItemDeleteClick.bind(this),index)
  39. }
  40. }
  41. onItemClick(item:add_animation_item){
  42. if(this.call_back!=null){
  43. this.call_back(item.getData())
  44. }
  45. this.close()
  46. }
  47. onItemDeleteClick(item:add_animation_item) {
  48. this.m_list.splice(item.getIndex(),1)
  49. this.content.removeAllChildren()
  50. for (let index = 0; index < this.m_list.length; index++) {
  51. const element = this.m_list[index];
  52. let item = instantiate(this.item_prefab)
  53. item.parent = this.content;
  54. item.getComponent(add_animation_item).initViewWithDelete(element,this.onItemClick.bind(this),this.onItemDeleteClick.bind(this),index)
  55. }
  56. tools.requestSyncAnimationList(this.m_list)
  57. }
  58. close(){
  59. this.node.destroy()
  60. }
  61. }