attributes_slide.ts 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { _decorator, Component, EditBox, instantiate, Label, Node, Prefab } from 'cc';
  2. import { att_slide_data, other_widget_finish_listen_item } from '../../../data/data';
  3. import { config } from '../../config';
  4. import { tools } from '../../tools';
  5. import { other_widget_finish_item } from './other_widget_finish_item';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('attributes_slide')
  8. export class attributes_slide extends Component {
  9. @property(Node) btn_slide_dir:Node = null;
  10. @property(Node) lab_slide_dir:Node = null;
  11. @property(Node) btn_slide_distance:Node = null;
  12. @property(Node) btn_slide_num:Node = null;
  13. @property(Node) btn_finish_event:Node = null;
  14. @property(EditBox) slide_num_edit:EditBox = null;
  15. @property(EditBox) slide_distance_edit:EditBox = null;
  16. @property(Node) btn_add_listen_other_widget_finish_event:Node = null;
  17. @property(Prefab) other_widget_finish_item:Prefab = null;
  18. @property(Node) other_widget_finish_content:Node = null;
  19. private call_back = null;
  20. private m_data:att_slide_data = null;
  21. public initView(call){
  22. this.call_back = call;
  23. this.btn_slide_dir.on(Node.EventType.TOUCH_END,()=>{
  24. tools.show_slide_dir_select((dir:number)=>{
  25. if(this.m_data.slide_dir!=dir){
  26. this.m_data.slide_dir = dir;
  27. this.change()
  28. }
  29. this.update_att(this.m_data)
  30. })
  31. })
  32. }
  33. public update_att(data:att_slide_data){
  34. this.m_data = data;
  35. this.slide_num_edit.string = data.slide_num.toString()
  36. this.slide_distance_edit.string = data.slide_distance.toString()
  37. this.lab_slide_dir.getComponent(Label).string = config.slide_type_map.get(data.slide_dir)
  38. this.other_widget_finish_content.removeAllChildren()
  39. if(this.m_data.other_widget_finish_listen_list==undefined){
  40. this.m_data.other_widget_finish_listen_list = []
  41. }
  42. for (let index = 0; index < this.m_data.other_widget_finish_listen_list.length; index++) {
  43. let item = instantiate(this.other_widget_finish_item)
  44. item.parent = this.other_widget_finish_content;
  45. let item_data = this.m_data.other_widget_finish_listen_list[index]
  46. item.getComponent(other_widget_finish_item).initView(item_data,this.onOtherWidgetFinishListenItemClickDelete.bind(this))
  47. }
  48. }
  49. protected start(): void {
  50. this.slide_num_edit.node.on('editing-did-ended', this.change, this);
  51. this.slide_distance_edit.node.on('editing-did-ended', this.change, this);
  52. this.btn_add_listen_other_widget_finish_event.on(Node.EventType.TOUCH_END,()=>{
  53. this.addOtherWidgetFinishListenItem()
  54. })
  55. }
  56. addOtherWidgetFinishListenItem(){
  57. let item = instantiate(this.other_widget_finish_item)
  58. item.parent = this.other_widget_finish_content;
  59. let item_data = new other_widget_finish_listen_item;
  60. this.m_data.other_widget_finish_listen_list.push(item_data)
  61. item.getComponent(other_widget_finish_item).initView(this.m_data.other_widget_finish_listen_list[this.m_data.other_widget_finish_listen_list.length-1],this.onOtherWidgetFinishListenItemClickDelete.bind(this))
  62. this.change()
  63. }
  64. onOtherWidgetFinishListenItemClickDelete(data:other_widget_finish_listen_item){
  65. let index = this.m_data.other_widget_finish_listen_list.indexOf(data)
  66. this.m_data.other_widget_finish_listen_list.splice(index,1)
  67. this.change()
  68. }
  69. change(){
  70. if(this.call_back!=null){
  71. this.call_back(this.m_data.slide_dir,parseInt(this.slide_num_edit.string),parseInt(this.slide_distance_edit.string))
  72. }
  73. }
  74. }