System.register(["__unresolved_0", "cc", "__unresolved_1"], function (_export, _context) {
  "use strict";

  var _reporterNs, _cclegacy, screen, _decorator, Component, Node, Vec2, Vec3, BaseJoystick, _dec, _dec2, _dec3, _class, _class2, _descriptor, _descriptor2, _temp, _crd, ccclass, property, JoystickComponent;

  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 }); }

  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

  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; }

  function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'proposal-class-properties is enabled and runs after the decorators transform.'); }

  function _reportPossibleCrUseOfBaseJoystick(extras) {
    _reporterNs.report("BaseJoystick", "./BaseJoystick", _context.meta, extras);
  }

  function _reportPossibleCrUseOfIMoveDirection(extras) {
    _reporterNs.report("IMoveDirection", "./BaseJoystick", _context.meta, extras);
  }

  return {
    setters: [function (_unresolved_) {
      _reporterNs = _unresolved_;
    }, function (_cc) {
      _cclegacy = _cc.cclegacy;
      screen = _cc.screen;
      _decorator = _cc._decorator;
      Component = _cc.Component;
      Node = _cc.Node;
      Vec2 = _cc.Vec2;
      Vec3 = _cc.Vec3;
    }, function (_unresolved_2) {
      BaseJoystick = _unresolved_2.BaseJoystick;
    }],
    execute: function () {
      _crd = true;

      _cclegacy._RF.push({}, "b3308C20ABHApkKGWjjU390", "JoystickComponent", undefined);

      ({
        ccclass,
        property
      } = _decorator);

      _export("JoystickComponent", JoystickComponent = (_dec = ccclass('JoystickComponent'), _dec2 = property({
        type: Node,
        tooltip: "摇杆的那个点"
      }), _dec3 = property({
        type: Node,
        tooltip: "所有事件的捕获区域"
      }), _dec(_class = (_class2 = (_temp = class JoystickComponent extends Component {
        constructor(...args) {
          super(...args);

          _initializerDefineProperty(this, "UI_Joystick_Ctl", _descriptor, this);

          _initializerDefineProperty(this, "UI_Joystick_Capture", _descriptor2, this);

          _defineProperty(this, "MoveTouchId", null);

          _defineProperty(this, "touchStartPos", new Vec2());

          _defineProperty(this, "touchMovePos", new Vec2());

          _defineProperty(this, "joystickDefPos", new Vec3());

          _defineProperty(this, "onmove", void 0);

          _defineProperty(this, "onmoveend", void 0);
        }

        start() {
          var _this$UI_Joystick_Cap, _this$UI_Joystick_Cap2, _this$UI_Joystick_Cap3, _this$UI_Joystick_Cap4;

          this.baseCtl = new (_crd && BaseJoystick === void 0 ? (_reportPossibleCrUseOfBaseJoystick({
            error: Error()
          }), BaseJoystick) : BaseJoystick)();

          this.baseCtl.onmove = dir => {
            var _this$onmove;

            (_this$onmove = this.onmove) === null || _this$onmove === void 0 ? void 0 : _this$onmove.call(this, dir);
          };

          this.baseCtl.onmoveend = () => {
            var _this$onmoveend;

            this.endMove();
            (_this$onmoveend = this.onmoveend) === null || _this$onmoveend === void 0 ? void 0 : _this$onmoveend.call(this);
          };

          (_this$UI_Joystick_Cap = this.UI_Joystick_Capture) === null || _this$UI_Joystick_Cap === void 0 ? void 0 : _this$UI_Joystick_Cap.on(Node.EventType.TOUCH_START, this.onTouchStartCtlUnit, this);
          (_this$UI_Joystick_Cap2 = this.UI_Joystick_Capture) === null || _this$UI_Joystick_Cap2 === void 0 ? void 0 : _this$UI_Joystick_Cap2.on(Node.EventType.TOUCH_MOVE, this.onTouchMoveCtlUnit, this);
          (_this$UI_Joystick_Cap3 = this.UI_Joystick_Capture) === null || _this$UI_Joystick_Cap3 === void 0 ? void 0 : _this$UI_Joystick_Cap3.on(Node.EventType.TOUCH_END, this.onTouchEndCtlUnit, this);
          (_this$UI_Joystick_Cap4 = this.UI_Joystick_Capture) === null || _this$UI_Joystick_Cap4 === void 0 ? void 0 : _this$UI_Joystick_Cap4.on(Node.EventType.TOUCH_CANCEL, this.onTouchEndCtlUnit, this);
        }

        onTouchStartCtlUnit(ev) {
          //某个触点被用作移动了,其他触点不需要
          if (this.MoveTouchId !== null) return;
          this.MoveTouchId = ev.getID();
          ev.getUILocation(this.touchStartPos);
          Vec3.copy(this.joystickDefPos, this.node.position); //var maxH = this.UI_Joystick.parent?.getComponent(UITransform)?.height ?? 960;

          this.node.setPosition(this.touchStartPos.x, this.touchStartPos.y, this.joystickDefPos.z); //creator的UI坐标系, y轴是左下角向上, 所以要转一下

          this.baseCtl.touchStart(this.touchStartPos.x, screen.windowSize.height - this.touchStartPos.y);
        }

        onTouchMoveCtlUnit(ev) {
          if (this.MoveTouchId === null || ev.getID() != this.MoveTouchId) return;
          ev.getUILocation(this.touchMovePos);
          var reX = this.touchMovePos.x - this.touchStartPos.x;
          var reY = this.touchMovePos.y - this.touchStartPos.y;
          var ctlMove = new Vec2(reX, reY);
          ctlMove.normalize();
          ctlMove.multiplyScalar(30);
          this.UI_Joystick_Ctl.setPosition(ctlMove.x, ctlMove.y, 0); //creator的UI坐标系, y轴是左下角向上, 所以要转一下

          this.baseCtl.touchMove(this.touchMovePos.x, screen.windowSize.height - this.touchMovePos.y);
        }

        onTouchEndCtlUnit(ev) {
          if (this.MoveTouchId === null || ev.getID() != this.MoveTouchId) return;
          this.baseCtl.touchEnd();
        }

        endMove() {
          this.MoveTouchId = null;
          this.UI_Joystick_Ctl.setPosition(new Vec3(0, 0, 0));
          this.node.setPosition(this.joystickDefPos);
        }

      }, _temp), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "UI_Joystick_Ctl", [_dec2], {
        configurable: true,
        enumerable: true,
        writable: true,
        initializer: null
      }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "UI_Joystick_Capture", [_dec3], {
        configurable: true,
        enumerable: true,
        writable: true,
        initializer: null
      })), _class2)) || _class));

      _cclegacy._RF.pop();

      _crd = false;
    }
  };
});
//# sourceMappingURL=JoystickComponent.js.map