LineComponent.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. e =
  5. (this && this.__decorate) ||
  6. function(t, e, i, s) {
  7. var o,
  8. a = arguments.length,
  9. n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
  10. if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
  11. else
  12. for (var r = t.length - 1; 0 <= r; r--)
  13. (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
  14. return 3 < a && n && Object.defineProperty(e, i, n), n;
  15. };
  16. Object.defineProperty(i, "__esModule", { value: !0 }), (i.LineComponent = void 0);
  17. const s = t("SwitchFrame"),
  18. { ccclass: o, property: a, menu: n, executeInEditMode: r, playOnFocus: l } = cc._decorator;
  19. t = class extends cc.Component {
  20. constructor() {
  21. super(...arguments),
  22. (this.node1 = null),
  23. (this.node2 = null),
  24. (this.light = null),
  25. (this.switchFrame = null),
  26. (this.pos1 = null),
  27. (this.pos2 = null),
  28. (this._isDraw = !1);
  29. }
  30. set drawLine(t) {
  31. Log.trace("wtffffff", t), (this._isDraw = t) && this.setPos(this.node1.position, this.node2.position);
  32. }
  33. get drawLine() {
  34. return this._isDraw;
  35. }
  36. onLoad() {
  37. (this.node.anchorY = 0.5), (this.node.anchorX = 0);
  38. }
  39. getRadian2(t, e, i, s) {
  40. return Math.atan2(s - e, i - t);
  41. }
  42. setGray(t) {
  43. this.switchFrame.frameIndex = t ? 0 : 1;
  44. }
  45. setNode(t, e, i = -1) {
  46. (this.node1 = t || this.node1), (this.node2 = e || this.node2);
  47. (e = this.node1.parent.convertToWorldSpaceAR(this.node1.position)),
  48. (e = this.node.parent.convertToNodeSpaceAR(e));
  49. this.pos2 = e;
  50. (e = this.node2.parent.convertToWorldSpaceAR(this.node2.position)),
  51. (e = this.node.parent.convertToNodeSpaceAR(e));
  52. (this.pos1 = e), this.playAni(i);
  53. }
  54. setPos(t, e, i = -1) {
  55. (this.pos1 = t), (this.pos2 = e), this.playAni(i);
  56. }
  57. setCallback(t) {
  58. this.cb = t;
  59. }
  60. playAni(t = 0, e) {
  61. var i, s, o;
  62. this.pos1 &&
  63. this.pos2 &&
  64. ((i = this.pos2),
  65. (s = this.pos1),
  66. (this.node.width = 0),
  67. (o = this.getRadian2(i.x, i.y, s.x, s.y)),
  68. (o = this.node.angle = (180 * o) / Math.PI),
  69. Log.trace("角度:", o),
  70. (this.node.x = this.pos2.x),
  71. (this.node.y = this.pos2.y),
  72. (o = cc.Vec2.distance(i, s)),
  73. Log.trace("绘制:::", o),
  74. t <= 0 ?
  75. (this.node.width = o) :
  76. ((this.light.active = !0),
  77. cc
  78. .tween(this.node)
  79. .to(0.012 * o, { width: cc.Vec2.distance(i, s) })
  80. .call(() => {
  81. this.light && (this.light.active = !1), e && e();
  82. })
  83. .start()));
  84. }
  85. getY() {
  86. if (this.pos1 && this.pos2) {
  87. var t = this.pos2,
  88. e = this.pos1,
  89. t = this.getRadian2(t.x, t.y, e.x, e.y),
  90. e = (Math.PI, this.node.width);
  91. return this.node.y + Math.sin(t) * e;
  92. }
  93. }
  94. stopAni() {
  95. this.node.stopAllActions();
  96. }
  97. removeSelf() {
  98. (this.pos1 = null),
  99. (this.pos2 = null),
  100. this.stopAni(),
  101. (this.cb = null),
  102. this.light && (this.light.active = !1);
  103. }
  104. };
  105. e([a(cc.Node)], t.prototype, "node1", void 0),
  106. e([a(cc.Node)], t.prototype, "node2", void 0),
  107. e([a(cc.Node)], t.prototype, "light", void 0),
  108. e([a(s.default)], t.prototype, "switchFrame", void 0),
  109. e([a({ type: cc.Boolean })], t.prototype, "drawLine", null),
  110. (t = e([o, r, l], t)),
  111. (i.LineComponent = t);