LayerAction.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { _decorator, Component, Node, Rect, tween, UIOpacity, UITransform, Vec2 } from 'cc';
  2. import { PinAction } from './PinAction';
  3. import { ElementAction } from './ElementAction';
  4. import { ColorDate } from './ColorDate';
  5. import { Global } from './Global';
  6. import { DataModel } from './DataModel';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('LayerAction')
  9. export class LayerAction extends Component {
  10. layer_group_id = 0;
  11. layer_color: ColorDate = null;
  12. start() {
  13. console.log("zh:layerAction.ts start");
  14. }
  15. update(deltaTime: number) {
  16. }
  17. public get_hole_num(): number {
  18. let hole_num: number = 0;
  19. this.node.children.forEach(element_node => {
  20. hole_num += element_node.getComponent(ElementAction).get_hole_num();
  21. });
  22. return hole_num;
  23. }
  24. public init_layer() {
  25. this.layer_group_id = DataModel.get_new_group_index();
  26. this.layer_color = DataModel.get_layer_color();
  27. this.node.children.forEach(element_node => {
  28. element_node.getComponent(ElementAction).init_element(this.layer_group_id, this.layer_color);
  29. });
  30. }
  31. public init_pin(color_pin_arr: ColorDate[]) {
  32. this.node.children.forEach(element_node => {
  33. element_node.getComponent(ElementAction).init_pin(this.layer_group_id, color_pin_arr);
  34. });
  35. }
  36. get_pin_color(arr: PinAction[]) {
  37. this.node.children.forEach(element_node => {
  38. element_node.getComponent(ElementAction)?.get_pin_color(arr);
  39. });
  40. }
  41. public get_element_size(): number {
  42. return this.node.children.length;
  43. }
  44. /**
  45. *
  46. * @param active
  47. * @param t
  48. */
  49. public layer_active(active: boolean, t: number = 0.3) {
  50. let need_show = !this.node.active;
  51. this.node.active = active;
  52. // this.node.opa
  53. let opc_1 = 100;
  54. let opc_2 = 200;
  55. if (need_show && active && this.node.getComponent(UIOpacity)) {
  56. this.node.getComponent(UIOpacity).opacity = 0;
  57. tween(this.node.getComponent(UIOpacity))
  58. .to(t, { opacity: opc_1 }, Global.our_easing)
  59. .to(t, { opacity: opc_2 }, Global.our_easing)
  60. .to(t, { opacity: opc_1 }, Global.our_easing)
  61. .to(t, { opacity: opc_2 }, Global.our_easing)
  62. .to(t, { opacity: opc_1 }, Global.our_easing)
  63. .to(t, { opacity: opc_2 }, Global.our_easing)
  64. .to(t, { opacity: opc_1 }, Global.our_easing)
  65. .to(t, { opacity: 255 }, Global.our_easing)
  66. .call(() => {
  67. this.node.getComponent(UIOpacity).opacity = 255;
  68. })
  69. .start();
  70. }
  71. }
  72. }