b9bb1f5602c0641781029635c894fc3c508bcbf5.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. System.register(["cc"], function (_export, _context) {
  2. "use strict";
  3. var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _cc, _decorator, Component, Input, _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _crd, cc, ccclass, property, ClickPenetrate;
  4. function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
  5. function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
  6. function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
  7. return {
  8. setters: [function (_cc2) {
  9. _cclegacy = _cc2.cclegacy;
  10. __checkObsolete__ = _cc2.__checkObsolete__;
  11. __checkObsoleteInNamespace__ = _cc2.__checkObsoleteInNamespace__;
  12. _cc = _cc2;
  13. _decorator = _cc2._decorator;
  14. Component = _cc2.Component;
  15. Input = _cc2.Input;
  16. }],
  17. execute: function () {
  18. _crd = true;
  19. _cclegacy._RF.push({}, "739bfHpcHtB3IXOkilm3JV7", "ClickPenetrate", undefined);
  20. cc = __checkObsoleteInNamespace__(_cc);
  21. __checkObsolete__(['_decorator', 'Component', 'Button', 'Input']);
  22. ({
  23. ccclass,
  24. property
  25. } = _decorator);
  26. /*** 按钮 点击穿透*/
  27. _export("ClickPenetrate", ClickPenetrate = (_dec = ccclass('ClickPenetrate'), _dec2 = property({
  28. tooltip: "滑动会关闭 end 触摸事件"
  29. }), _dec3 = property({
  30. tooltip: "触摸开始",
  31. type: cc.EventHandler
  32. }), _dec4 = property({
  33. tooltip: "触摸移动",
  34. type: cc.EventHandler
  35. }), _dec5 = property({
  36. tooltip: "触摸结束",
  37. type: cc.EventHandler
  38. }), _dec(_class = (_class2 = class ClickPenetrate extends Component {
  39. constructor(...args) {
  40. super(...args);
  41. _initializerDefineProperty(this, "move_began_end", _descriptor, this);
  42. _initializerDefineProperty(this, "on_touch_began", _descriptor2, this);
  43. _initializerDefineProperty(this, "on_touch_move", _descriptor3, this);
  44. _initializerDefineProperty(this, "on_touch_end", _descriptor4, this);
  45. // @property({ tooltip: "触摸关闭", type: cc.EventHandler })
  46. // private on_touch_cancel: Array<cc.EventHandler> = [];
  47. this.has_began = false;
  48. this.comp_btn = null;
  49. /** 是移动状态 */
  50. this.is_move = null;
  51. /** 本次点击所移动的距离 */
  52. this.delta = new cc.Vec2(0, 0);
  53. }
  54. onLoad() {
  55. this.comp_btn = this.node.getComponent(cc.Button) || this.node.addComponent(cc.Button);
  56. this.comp_btn.node.on(Input.EventType.TOUCH_START, this.onTouchBegan, this);
  57. this.comp_btn.node.on(Input.EventType.TOUCH_MOVE, this.onTouchMoved, this);
  58. this.comp_btn.node.on(Input.EventType.TOUCH_END, this.onTouchEnded, this);
  59. this.comp_btn.node.on(Input.EventType.TOUCH_CANCEL, this.onTouchCancelled, this);
  60. }
  61. onTouchBegan(touch, param) {
  62. touch.preventSwallow = true;
  63. this.has_began = true;
  64. this.is_move = false;
  65. this.delta = new cc.Vec2(0, 0);
  66. this.on_touch_began.forEach((value, key) => {
  67. value.emit([this.comp_btn]);
  68. });
  69. }
  70. onTouchMoved(touch, param) {
  71. touch.preventSwallow = true;
  72. if (!this.has_began) return;
  73. this.on_touch_move.forEach((value, key) => {
  74. value.emit([this.comp_btn]);
  75. });
  76. let delta = touch.getDelta();
  77. this.delta.x += delta.x;
  78. this.delta.y += delta.y;
  79. const distance = this.delta.length();
  80. if (distance >= 20) this.is_move = true; // 滑动超过20像素,算作点击
  81. }
  82. onTouchEnded(touch, param) {
  83. touch.preventSwallow = true;
  84. if (!this.has_began) return;
  85. if (this.move_began_end && this.is_move) return;
  86. this.on_touch_end.forEach((value, key) => {
  87. value.emit([this.comp_btn]);
  88. });
  89. this.has_began = false;
  90. this.is_move = false;
  91. }
  92. onTouchCancelled(touch, param) {
  93. touch.preventSwallow = true;
  94. }
  95. }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "move_began_end", [_dec2], {
  96. configurable: true,
  97. enumerable: true,
  98. writable: true,
  99. initializer: function () {
  100. return false;
  101. }
  102. }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "on_touch_began", [_dec3], {
  103. configurable: true,
  104. enumerable: true,
  105. writable: true,
  106. initializer: function () {
  107. return [];
  108. }
  109. }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "on_touch_move", [_dec4], {
  110. configurable: true,
  111. enumerable: true,
  112. writable: true,
  113. initializer: function () {
  114. return [];
  115. }
  116. }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "on_touch_end", [_dec5], {
  117. configurable: true,
  118. enumerable: true,
  119. writable: true,
  120. initializer: function () {
  121. return [];
  122. }
  123. })), _class2)) || _class));
  124. _cclegacy._RF.pop();
  125. _crd = false;
  126. }
  127. };
  128. });
  129. //# sourceMappingURL=b9bb1f5602c0641781029635c894fc3c508bcbf5.js.map