LayerAction.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { _decorator, Component, ERigidBody2DType, RigidBody2D } from 'cc';
  2. import { CarColors } from './CarColorsGlobalTypes';
  3. import { PinComponent } from './Components/PinComponent';
  4. import { ElementAction } from './ElementAction';
  5. import { DataModel } from './Model/DataModel';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('LayerAction')
  8. export class LayerAction extends Component {
  9. layer_group_id = 0;
  10. layer_color: CarColors = null;
  11. start() {
  12. }
  13. update(deltaTime: number) {
  14. }
  15. public get_hole_num(): number {
  16. let hole_num: number = 0;
  17. this.node.children.forEach(element_node => {
  18. hole_num += element_node.getComponent(ElementAction).get_hole_num();
  19. });
  20. return hole_num;
  21. }
  22. public init_layer() {
  23. this.layer_group_id = DataModel.get_new_group_index();
  24. this.node.children.forEach(element_node => {
  25. element_node.getComponent(ElementAction).init_element(this.layer_group_id, this.layer_color);
  26. });
  27. }
  28. public init_pin(color_pin_arr: CarColors[]) {
  29. this.node.children.forEach(element_node => {
  30. element_node.getComponent(ElementAction).init_pin(this.layer_group_id, color_pin_arr);
  31. });
  32. }
  33. public change_pin_color(color: CarColors) {
  34. this.node.children.forEach(element_node => {
  35. element_node.getComponent(ElementAction).change_pin_color(color);
  36. });
  37. }
  38. get_pin_color(arr: PinComponent[]) {
  39. this.node.children.forEach(element_node => {
  40. element_node.getComponent(ElementAction)!.get_pin_color(arr);
  41. });
  42. }
  43. public get_element_num(): number {
  44. return this.node.children.length;
  45. }
  46. layer_status: number = 0;
  47. /**0 =隐藏,1=显示,2=黑色模式 */
  48. public set_status(args: number) {
  49. switch (args) {
  50. case 0:
  51. this.node.active = false;
  52. break;
  53. case 1:
  54. this.node.active = true;
  55. if (this.layer_status == 0) {
  56. this.node.children.forEach(element_node => {
  57. element_node.getComponent(ElementAction)?.flash_img();
  58. });
  59. }
  60. if (this.layer_status == 2) {
  61. this.node.children.forEach(element_node => {
  62. element_node.getComponent(ElementAction)?.set_layer_bg_or_orgin(false);
  63. element_node.getComponent(ElementAction)?.flash_img();
  64. });
  65. }
  66. // console.log('显示layer+++++++++++++')
  67. break;
  68. case 2:
  69. if (this.layer_status != 2) {
  70. this.node.children.forEach(element_node => {
  71. element_node.getComponent(ElementAction)?.set_layer_bg_or_orgin(true);
  72. });
  73. this.scheduleOnce(() => {
  74. this.node.active = true;
  75. }, 1);
  76. }
  77. break;
  78. }
  79. this.layer_status = args;
  80. }
  81. }