attributes_click.ts 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { _decorator, Component, EditBox, instantiate, Label, Node, Prefab } from 'cc';
  2. import { att_click_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_click')
  8. export class attributes_click extends Component {
  9. @property(Node) btn_finish_event:Node = null;
  10. @property(Node) btn_click_type:Node = null;
  11. @property(Node) lab_click_type:Node = null;
  12. @property(Node) click_hold_time:Node = null;
  13. @property(Node) multiple_clicks_num:Node = null;
  14. @property(EditBox) edit_click_hold_time:EditBox = null;
  15. @property(EditBox) edit_multiple_clicks_num: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_click_data = null;
  21. public initView(call){
  22. this.call_back = call;
  23. this.btn_click_type.on(Node.EventType.TOUCH_END,()=>{
  24. tools.show_click_type_select((type:number)=>{
  25. this.m_data.click_type = type;
  26. this.update_att(this.m_data)
  27. this.change()
  28. })
  29. })
  30. }
  31. protected start(): void {
  32. this.edit_click_hold_time.node.on('editing-did-ended', this.change, this);
  33. this.edit_multiple_clicks_num.node.on('editing-did-ended', this.change, this);
  34. this.btn_add_listen_other_widget_finish_event.on(Node.EventType.TOUCH_END,()=>{
  35. this.addOtherWidgetFinishListenItem()
  36. })
  37. }
  38. addOtherWidgetFinishListenItem(){
  39. let item = instantiate(this.other_widget_finish_item)
  40. item.parent = this.other_widget_finish_content;
  41. let item_data = new other_widget_finish_listen_item;
  42. this.m_data.other_widget_finish_listen_list.push(item_data)
  43. 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))
  44. this.change()
  45. }
  46. onOtherWidgetFinishListenItemClickDelete(data:other_widget_finish_listen_item){
  47. let index = this.m_data.other_widget_finish_listen_list.indexOf(data)
  48. this.m_data.other_widget_finish_listen_list.splice(index,1)
  49. this.change()
  50. }
  51. change(){
  52. if(this.call_back!=null){
  53. this.m_data.hold_time = parseInt(this.edit_click_hold_time.string)
  54. this.m_data.multiple_check_num = parseInt(this.edit_multiple_clicks_num.string)
  55. this.call_back(this.m_data)
  56. }
  57. }
  58. public update_att(data:att_click_data){
  59. this.m_data = data;
  60. this.edit_click_hold_time.string = this.m_data.hold_time .toString()
  61. this.edit_multiple_clicks_num.string = this.m_data.multiple_check_num .toString()
  62. if(this.m_data.click_type===config.clcik_type.click){
  63. this.click_hold_time.active = false;
  64. this.multiple_clicks_num.active = false;
  65. }else if(this.m_data.click_type===config.clcik_type.Press_and_hold){
  66. this.multiple_clicks_num.active = false;
  67. this.click_hold_time.active = true;
  68. }else if(this.m_data.click_type===config.clcik_type.Multiple_clicks){
  69. this.multiple_clicks_num.active = true;
  70. this.click_hold_time.active = false;
  71. }
  72. if(this.m_data.other_widget_finish_listen_list==undefined){
  73. this.m_data.other_widget_finish_listen_list = []
  74. }
  75. this.lab_click_type.getComponent(Label).string =config.clcik_type_map.get(this.m_data.click_type)
  76. this.other_widget_finish_content.removeAllChildren()
  77. for (let index = 0; index < this.m_data.other_widget_finish_listen_list.length; index++) {
  78. let item = instantiate(this.other_widget_finish_item)
  79. item.parent = this.other_widget_finish_content;
  80. let item_data = this.m_data.other_widget_finish_listen_list[index]
  81. item.getComponent(other_widget_finish_item).initView(item_data,this.onOtherWidgetFinishListenItemClickDelete.bind(this))
  82. }
  83. }
  84. }