123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- var t = require;
- var e = module;
- var i = 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(i, "__esModule", { value: !0 });
- const s = t("App"),
- o = t("Draggable"),
- { ccclass: a, menu: n } = cc._decorator;
- (t = class extends cc.Component {
- constructor() {
- super(...arguments),
- (this.canDrop = !1),
- (this.delegate = {
- checkCanDrop: function() {
- return !0;
- },
- onDragIn: function() {
- return null;
- },
- onDragOut: function() {
- return null;
- },
- onDrop: function() {
- return null;
- },
- onDropCancel: function() {
- return null;
- },
- onDropEnd: function() {
- return null;
- }
- }),
- (this.isDragingIn = !1);
- }
- start() {}
- onEnable() {
- s.default.ViewManager.uiRoot.on(o.DragEventType.DRAG_START, this.onDragStart, this),
- s.default.ViewManager.uiRoot.on(o.DragEventType.DRAG_END, this.onDragEnd, this);
- }
- onDisable() {
- s.default.ViewManager.uiRoot.off(o.DragEventType.DRAG_START, this.onDragStart, this),
- s.default.ViewManager.uiRoot.off(o.DragEventType.DRAG_END, this.onDragEnd, this);
- }
- setTouchNode(t) {
- s.default.ViewManager.uiRoot.off(o.DragEventType.DRAG_START, this.onDragStart, this),
- s.default.ViewManager.uiRoot.off(o.DragEventType.DRAG_END, this.onDragEnd, this),
- s.default.ViewManager.uiRoot.on(o.DragEventType.DRAG_START, this.onDragStart, this),
- s.default.ViewManager.uiRoot.on(o.DragEventType.DRAG_END, this.onDragEnd, this);
- }
- setDelegate(t) {
- this.delegate = t;
- }
- onDragStart(t, e) {
- t.node != this.node &&
- ((this.dragingSource = t),
- (this.dragingData = e),
- s.default.ViewManager.uiRoot.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this, !0),
- (this.canDrop = this.delegate.checkCanDrop(this.dragingSource, this.dragingData)));
- }
- onDragEnd(t, e, i) {
- s.default.ViewManager.uiRoot.off(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
- i = this.node.getBoundingBoxToWorld().contains(i.getLocation());
- i && this.isDragingIn && this.canDrop ?
- (this.delegate.onDrop && this.delegate.onDrop(this.dragingSource, this.dragingData),
- this.node.emit(o.DragEventType.DROP, this, this.dragingData),
- t.onDragDone(e, this)) :
- i ||
- (this.delegate.onDropCancel && this.delegate.onDropCancel(this.dragingSource, this.dragingData),
- this.node.emit(o.DragEventType.CANCEL, this, this.dragingData)),
- this.canDrop &&
- (this.delegate.onDropEnd && this.delegate.onDropEnd(this.dragingSource, this.dragingData),
- this.node.emit(o.DragEventType.DRAG_END, this, this.dragingData)),
- (this.isDragingIn = !1),
- (this.dragingData = null),
- (this.dragingSource = null),
- (this.canDrop = !1);
- }
- onTouchMove(t) {
- t = this.node.getBoundingBoxToWorld().contains(t.getLocation());
- t
- ?
- this.canDrop &&
- (this.isDragingIn ?
- this.node.emit(o.DragEventType.DRAGING, this, this.dragingData) :
- ((this.isDragingIn = !0),
- this.delegate.onDragIn && this.delegate.onDragIn(this.dragingSource, this.dragingData),
- this.node.emit(o.DragEventType.DRAGING_IN, this, this.dragingData))) :
- !t &&
- this.isDragingIn &&
- this.canDrop &&
- ((this.isDragingIn = !1),
- this.delegate.onDragOut && this.delegate.onDragOut(this.dragingSource, this.dragingData),
- this.node.emit(o.DragEventType.DRAGING_OUT, this, this.dragingData));
- }
- }),
- (t = e([a], t));
- i.default = t;
|