attributes_count_down.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import { _decorator, Color, Component, EditBox, Label, Node, Sprite, Toggle } from 'cc';
  2. import { att_count_down, event_item, font_color_info, font_info } from '../../../data/data';
  3. import { tools } from '../../tools';
  4. import { question_btn_info } from './question_btn_info';
  5. import { config } from '../../config';
  6. import { Attributes } from '../Attributes';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('attributes_count_down')
  9. export class attributes_count_down extends Component {
  10. @property(Node) ProgressBar_Bg:Node = null;
  11. @property(Node) ProgressBar_Bar:Node = null;
  12. @property(Node) img_text:Node = null;
  13. @property(Node) toggle_enbale_time:Node = null;
  14. @property(Node) edit_down_count_time:Node = null;
  15. //event
  16. @property(Node) btn_finish_event:Node = null;
  17. @property(Node) btn_fail_event:Node = null;
  18. @property(Node) btn_start_event:Node = null;
  19. @property(Node) lab_finish_event:Node = null;
  20. @property(Node) lab_fail_event:Node = null;
  21. @property(Node) lab_start_event:Node = null;
  22. @property(Node) clear_finish_event:Node = null;
  23. @property(Node) clear_fail_event:Node = null;
  24. @property(Node) clear_start_event:Node = null;
  25. @property(Node) font_size:Node = null;
  26. @property(Node) font_color:Node = null;
  27. private call_back = null;
  28. private m_data:att_count_down = null;
  29. public initView(call){
  30. this.call_back = call;
  31. this.edit_down_count_time.on('editing-did-ended',()=>{
  32. this.change()
  33. this.update_att(this.m_data)
  34. })
  35. this.toggle_enbale_time.on('toggle',()=>{
  36. this.change()
  37. this.update_att(this.m_data)
  38. })
  39. this.btn_finish_event.on(Node.EventType.TOUCH_END,()=>{
  40. let list = Attributes.Singleton.getEventList()
  41. tools.show_select_evele_list(list,(data:event_item)=>{
  42. this.m_data.finish_event_id = data.event_id;
  43. this.change()
  44. this.update_att(this.m_data)
  45. })
  46. })
  47. this.btn_fail_event.on(Node.EventType.TOUCH_END,()=>{
  48. let list = Attributes.Singleton.getEventList()
  49. tools.show_select_evele_list(list,(data:event_item)=>{
  50. this.m_data.fail_event_id = data.event_id;
  51. this.change()
  52. this.update_att(this.m_data)
  53. })
  54. })
  55. this.btn_start_event.on(Node.EventType.TOUCH_END,()=>{
  56. let list = Attributes.Singleton.getEventList()
  57. tools.show_select_evele_list(list,(data:event_item)=>{
  58. if(data.type!=config.event_type.collect_event){
  59. return tools.showToast("必须设置收集事件")
  60. }
  61. this.m_data.start_event_id = data.event_id;
  62. this.change()
  63. this.update_att(this.m_data)
  64. })
  65. })
  66. this.clear_finish_event.on(Node.EventType.TOUCH_END,()=>{
  67. this.m_data.finish_event_id = -1;
  68. this.change()
  69. this.update_att(this.m_data)
  70. })
  71. this.clear_fail_event.on(Node.EventType.TOUCH_END,()=>{
  72. this.m_data.fail_event_id = -1;
  73. this.change()
  74. this.update_att(this.m_data)
  75. })
  76. this.clear_start_event.on(Node.EventType.TOUCH_END,()=>{
  77. this.m_data.start_event_id = -1;
  78. this.change()
  79. this.update_att(this.m_data)
  80. })
  81. this.font_color.on(Node.EventType.TOUCH_END,()=>{
  82. tools.show_set_color(this.font_color.getComponent(Sprite).color,(color:Color)=>{
  83. this.m_data.font_info.font_color = new font_color_info().infoColor(color) ;
  84. this.update_att(this.m_data)
  85. this.change()
  86. })
  87. })
  88. this.font_size.on('editing-did-ended',()=>{
  89. this.change()
  90. this.update_att(this.m_data)
  91. })
  92. }
  93. public update_att(data:att_count_down){
  94. this.m_data = data;
  95. console.log(' this.m_data.time_count=', this.m_data.time_count)
  96. console.log(' this.m_data.font_info.font_size=', this.m_data.font_info.font_size)
  97. this.ProgressBar_Bg.getComponent(question_btn_info).initView(this.m_data.ProgressBar_Bg,1,null,config.attributes_list_type.count_down)
  98. this.ProgressBar_Bar.getComponent(question_btn_info).initView(this.m_data.ProgressBar_Bar,2,null,config.attributes_list_type.count_down)
  99. this.img_text.getComponent(question_btn_info).initView(this.m_data.img_text,3,null,config.attributes_list_type.count_down)
  100. this.toggle_enbale_time.getComponent(Toggle).isChecked = this.m_data.is_show_time;
  101. this.edit_down_count_time.getComponent(EditBox).string = this.m_data.time_count.toString()
  102. this.lab_finish_event.getComponent(Label).string = this.m_data.finish_event_id!=-1?`绑定的id${this.m_data.finish_event_id}`:"无"
  103. this.lab_fail_event.getComponent(Label).string = this.m_data.fail_event_id!=-1?`绑定的id${this.m_data.fail_event_id}`:"无"
  104. this.lab_start_event.getComponent(Label).string = this.m_data.start_event_id!=-1?`绑定的id${this.m_data.start_event_id}`:"无"
  105. if(this.m_data.font_info!=undefined&&this.m_data.font_info!=null){
  106. if(this.m_data.font_info.font_size==undefined||
  107. this.m_data.font_info.font_size==null||
  108. isNaN(this.m_data.font_info.font_size)) {
  109. this.m_data.font_info.font_size = 20
  110. } else {
  111. this.m_data.font_info.font_size = parseInt(this.font_size.getComponent(EditBox).string)
  112. }
  113. let color = this.m_data.font_info.font_color;
  114. this.font_color.getComponent(Sprite).color = new Color(color.r,color.g,color.b);
  115. this.font_size.getComponent(EditBox).string = this.m_data.font_info.font_size.toString()
  116. }else{
  117. this.m_data.font_info = new font_info;
  118. }
  119. }
  120. change(){
  121. this.m_data.is_show_time = this.toggle_enbale_time.getComponent(Toggle).isChecked ;
  122. let down_count_time = this.edit_down_count_time.getComponent(EditBox).string
  123. if(this.m_data.font_info!=undefined&&this.m_data.font_info!=null){
  124. if(this.m_data.font_info.font_size==undefined||
  125. this.m_data.font_info.font_size==null||
  126. isNaN(this.m_data.font_info.font_size)) {
  127. this.m_data.font_info.font_size = 20
  128. } else {
  129. this.m_data.font_info.font_size = parseInt(this.font_size.getComponent(EditBox).string)
  130. }
  131. }
  132. if(down_count_time.length>0) {
  133. this.m_data.time_count = parseInt(down_count_time);
  134. }
  135. if(this.call_back!=null){
  136. this.call_back(this.m_data)
  137. }
  138. }
  139. }