event_switch_scene_event.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import { _decorator, Component, EditBox, Label, Node, Toggle } from 'cc';
  2. import { event_item_switch_scene_event, scene_item_data } from '../../../data/data';
  3. import { config } from '../../config';
  4. import { main } from '../../main';
  5. import { tools } from '../../tools';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('event_switch_scene_event')
  8. export class event_switch_scene_event extends Component {
  9. @property(Node) lab_name:Node = null;
  10. @property(Node) btn_select_page:Node = null;
  11. @property(Node) up_node:Node = null;
  12. @property(Node) down_node:Node = null;
  13. @property(Node) left_node:Node = null;
  14. @property(Node) right_node:Node = null;
  15. @property(Node) only_once_node:Node = null;
  16. @property(EditBox) edit_time:EditBox = null;
  17. private m_data:event_item_switch_scene_event = null;
  18. private m_scene_data:scene_item_data = null;
  19. public initView(data:event_item_switch_scene_event){
  20. this.m_data = data;
  21. this.m_scene_data = main.Singleton.getEditSceneView().getCurSelectScene()
  22. this.updateSceneStatus()
  23. this.updateLabStatus()
  24. this.updateDirectionNodeStatus()
  25. this.only_once_node.getComponent(Toggle).isChecked = this.m_data.executeOnlyOnce
  26. if(data.delay_time == undefined) {
  27. data.delay_time = 0
  28. }
  29. this.edit_time.string = data.delay_time.toString()
  30. }
  31. start() {
  32. this.btn_select_page.on(Node.EventType.TOUCH_END, ()=> {
  33. tools.show_select_more_scene_page(this.m_scene_data.page_list,this.m_data.binding_page_index,(index:number)=> {
  34. this.m_data.binding_page_index = index
  35. this.updateSceneStatus()
  36. this.updateLabStatus()
  37. })
  38. })
  39. this.up_node.on(Node.EventType.TOUCH_END, ()=> {
  40. this.change(config.switch_scene_page_direction.up)
  41. })
  42. this.down_node.on(Node.EventType.TOUCH_END,()=> {
  43. this.change(config.switch_scene_page_direction.down)
  44. })
  45. this.left_node.on(Node.EventType.TOUCH_END,()=> {
  46. this.change(config.switch_scene_page_direction.left)
  47. })
  48. this.right_node.on(Node.EventType.TOUCH_END,()=> {
  49. this.change(config.switch_scene_page_direction.right)
  50. })
  51. this.only_once_node.on('toggle', ()=>{
  52. this.m_data.executeOnlyOnce = this.only_once_node.getComponent(Toggle).isChecked
  53. })
  54. this.edit_time.node.on('editing-did-ended', ()=> {
  55. this.m_data.delay_time = parseFloat(this.edit_time.string)
  56. })
  57. }
  58. change(direction = config.switch_scene_page_direction.unknown) {
  59. if(this.m_data.direction == direction) {
  60. this.m_data.direction = config.switch_scene_page_direction.unknown
  61. return
  62. }
  63. this.m_data.direction = direction
  64. this.updateDirectionNodeStatus()
  65. }
  66. noCheckedAll() {
  67. this.up_node.getComponent(Toggle).isChecked = false
  68. this.down_node.getComponent(Toggle).isChecked = false
  69. this.left_node.getComponent(Toggle).isChecked = false
  70. this.right_node.getComponent(Toggle).isChecked = false
  71. }
  72. updateSceneStatus() {
  73. switch (this.m_scene_data.type) {
  74. case config.Scene_Type_List.many_screen_switch_up_down:
  75. this.up_node.active = true
  76. this.down_node.active = true
  77. this.left_node.active = false
  78. this.right_node.active = false
  79. if(this.m_data.binding_page_index == 0) {
  80. this.up_node.active = false
  81. if(this.m_data.direction==config.switch_scene_page_direction.up) {
  82. this.m_data.direction=config.switch_scene_page_direction.unknown
  83. this.up_node.getComponent(Toggle).isChecked = false
  84. }
  85. } else if(this.m_data.binding_page_index >= this.m_scene_data.page_list.length-1) {
  86. this.down_node.active = false
  87. if(this.m_data.direction==config.switch_scene_page_direction.down) {
  88. this.m_data.direction=config.switch_scene_page_direction.unknown
  89. this.down_node.getComponent(Toggle).isChecked = false
  90. }
  91. }
  92. break;
  93. case config.Scene_Type_List.many_screen_switch_left_right:
  94. this.up_node.active = false
  95. this.down_node.active = false
  96. this.left_node.active = true
  97. this.right_node.active = true
  98. if(this.m_data.binding_page_index == 0) {
  99. this.left_node.active = false
  100. if(this.m_data.direction==config.switch_scene_page_direction.left) {
  101. this.m_data.direction=config.switch_scene_page_direction.unknown
  102. this.left_node.getComponent(Toggle).isChecked = false
  103. }
  104. } else if(this.m_data.binding_page_index >= this.m_scene_data.page_list.length-1) {
  105. this.right_node.active = false
  106. if(this.m_data.direction==config.switch_scene_page_direction.right) {
  107. this.m_data.direction=config.switch_scene_page_direction.unknown
  108. this.right_node.getComponent(Toggle).isChecked = false
  109. }
  110. }
  111. break;
  112. default:
  113. break;
  114. }
  115. }
  116. updateDirectionNodeStatus() {
  117. this.noCheckedAll()
  118. this.scheduleOnce(()=> {
  119. switch (this.m_data.direction) {
  120. case config.switch_scene_page_direction.up:
  121. this.up_node.getComponent(Toggle).isChecked = true
  122. break;
  123. case config.switch_scene_page_direction.down:
  124. this.down_node.getComponent(Toggle).isChecked = true
  125. break;
  126. case config.switch_scene_page_direction.left:
  127. this.left_node.getComponent(Toggle).isChecked = true
  128. break;
  129. case config.switch_scene_page_direction.right:
  130. this.right_node.getComponent(Toggle).isChecked = true
  131. break;
  132. default:
  133. break;
  134. }
  135. },0.1)
  136. }
  137. updateLabStatus() {
  138. // console.log('this.m_data.binding_page_index=',this.m_data.binding_page_index)
  139. let string = '请选择切换场景的页数'
  140. if(this.m_data.binding_page_index != undefined && this.m_data.binding_page_index != -1) {
  141. string = `选择切换场景的页数是:${this.m_data.binding_page_index + 1}`
  142. }
  143. this.lab_name.getComponent(Label).string = string
  144. }
  145. }