add_animation.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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) btn_select_server_animation:Node = null;
  19. @property(Node) btn_set_server_animation:Node = null;
  20. @property(Node) new_animation_node:Node = null;
  21. @property(Node) edit_animation_node:Node = null;
  22. private call_back = null;
  23. private m_list:att_ani_data[] = []
  24. private cur_select:add_animation_item = null;
  25. public show(list:att_ani_data[],call){
  26. this.call_back = call;
  27. this.m_list = list;
  28. this.updateView()
  29. this.btn_close.on(Node.EventType.TOUCH_END,()=>{
  30. this.close()
  31. })
  32. this.btn_edit_animation.on(Node.EventType.TOUCH_END,()=>{
  33. if(this.m_list.length<=0){
  34. return tools.showToast("无动画可编辑!")
  35. }
  36. this.edit_animation_node.getComponent(edit_animation).show(this.cur_select.getData())
  37. })
  38. this.new_animation_node.getComponent(new_animation).initView(this.onCreateAni.bind(this))
  39. this.btn_add_animation.on(Node.EventType.TOUCH_END,()=>{
  40. this.new_animation_node.getComponent(new_animation).show(this.m_list.length, Attributes.Singleton.get_cur_att_data().id)
  41. })
  42. this.btn_delete_animation.on(Node.EventType.TOUCH_END,()=>{
  43. if(this.m_list.length<=0){
  44. return tools.showToast("无动画可删除!")
  45. }
  46. tools.show_dialog("是否删除当前选中的动画?",()=>{
  47. this.m_list.splice(this.cur_select.getIndex(),1)
  48. this.updateView()
  49. // this.cur_select.node.removeFromParent()
  50. // if(this.m_list.length<=0){
  51. // this.btn_delete_animation.getComponent(Button).interactable = false;
  52. // }else{
  53. // this.cur_select = this.content.children[this.content.children.length-1].getComponent(add_animation_item)
  54. // this.cur_select.selectStatus()
  55. // }
  56. if(this.call_back!=null){
  57. this.call_back(this.m_list)
  58. }
  59. })
  60. })
  61. this.btn_edit_animation.getComponent(Button).interactable = list.length<=0?false:true
  62. this.btn_delete_animation.getComponent(Button).interactable = list.length<=0?false:true
  63. this.btn_select_server_animation.on(Node.EventType.TOUCH_END, ()=>{
  64. tools.requestGetAnimationList((ani_list)=>{
  65. if(ani_list.length==0) {
  66. return tools.showToast('服务器还没有动画列表')
  67. }
  68. tools.show_select_animation_delete_list(ani_list,(item:att_ani_data)=>{
  69. if(this.m_list.length>0) {
  70. let end_item = this.m_list[this.m_list.length-1]
  71. item.ani_id = end_item.ani_id + 1
  72. }
  73. this.onCreateAni(item)
  74. })
  75. })
  76. })
  77. this.btn_set_server_animation.on(Node.EventType.TOUCH_END, ()=>{
  78. if(this.cur_select==null) {
  79. return tools.showToast('还没有动画')
  80. }
  81. let cur_data = this.cur_select.getData()
  82. if(cur_data==null) {
  83. return tools.showToast('请选择当前的动画')
  84. }
  85. tools.requestAddAnimationToAnimationList(cur_data)
  86. })
  87. }
  88. updateView(){
  89. this.content.removeAllChildren()
  90. for (let index = 0; index < this.m_list.length; index++) {
  91. const element = this.m_list[index];
  92. let item = instantiate(this.item_prefab)
  93. item.parent = this.content;
  94. item.getComponent(add_animation_item).initView(element,this.onItemClick.bind(this),index)
  95. if(index===0){
  96. item.getComponent(add_animation_item).selectStatus()
  97. this.cur_select = item.getComponent(add_animation_item);
  98. }
  99. }
  100. }
  101. onCreateAni(d:att_ani_data){
  102. this.m_list.push(d)
  103. this.updateView()
  104. this.btn_edit_animation.getComponent(Button).interactable = this.m_list.length<=0?false:true
  105. this.btn_delete_animation.getComponent(Button).interactable = this.m_list.length<=0?false:true
  106. if(this.call_back!=null){
  107. this.call_back(this.m_list)
  108. }
  109. }
  110. onItemClick(item:add_animation_item){
  111. for (let index = 0; index < this.content.children.length; index++) {
  112. const element = this.content.children[index];
  113. element.getComponent(add_animation_item).unSelectStatus()
  114. }
  115. item.selectStatus()
  116. this.cur_select = item;
  117. this.btn_edit_animation.getComponent(Button).interactable = true;
  118. this.btn_delete_animation.getComponent(Button).interactable = true
  119. }
  120. close(){
  121. this.node.destroy()
  122. }
  123. }