123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392 |
- var t = require;
- var e = module;
- var i = exports;
- var 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;
- },
- s =
- (this && this.__awaiter) ||
- function (t, n, r, l) {
- return new (r = r || Promise)(function (i, e) {
- function s(t) {
- try {
- a(l.next(t));
- } catch (t) {
- e(t);
- }
- }
- function o(t) {
- try {
- a(l.throw(t));
- } catch (t) {
- e(t);
- }
- }
- function a(t) {
- var e;
- t.done
- ? i(t.value)
- : ((e = t.value) instanceof r
- ? e
- : new r(function (t) {
- t(e);
- })
- ).then(s, o);
- }
- a((l = l.apply(t, n || [])).next());
- });
- };
- Object.defineProperty(i, "__esModule", {value: !0});
- const n = t("App"),
- o = t("SwitchFrame"),
- a = t("BaseView"),
- r = t("GuideModel"),
- l = t("Locator"),
- h = (2 * Math.PI) / 360;
- function c(t, e, i) {
- return [
- cc.v2(t.x, t.y),
- cc.v2(t.x + t.width, t.y),
- cc.v2(t.x + t.width, t.y + t.height),
- cc.v2(t.x, t.y + t.height)
- ].map(t =>
- (function (t, e, i) {
- let s = cc.v2(),
- o = -e * h;
- return (
- (s.x = (t.x - i.x) * Math.cos(o) - (t.y - i.y) * Math.sin(o) + i.x),
- (s.y = (t.x - i.x) * Math.sin(o) + (t.y - i.y) * Math.cos(o) + i.y),
- s
- );
- })(t, e, i)
- );
- }
- const {ccclass: d, property: u} = cc._decorator;
- t = class extends a.default {
- constructor() {
- super(...arguments),
- (this.closeType = 0),
- (this.FINGER_PREFAB = null),
- (this.TEXT_PREFAB = null),
- (this.skipBtn = null),
- (this.storyPrefab = null),
- (this.stroyObj = null),
- (this._checkPosFunc = null);
- }
- initUI() {
- super.initUI(), this.init();
- }
- touchSimulation(e) {
- this.log("自动执行,模拟触摸"),
- this.scheduleOnce(() => {
- cc.log("自动节点 :", JSON.stringify(e.position));
- var t = e.parent.convertToWorldSpaceAR(e.position);
- cc.log("世界节点 :", JSON.stringify(t)),
- (function (t, e) {
- let i,
- s = window._cc.inputManager;
- cc.sys.isBrowser
- ? ((r = document.getElementById("GameCanvas")), (i = s.getHTMLElementPosition(r)))
- : (((i = cc.view.getFrameSize()).left = 0), (i.top = 0));
- var o = cc.view.getViewportRect(),
- a = cc.view.getScaleX(),
- n = cc.view.getScaleY(),
- r = cc.view.getDevicePixelRatio(),
- a = (t * a + o.x) / r + i.left,
- r = i.top + i.height - (e * n + o.y) / r,
- r = cc.v2(a, r);
- cc.log(`\u6a21\u62df\u70b9\u51fb\u5750\u6807\uff1a${r.x}, ${r.y}`);
- let l = s.getTouchByXY(r.x, r.y, i);
- s.handleTouchesBegin([l]),
- setTimeout(() => {
- s.handleTouchesEnd([l]);
- }, 200);
- })(t.x, t.y);
- }, 1);
- }
- showSkip(t) {
- this.skipBtn.active = !!t;
- }
- init() {
- (this.node.getChildByName("SkipBtn").zIndex = 100),
- this.node.setContentSize(cc.winSize),
- (this._targetNode = null),
- this.FINGER_PREFAB &&
- ((this._finger = cc.instantiate(this.FINGER_PREFAB)),
- (this._finger.parent = this.node),
- (this._finger.active = !1)),
- this.TEXT_PREFAB &&
- ((this.text = cc.instantiate(this.TEXT_PREFAB)),
- (this.text.parent = this.node),
- (this.text.active = !1)),
- (this._mask = this.node.getComponentInChildren(cc.Mask)),
- (this._mask.inverted = !0),
- (this._mask.node.opacity = 0),
- this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this, !0);
- }
- onTouchSkin() {
- this.applyFunc(r.GuideConst.SKIN_GUIDE);
- }
- getStoryObj() {
- if (!this.stroyObj) {
- let t = cc.instantiate(this.storyPrefab);
- this.node.addChild(t),
- (this.stroyObj = {
- index: 0,
- node: t,
- items: [],
- label: t.getChildByName("Label").getComponent(cc.Label)
- }),
- t.getChildByName("skinBtn").on(cc.Node.EventType.TOUCH_END, this.onTouchSkin, this);
- for (const e of t.getChildByName("content").children)
- (e.active = !1), this.stroyObj.items.push({node: e, img: e.getComponent(o.default)});
- }
- return this.stroyObj;
- }
- stepFinish(t) {
- this._mask.node.active = !1;
- }
- enterStep(t) {
- this._mask.node.active = !0;
- }
- hideFinger() {
- this._finger && (this._finger.active = !1);
- }
- onTouchStart(t) {
- if (this._dispatchEvent) this.node._touchListener.setSwallowTouches(!1);
- else {
- if (this._mask.node.active)
- return this._targetNode
- ? void (this._targetNode._hitTest(t.getLocation(), this._targetNode)
- ? this.node._touchListener.setSwallowTouches(this._targetNode == this.node)
- : (this.node._touchListener.setSwallowTouches(!0),
- t.stopPropagationImmediate(),
- Log.trace("未命中目标节点,拦截")))
- : (t.stopPropagationImmediate(), void this.node._touchListener.setSwallowTouches(!0));
- this.node._touchListener.setSwallowTouches(!1);
- }
- }
- reset() {
- (this._targetNode = null), this.hideFinger(), this.hideText(), this.showSkip(0);
- }
- hideText() {
- this.text.getComponent(this.TEXT_PREFAB.name).hideText();
- }
- hideMask() {
- this._mask._graphics && this._mask._graphics.clear(), (this._mask.node.active = !1);
- }
- showMask(t) {
- (this._mask.node.active = !0), this._mask._graphics.clear(), (this._mask.node.opacity = -1 < t ? t : 255);
- }
- open() {
- super.open(), (this._mask.node.active = !1);
- }
- fingerToNode(t, e) {
- this._finger || e(), (this._finger.active = !0);
- let i = this.node.convertToNodeSpaceAR(t.parent.convertToWorldSpaceAR(t.position)),
- s = i.sub(this._finger.position).mag() / cc.winSize.height;
- this._finger.stopActionByTag(111), cc.tween(this._finger).to(s, {position: i}).call(e).tag(111).start();
- }
- fingerToNodeAsync(s) {
- return this._finger
- ? new Promise(t => {
- this._finger.active = !0;
- let e = this.node.convertToNodeSpaceAR(s),
- i = e.sub(this._finger.position).mag() / cc.winSize.height;
- cc.tween(this._finger).to(i, {position: e}).call(t).tag(111).start();
- })
- : Promise.resolve();
- }
- log(t) {}
- find(t, i, s = 0, o) {
- var e = cc.director.getScene();
- l.Locator.locateNode(e, t, (t, e) => {
- if (t) Log.trace(t);
- else {
- let t = e;
- for (; (t = t.parent), t; );
- n.default.TimerManager.setFrameOut(
- 2,
- () => {
- let t = this._focusToNode(e, s);
- o
- ? this.fingerToNode(e, () => {
- i(e, t);
- })
- : i(e, t);
- },
- this
- );
- }
- });
- }
- findAsync(a) {
- return s(this, void 0, void 0, function* () {
- let t = cc.director.getScene(),
- {error: e, node: i} = yield l.Locator.locateNodeSync(t, a.args);
- if (!e) {
- yield n.default.TimerManager.sleepFrame(2), this._focusToNode(i, a.type), a.isShowFinger;
- {
- const t = a.fy || 0;
- this._finger.getChildByName("hand").anchorY = 1 + i.height / 2 / this._finger.height;
- var s = i.convertToWorldSpaceAR(cc.v2(a.fX || 0, t));
- const o = cc.Camera.findCamera(i);
- (this._finger.angle = a.angle || 0), o.getWorldToScreenPoint(s, s), yield this.fingerToNodeAsync(s);
- }
- return i;
- }
- Log.trace(e);
- });
- }
- clearCheckPosFuncTimer() {
- this._checkPosFunc && (n.default.TimerManager.remove(this._checkPosFunc, this), (this._checkPosFunc = null));
- }
- checkPos(e, i, s, o) {
- let a = e.convertToWorldSpaceAR(o);
- this.clearCheckPosFuncTimer(),
- (this._checkPosFunc = () => {
- var t = e.convertToWorldSpaceAR(o);
- (a.x == t.x && a.y == t.y) || ((a = t), this._focusToNode(e, i), s && this.fingerToNodeAsync(t));
- }),
- n.default.TimerManager.doFrame(100, 0, this._checkPosFunc, this);
- }
- getNodePoints(t, e, i) {
- return c(t, e, i).map(t => t);
- }
- fillPolygon(t) {
- var e = t[0];
- this._mask._graphics.moveTo(e.x, e.y),
- t.slice(1).forEach(t => {
- this._mask._graphics.lineTo(t.x, t.y);
- }),
- this._mask._graphics.lineTo(e.x, e.y),
- this._mask._graphics.stroke(),
- this._mask._graphics.fill();
- }
- fillPoints(t) {
- var e = t[0];
- this._mask._graphics.moveTo(e.x, e.y),
- t.slice(1).forEach(t => {
- this._mask._graphics.lineTo(t.x, t.y);
- }),
- this._mask._graphics.lineTo(e.x, e.y),
- this._mask._graphics.stroke(),
- this._mask._graphics.fill();
- }
- _focusToNode(t, e = 0) {
- this._mask._graphics.clear();
- var i = t.getBoundingBoxToWorld();
- const s = cc.Camera.findCamera(t),
- o = i.center;
- return (
- s.getWorldToScreenPoint(o, o),
- this.node.convertToNodeSpaceAR(o, o),
- 0 === e
- ? ((e = t.width > t.height ? t.width / 2 : t.height / 2 + 10), this._mask._graphics.circle(o.x, o.y, e))
- : this._mask._graphics.roundRect(o.x - t.width / 2, o.y - t.height / 2, t.width, t.height, 10),
- this._mask._graphics.fill(),
- i
- );
- }
- getNodeFullPath(t) {
- let e = [],
- i = t;
- for (; "GameScene" !== i.name && e.unshift(i.name), (i = i.parent), i && "Canvas" !== i.name; );
- return e.join("/");
- }
- isGuideNode(t) {
- let e = !1,
- i = t;
- do {
- if (i === this.node) {
- e = !0;
- break;
- }
- } while ((i = i.parent));
- return e;
- }
- startRecordNodeTouch() {
- if (this._dispatchEvent) cc.warn("已经进入录制模式");
- else {
- (this._dispatchEvent = cc.Node.prototype.dispatchEvent), (this._recordSteps = []);
- let s = this,
- o = Date.now();
- cc.Node.prototype.dispatchEvent = function (t) {
- var e, i;
- s.isGuideNode(this) ||
- (t.type === cc.Node.EventType.TOUCH_END &&
- ((e = ((i = Date.now()) - o) / 1e3),
- (o = i),
- (i = s.getNodeFullPath(this)),
- s._recordSteps.push({arg1: i, delay: e}))),
- s._dispatchEvent.call(this, t);
- };
- }
- }
- stopRecordNodeTouch() {
- this._dispatchEvent
- ? ((cc.Node.prototype.dispatchEvent = this._dispatchEvent),
- (this._dispatchEvent = null),
- cc.warn("退出录制状态"))
- : cc.warn("未进入录制状态");
- }
- playRecordNodeTouch() {
- this.stopRecordNodeTouch(),
- this._recordSteps && this._recordSteps.length && cc.log("生成任务:", console.table(this._recordSteps));
- }
- showText(t, e) {
- let i = this.text.getChildByName("Body").getComponent(cc.Widget);
- switch (t.ani) {
- case "l":
- (this.text.x = -cc.winSize.width / 2),
- cc.tween(this.text).to(0.5, {x: 0}, {easing: cc.easing.cubicOut}).start();
- break;
- case "r":
- (this.text.x = cc.winSize.width / 2),
- cc.tween(this.text).to(0.5, {x: 0}, {easing: cc.easing.cubicOut}).start();
- break;
- default:
- this.text.x = 0;
- }
- if (t.pos) {
- const e = t.pos;
- switch (((i.isAlignVerticalCenter = i.isAlignTop = i.isAlignBottom = !1), e[0])) {
- case "v":
- (i.isAlignVerticalCenter = !0), (i.verticalCenter = parseInt(e.slice(1)));
- break;
- case "t":
- (i.isAlignTop = !0), (i.top = parseInt(e.slice(1)));
- break;
- case "b":
- (i.isAlignBottom = !0), (i.bottom = parseInt(e.slice(1)));
- break;
- default:
- (i.isAlignBottom = !0), (i.bottom = 155);
- }
- } else (i.isAlignVerticalCenter = !1), (i.isAlignTop = !1), (i.isAlignBottom = !0), (i.bottom = 155);
- this.text.getComponent(this.TEXT_PREFAB.name).setText(t, () => {
- this.text.off(cc.Node.EventType.TOUCH_END), (this._targetNode = null), e && e();
- });
- }
- onTouchStartGuideBtn() {
- this.applyFunc(r.GuideConst.OPEN_GUIDE);
- }
- close() {
- super.close(), (this.node.active = !1);
- }
- };
- e([u(cc.Prefab)], t.prototype, "FINGER_PREFAB", void 0),
- e([u(cc.Prefab)], t.prototype, "TEXT_PREFAB", void 0),
- e([u(cc.Node)], t.prototype, "skipBtn", void 0),
- e([u(cc.Prefab)], t.prototype, "storyPrefab", void 0),
- (t = e([d], t)),
- (i.default = t);
|