add_animation.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import { _decorator, Button, Component, instantiate, Node, Prefab } from 'cc';
  2. import { config } from '../../config';
  3. import { add_animation_item } from './add_animation_item';
  4. import { att_ani_data } from '../../../data/data';
  5. import { Attributes } from '../Attributes';
  6. import { tools } from '../../tools';
  7. import { new_animation } from './new_animation';
  8. import { edit_animation } from './edit_animation';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('add_animation')
  11. export class add_animation extends Component {
  12. @property(Node) content:Node = null;
  13. @property(Node) btn_close:Node = null;
  14. @property(Prefab) item_prefab:Prefab = null;
  15. @property(Node) btn_add_animation:Node = null;
  16. @property(Node) btn_delete_animation:Node = null;
  17. @property(Node) btn_edit_animation:Node = null;
  18. @property(Node) new_animation_node:Node = null;
  19. @property(Node) edit_animation_node:Node = null;
  20. private call_back = null;
  21. private m_list:att_ani_data[] = []
  22. private cur_select:add_animation_item = null;
  23. public show(list:att_ani_data[],call){
  24. this.call_back = call;
  25. this.m_list = list;
  26. this.updateView()
  27. this.btn_close.on(Node.EventType.TOUCH_END,()=>{
  28. this.close()
  29. })
  30. this.btn_edit_animation.on(Node.EventType.TOUCH_END,()=>{
  31. if(this.m_list.length<=0){
  32. return tools.showToast("无动画可编辑!")
  33. }
  34. this.edit_animation_node.getComponent(edit_animation).show(this.cur_select.getData())
  35. })
  36. this.new_animation_node.getComponent(new_animation).initView(this.onCreateAni.bind(this))
  37. this.btn_add_animation.on(Node.EventType.TOUCH_END,()=>{
  38. this.new_animation_node.getComponent(new_animation).show(this.m_list.length, Attributes.Singleton.get_cur_att_data().id)
  39. })
  40. this.btn_delete_animation.on(Node.EventType.TOUCH_END,()=>{
  41. if(this.m_list.length<=0){
  42. return tools.showToast("无动画可删除!")
  43. }
  44. tools.show_dialog("是否删除当前选中的动画?",()=>{
  45. this.m_list.splice(this.cur_select.getIndex(),1)
  46. this.cur_select.node.removeFromParent()
  47. if(this.m_list.length<=0){
  48. this.btn_delete_animation.getComponent(Button).interactable = false;
  49. }else{
  50. this.cur_select = this.content.children[this.content.children.length-1].getComponent(add_animation_item)
  51. this.cur_select.selectStatus()
  52. }
  53. if(this.call_back!=null){
  54. this.call_back(this.m_list)
  55. }
  56. })
  57. })
  58. this.btn_edit_animation.getComponent(Button).interactable = list.length<=0?false:true
  59. this.btn_delete_animation.getComponent(Button).interactable = list.length<=0?false:true
  60. }
  61. updateView(){
  62. this.content.removeAllChildren()
  63. for (let index = 0; index < this.m_list.length; index++) {
  64. const element = this.m_list[index];
  65. let item = instantiate(this.item_prefab)
  66. item.parent = this.content;
  67. item.getComponent(add_animation_item).initView(element,this.onItemClick.bind(this),index)
  68. if(index===0){
  69. item.getComponent(add_animation_item).selectStatus()
  70. this.cur_select = item.getComponent(add_animation_item);
  71. }
  72. }
  73. }
  74. onCreateAni(d:att_ani_data){
  75. this.m_list.push(d)
  76. this.updateView()
  77. this.btn_edit_animation.getComponent(Button).interactable = this.m_list.length<=0?false:true
  78. this.btn_delete_animation.getComponent(Button).interactable = this.m_list.length<=0?false:true
  79. if(this.call_back!=null){
  80. this.call_back(this.m_list)
  81. }
  82. }
  83. onItemClick(item:add_animation_item){
  84. for (let index = 0; index < this.content.children.length; index++) {
  85. const element = this.content.children[index];
  86. element.getComponent(add_animation_item).unSelectStatus()
  87. }
  88. item.selectStatus()
  89. this.cur_select = item;
  90. this.btn_edit_animation.getComponent(Button).interactable = true;
  91. this.btn_delete_animation.getComponent(Button).interactable = true
  92. }
  93. close(){
  94. this.node.destroy()
  95. }
  96. }