123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- var t = require;
- var e = module;
- var a = exports;
- e =
- (this && this.__decorate) ||
- function (t, e, i, s) {
- var o,
- a = arguments.length,
- n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
- if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
- else
- for (var r = t.length - 1; 0 <= r; r--)
- (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
- return 3 < a && n && Object.defineProperty(e, i, n), n;
- };
- Object.defineProperty(a, "__esModule", {value: !0}), (a.InputType = void 0);
- const i = t("Toucher"),
- s = t("TouchPinch"),
- {ccclass: o, property: n} = cc._decorator;
- let r = class extends cc.Component {
- constructor() {
- super(...arguments),
- (this.inputNode = null),
- (this.stickBaseNode = null),
- (this.stickNode = null),
- (this.screenCoord = !0),
- (this.ignoreInput = !1);
- }
- onLoad() {
- (this.inputNode = this.inputNode || this.node),
- (this._eventTarget = new cc.EventTarget()),
- this.initToucher(),
- this.initKeyboard(),
- this.initMouse();
- }
- initToucher() {
- (cc.macro.TOUCH_TIMEOUT = 120),
- (this.touchFingers = 0),
- (this.toucher = this.inputNode.getComponent(i.default));
- const t = this.toucher;
- t.init(), t.registerEvents(this.inputNode, !1), t.registerEventsOnChildren(this.inputNode, !1);
- const o = new s.default();
- (t.onStart = (t, e, i) => {
- var s = i.target;
- (this.touchFingers = this.getFingerCount("onStart")),
- 1 === this.touchFingers
- ? (o.reset(), o.onTouchStart(i))
- : 2 === this.touchFingers
- ? o.onTouchStart(i)
- : o.reset(),
- this._eventTarget.emit(a.InputType.TOUCH_START, t, e, s);
- }),
- (t.onMove = (t, e, i) => {
- i = i.target;
- (this.touchFingers = this.getFingerCount("onMove")),
- 2 === this.touchFingers &&
- o.onPinch() &&
- (this.screenCoord && (o.pinchCenter.y = cc.visibleRect.height - o.pinchCenter.y),
- this._eventTarget.emit(a.InputType.PINCH, o.pinchCenter, o.lastPinchDist, o.pinchDist, i));
- }),
- (t.onEnd = (t, e, i) => {
- var s = i.target;
- (this.touchFingers = this.getFingerCount("onEnd")),
- 0 === this.touchFingers ? o.reset() : o.onTouchEnd(i),
- this.screenCoord && (e = cc.visibleRect.height - e),
- this._eventTarget.emit(a.InputType.TOUCH_END, t, e, s);
- }),
- (t.onPan = (t, e, i, s, o) => {
- o = o.target;
- 1 === this.touchFingers &&
- (this.screenCoord && ((e = cc.visibleRect.height - e), (s = -s)),
- this._eventTarget.emit(a.InputType.PAN, t, e, i, s, o));
- }),
- (t.onTap = (t, e, i) => {
- this.touchFingers = this.getFingerCount("onTap");
- i = i.target;
- this._eventTarget.emit(a.InputType.TAP, t, e, i);
- }),
- (t.holdStart = (t, e, i) => {
- i = i.target;
- (this.touchFingers = this.getFingerCount("holdStart")),
- 1 === this.touchFingers &&
- (this.screenCoord && (e = cc.visibleRect.height - e),
- this._eventTarget.emit(a.InputType.HOLD_START, t, e, i));
- }),
- (t.holdEnd = (t, e, i) => {
- this.touchFingers = this.getFingerCount("holdEnd");
- i = i.target;
- this.screenCoord && (e = cc.visibleRect.height - e),
- this._eventTarget.emit(a.InputType.HOLD_END, t, e, i);
- }),
- (t.onJoystickChanged = (t, e) => {
- const i = t.pressed,
- s = this.stickBaseNode,
- o = this.stickNode;
- i &&
- ((s.width = 2 * t.radius),
- (s.height = 2 * t.radius),
- s.setPosition(t.centerX - this.inputNode.width / 2, t.centerY - this.inputNode.height / 2),
- o.setPosition(t.x - this.inputNode.width / 2, t.y - this.inputNode.height / 2)),
- (o.active = i),
- (s.active = i),
- this.screenCoord && (t.rotation = -t.rotation);
- e = e.target;
- t.pressed && t.distance, this._eventTarget.emit(a.InputType.JOYSTICK, t, e);
- });
- }
- addEventListener(t, e, i, s) {
- this._eventTarget.on(t, e, i, s);
- }
- addEventListenerOnce(t, e, i, s) {
- this._eventTarget.once(t, e, i, s);
- }
- removeEventListener(t, e, i) {
- this._eventTarget.off(t, e, i);
- }
- onTouchStart(t, e, i) {
- this._eventTarget.on(a.InputType.TOUCH_START, t, e, i);
- }
- onTouchEnd(t, e, i) {
- this._eventTarget.on(a.InputType.TOUCH_END, t, e, i);
- }
- onPan(t, e, i) {
- this._eventTarget.on(a.InputType.PAN, t, e, i);
- }
- onTap(t, e, i) {
- this._eventTarget.on(a.InputType.TAP, t, e, i);
- }
- onHoldStart(t, e, i) {
- this._eventTarget.on(a.InputType.HOLD_START, t, e, i);
- }
- onHoldEnd(t, e, i) {
- this._eventTarget.on(a.InputType.HOLD_END, t, e, i);
- }
- onPinch(t, e, i) {
- this._eventTarget.on(a.InputType.PINCH, t, e, i);
- }
- onJoystickChanged(t, e, i) {
- this._eventTarget.on(a.InputType.JOYSTICK, t, e, i);
- }
- onKeyDown(t) {
- this._eventTarget.on(a.InputType.KEY_DOWN, t);
- }
- onKeyUp(t) {
- this._eventTarget.on(a.InputType.KEY_UP, t);
- }
- onMouseWheel(t) {
- this._eventTarget.on(a.InputType.MOUSE_WHEEL, t);
- }
- offTouchStart(t, e) {
- this._eventTarget.off(a.InputType.TOUCH_START, t, e);
- }
- offTouchEnd(t, e) {
- this._eventTarget.off(a.InputType.TOUCH_END, t, e);
- }
- offPan(t, e) {
- this._eventTarget.off(a.InputType.PAN, t, e);
- }
- offTap(t, e) {
- this._eventTarget.off(a.InputType.TAP, t, e);
- }
- offHoldStart(t, e) {
- this._eventTarget.off(a.InputType.HOLD_START, t, e);
- }
- offHoldEnd(t, e) {
- this._eventTarget.off(a.InputType.HOLD_END, t, e);
- }
- offPinch(t, e) {
- this._eventTarget.off(a.InputType.PINCH, t, e);
- }
- offJoystickChanged(t, e) {
- this._eventTarget.off(a.InputType.JOYSTICK, t, e);
- }
- offKeyDown(t) {
- this._eventTarget.off(a.InputType.KEY_DOWN, t);
- }
- offKeyUp(t) {
- this._eventTarget.off(a.InputType.KEY_UP, t);
- }
- offMouseWheel(t) {
- this._eventTarget.off(a.InputType.MOUSE_WHEEL, t);
- }
- initKeyboard() {
- cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.keyDownListener, this),
- cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.keyUpListener, this);
- }
- initMouse() {
- cc.systemEvent.on(cc.Node.EventType.MOUSE_WHEEL, this.mouseWheelListener, this);
- }
- getFingerCount(t) {
- return cc.internal.inputManager.getGlobalTouchCount();
- }
- keyDownListener(t) {
- this._eventTarget.emit(a.InputType.KEY_DOWN, t);
- }
- keyUpListener(t) {
- this._eventTarget.emit(a.InputType.KEY_UP, t);
- }
- mouseWheelListener(t) {
- this._eventTarget.emit(a.InputType.MOUSE_WHEEL, t);
- }
- lateUpdate(t) {}
- onDestroy() {
- this._eventTarget.clear(),
- (this._eventTarget = null),
- cc.systemEvent.off(cc.SystemEvent.EventType.KEY_DOWN, this.keyDownListener, this),
- cc.systemEvent.off(cc.SystemEvent.EventType.KEY_UP, this.keyUpListener, this),
- cc.systemEvent.off(cc.Node.EventType.MOUSE_WHEEL, this.mouseWheelListener, this);
- }
- };
- e([n(cc.Node)], r.prototype, "inputNode", void 0),
- e([n(cc.Node)], r.prototype, "stickBaseNode", void 0),
- e([n(cc.Node)], r.prototype, "stickNode", void 0),
- e([n()], r.prototype, "screenCoord", void 0),
- (r = e([o], r)),
- (a.default = r),
- (r.prototype.on = r.prototype.addEventListener),
- (r.prototype.once = r.prototype.addEventListenerOnce),
- (r.prototype.off = r.prototype.removeEventListener),
- (a.InputType = {
- TOUCH_START: "touchStart",
- TOUCH_END: "touchEnd",
- PAN: "pan",
- TAP: "tap",
- HOLD_START: "holdStart",
- HOLD_END: "holdEnd",
- PINCH: "pinch",
- JOYSTICK: "joystick",
- KEY_DOWN: "keyDown",
- KEY_UP: "keyUP",
- MOUSE_WHEEL: "mouseWheel"
- });
|