GodGuide.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. var e =
  5. (this && this.__decorate) ||
  6. function (t, e, i, s) {
  7. var o,
  8. a = arguments.length,
  9. n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
  10. if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
  11. else
  12. for (var r = t.length - 1; 0 <= r; r--)
  13. (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
  14. return 3 < a && n && Object.defineProperty(e, i, n), n;
  15. },
  16. s =
  17. (this && this.__awaiter) ||
  18. function (t, n, r, l) {
  19. return new (r = r || Promise)(function (i, e) {
  20. function s(t) {
  21. try {
  22. a(l.next(t));
  23. } catch (t) {
  24. e(t);
  25. }
  26. }
  27. function o(t) {
  28. try {
  29. a(l.throw(t));
  30. } catch (t) {
  31. e(t);
  32. }
  33. }
  34. function a(t) {
  35. var e;
  36. t.done
  37. ? i(t.value)
  38. : ((e = t.value) instanceof r
  39. ? e
  40. : new r(function (t) {
  41. t(e);
  42. })
  43. ).then(s, o);
  44. }
  45. a((l = l.apply(t, n || [])).next());
  46. });
  47. };
  48. Object.defineProperty(i, "__esModule", {value: !0});
  49. const n = t("App"),
  50. o = t("SwitchFrame"),
  51. a = t("BaseView"),
  52. r = t("GuideModel"),
  53. l = t("Locator"),
  54. h = (2 * Math.PI) / 360;
  55. function c(t, e, i) {
  56. return [
  57. cc.v2(t.x, t.y),
  58. cc.v2(t.x + t.width, t.y),
  59. cc.v2(t.x + t.width, t.y + t.height),
  60. cc.v2(t.x, t.y + t.height)
  61. ].map(t =>
  62. (function (t, e, i) {
  63. let s = cc.v2(),
  64. o = -e * h;
  65. return (
  66. (s.x = (t.x - i.x) * Math.cos(o) - (t.y - i.y) * Math.sin(o) + i.x),
  67. (s.y = (t.x - i.x) * Math.sin(o) + (t.y - i.y) * Math.cos(o) + i.y),
  68. s
  69. );
  70. })(t, e, i)
  71. );
  72. }
  73. const {ccclass: d, property: u} = cc._decorator;
  74. t = class extends a.default {
  75. constructor() {
  76. super(...arguments),
  77. (this.closeType = 0),
  78. (this.FINGER_PREFAB = null),
  79. (this.TEXT_PREFAB = null),
  80. (this.skipBtn = null),
  81. (this.storyPrefab = null),
  82. (this.stroyObj = null),
  83. (this._checkPosFunc = null);
  84. }
  85. initUI() {
  86. super.initUI(), this.init();
  87. }
  88. touchSimulation(e) {
  89. this.log("自动执行,模拟触摸"),
  90. this.scheduleOnce(() => {
  91. cc.log("自动节点 :", JSON.stringify(e.position));
  92. var t = e.parent.convertToWorldSpaceAR(e.position);
  93. cc.log("世界节点 :", JSON.stringify(t)),
  94. (function (t, e) {
  95. let i,
  96. s = window._cc.inputManager;
  97. cc.sys.isBrowser
  98. ? ((r = document.getElementById("GameCanvas")), (i = s.getHTMLElementPosition(r)))
  99. : (((i = cc.view.getFrameSize()).left = 0), (i.top = 0));
  100. var o = cc.view.getViewportRect(),
  101. a = cc.view.getScaleX(),
  102. n = cc.view.getScaleY(),
  103. r = cc.view.getDevicePixelRatio(),
  104. a = (t * a + o.x) / r + i.left,
  105. r = i.top + i.height - (e * n + o.y) / r,
  106. r = cc.v2(a, r);
  107. cc.log(`\u6a21\u62df\u70b9\u51fb\u5750\u6807\uff1a${r.x}, ${r.y}`);
  108. let l = s.getTouchByXY(r.x, r.y, i);
  109. s.handleTouchesBegin([l]),
  110. setTimeout(() => {
  111. s.handleTouchesEnd([l]);
  112. }, 200);
  113. })(t.x, t.y);
  114. }, 1);
  115. }
  116. showSkip(t) {
  117. this.skipBtn.active = !!t;
  118. }
  119. init() {
  120. (this.node.getChildByName("SkipBtn").zIndex = 100),
  121. this.node.setContentSize(cc.winSize),
  122. (this._targetNode = null),
  123. this.FINGER_PREFAB &&
  124. ((this._finger = cc.instantiate(this.FINGER_PREFAB)),
  125. (this._finger.parent = this.node),
  126. (this._finger.active = !1)),
  127. this.TEXT_PREFAB &&
  128. ((this.text = cc.instantiate(this.TEXT_PREFAB)),
  129. (this.text.parent = this.node),
  130. (this.text.active = !1)),
  131. (this._mask = this.node.getComponentInChildren(cc.Mask)),
  132. (this._mask.inverted = !0),
  133. (this._mask.node.opacity = 0),
  134. this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this, !0);
  135. }
  136. onTouchSkin() {
  137. this.applyFunc(r.GuideConst.SKIN_GUIDE);
  138. }
  139. getStoryObj() {
  140. if (!this.stroyObj) {
  141. let t = cc.instantiate(this.storyPrefab);
  142. this.node.addChild(t),
  143. (this.stroyObj = {
  144. index: 0,
  145. node: t,
  146. items: [],
  147. label: t.getChildByName("Label").getComponent(cc.Label)
  148. }),
  149. t.getChildByName("skinBtn").on(cc.Node.EventType.TOUCH_END, this.onTouchSkin, this);
  150. for (const e of t.getChildByName("content").children)
  151. (e.active = !1), this.stroyObj.items.push({node: e, img: e.getComponent(o.default)});
  152. }
  153. return this.stroyObj;
  154. }
  155. stepFinish(t) {
  156. this._mask.node.active = !1;
  157. }
  158. enterStep(t) {
  159. this._mask.node.active = !0;
  160. }
  161. hideFinger() {
  162. this._finger && (this._finger.active = !1);
  163. }
  164. onTouchStart(t) {
  165. if (this._dispatchEvent) this.node._touchListener.setSwallowTouches(!1);
  166. else {
  167. if (this._mask.node.active)
  168. return this._targetNode
  169. ? void (this._targetNode._hitTest(t.getLocation(), this._targetNode)
  170. ? this.node._touchListener.setSwallowTouches(this._targetNode == this.node)
  171. : (this.node._touchListener.setSwallowTouches(!0),
  172. t.stopPropagationImmediate(),
  173. Log.trace("未命中目标节点,拦截")))
  174. : (t.stopPropagationImmediate(), void this.node._touchListener.setSwallowTouches(!0));
  175. this.node._touchListener.setSwallowTouches(!1);
  176. }
  177. }
  178. reset() {
  179. (this._targetNode = null), this.hideFinger(), this.hideText(), this.showSkip(0);
  180. }
  181. hideText() {
  182. this.text.getComponent(this.TEXT_PREFAB.name).hideText();
  183. }
  184. hideMask() {
  185. this._mask._graphics && this._mask._graphics.clear(), (this._mask.node.active = !1);
  186. }
  187. showMask(t) {
  188. (this._mask.node.active = !0), this._mask._graphics.clear(), (this._mask.node.opacity = -1 < t ? t : 255);
  189. }
  190. open() {
  191. super.open(), (this._mask.node.active = !1);
  192. }
  193. fingerToNode(t, e) {
  194. this._finger || e(), (this._finger.active = !0);
  195. let i = this.node.convertToNodeSpaceAR(t.parent.convertToWorldSpaceAR(t.position)),
  196. s = i.sub(this._finger.position).mag() / cc.winSize.height;
  197. this._finger.stopActionByTag(111), cc.tween(this._finger).to(s, {position: i}).call(e).tag(111).start();
  198. }
  199. fingerToNodeAsync(s) {
  200. return this._finger
  201. ? new Promise(t => {
  202. this._finger.active = !0;
  203. let e = this.node.convertToNodeSpaceAR(s),
  204. i = e.sub(this._finger.position).mag() / cc.winSize.height;
  205. cc.tween(this._finger).to(i, {position: e}).call(t).tag(111).start();
  206. })
  207. : Promise.resolve();
  208. }
  209. log(t) {}
  210. find(t, i, s = 0, o) {
  211. var e = cc.director.getScene();
  212. l.Locator.locateNode(e, t, (t, e) => {
  213. if (t) Log.trace(t);
  214. else {
  215. let t = e;
  216. for (; (t = t.parent), t; );
  217. n.default.TimerManager.setFrameOut(
  218. 2,
  219. () => {
  220. let t = this._focusToNode(e, s);
  221. o
  222. ? this.fingerToNode(e, () => {
  223. i(e, t);
  224. })
  225. : i(e, t);
  226. },
  227. this
  228. );
  229. }
  230. });
  231. }
  232. findAsync(a) {
  233. return s(this, void 0, void 0, function* () {
  234. let t = cc.director.getScene(),
  235. {error: e, node: i} = yield l.Locator.locateNodeSync(t, a.args);
  236. if (!e) {
  237. yield n.default.TimerManager.sleepFrame(2), this._focusToNode(i, a.type), a.isShowFinger;
  238. {
  239. const t = a.fy || 0;
  240. this._finger.getChildByName("hand").anchorY = 1 + i.height / 2 / this._finger.height;
  241. var s = i.convertToWorldSpaceAR(cc.v2(a.fX || 0, t));
  242. const o = cc.Camera.findCamera(i);
  243. (this._finger.angle = a.angle || 0), o.getWorldToScreenPoint(s, s), yield this.fingerToNodeAsync(s);
  244. }
  245. return i;
  246. }
  247. Log.trace(e);
  248. });
  249. }
  250. clearCheckPosFuncTimer() {
  251. this._checkPosFunc && (n.default.TimerManager.remove(this._checkPosFunc, this), (this._checkPosFunc = null));
  252. }
  253. checkPos(e, i, s, o) {
  254. let a = e.convertToWorldSpaceAR(o);
  255. this.clearCheckPosFuncTimer(),
  256. (this._checkPosFunc = () => {
  257. var t = e.convertToWorldSpaceAR(o);
  258. (a.x == t.x && a.y == t.y) || ((a = t), this._focusToNode(e, i), s && this.fingerToNodeAsync(t));
  259. }),
  260. n.default.TimerManager.doFrame(100, 0, this._checkPosFunc, this);
  261. }
  262. getNodePoints(t, e, i) {
  263. return c(t, e, i).map(t => t);
  264. }
  265. fillPolygon(t) {
  266. var e = t[0];
  267. this._mask._graphics.moveTo(e.x, e.y),
  268. t.slice(1).forEach(t => {
  269. this._mask._graphics.lineTo(t.x, t.y);
  270. }),
  271. this._mask._graphics.lineTo(e.x, e.y),
  272. this._mask._graphics.stroke(),
  273. this._mask._graphics.fill();
  274. }
  275. fillPoints(t) {
  276. var e = t[0];
  277. this._mask._graphics.moveTo(e.x, e.y),
  278. t.slice(1).forEach(t => {
  279. this._mask._graphics.lineTo(t.x, t.y);
  280. }),
  281. this._mask._graphics.lineTo(e.x, e.y),
  282. this._mask._graphics.stroke(),
  283. this._mask._graphics.fill();
  284. }
  285. _focusToNode(t, e = 0) {
  286. this._mask._graphics.clear();
  287. var i = t.getBoundingBoxToWorld();
  288. const s = cc.Camera.findCamera(t),
  289. o = i.center;
  290. return (
  291. s.getWorldToScreenPoint(o, o),
  292. this.node.convertToNodeSpaceAR(o, o),
  293. 0 === e
  294. ? ((e = t.width > t.height ? t.width / 2 : t.height / 2 + 10), this._mask._graphics.circle(o.x, o.y, e))
  295. : this._mask._graphics.roundRect(o.x - t.width / 2, o.y - t.height / 2, t.width, t.height, 10),
  296. this._mask._graphics.fill(),
  297. i
  298. );
  299. }
  300. getNodeFullPath(t) {
  301. let e = [],
  302. i = t;
  303. for (; "GameScene" !== i.name && e.unshift(i.name), (i = i.parent), i && "Canvas" !== i.name; );
  304. return e.join("/");
  305. }
  306. isGuideNode(t) {
  307. let e = !1,
  308. i = t;
  309. do {
  310. if (i === this.node) {
  311. e = !0;
  312. break;
  313. }
  314. } while ((i = i.parent));
  315. return e;
  316. }
  317. startRecordNodeTouch() {
  318. if (this._dispatchEvent) cc.warn("已经进入录制模式");
  319. else {
  320. (this._dispatchEvent = cc.Node.prototype.dispatchEvent), (this._recordSteps = []);
  321. let s = this,
  322. o = Date.now();
  323. cc.Node.prototype.dispatchEvent = function (t) {
  324. var e, i;
  325. s.isGuideNode(this) ||
  326. (t.type === cc.Node.EventType.TOUCH_END &&
  327. ((e = ((i = Date.now()) - o) / 1e3),
  328. (o = i),
  329. (i = s.getNodeFullPath(this)),
  330. s._recordSteps.push({arg1: i, delay: e}))),
  331. s._dispatchEvent.call(this, t);
  332. };
  333. }
  334. }
  335. stopRecordNodeTouch() {
  336. this._dispatchEvent
  337. ? ((cc.Node.prototype.dispatchEvent = this._dispatchEvent),
  338. (this._dispatchEvent = null),
  339. cc.warn("退出录制状态"))
  340. : cc.warn("未进入录制状态");
  341. }
  342. playRecordNodeTouch() {
  343. this.stopRecordNodeTouch(),
  344. this._recordSteps && this._recordSteps.length && cc.log("生成任务:", console.table(this._recordSteps));
  345. }
  346. showText(t, e) {
  347. let i = this.text.getChildByName("Body").getComponent(cc.Widget);
  348. switch (t.ani) {
  349. case "l":
  350. (this.text.x = -cc.winSize.width / 2),
  351. cc.tween(this.text).to(0.5, {x: 0}, {easing: cc.easing.cubicOut}).start();
  352. break;
  353. case "r":
  354. (this.text.x = cc.winSize.width / 2),
  355. cc.tween(this.text).to(0.5, {x: 0}, {easing: cc.easing.cubicOut}).start();
  356. break;
  357. default:
  358. this.text.x = 0;
  359. }
  360. if (t.pos) {
  361. const e = t.pos;
  362. switch (((i.isAlignVerticalCenter = i.isAlignTop = i.isAlignBottom = !1), e[0])) {
  363. case "v":
  364. (i.isAlignVerticalCenter = !0), (i.verticalCenter = parseInt(e.slice(1)));
  365. break;
  366. case "t":
  367. (i.isAlignTop = !0), (i.top = parseInt(e.slice(1)));
  368. break;
  369. case "b":
  370. (i.isAlignBottom = !0), (i.bottom = parseInt(e.slice(1)));
  371. break;
  372. default:
  373. (i.isAlignBottom = !0), (i.bottom = 155);
  374. }
  375. } else (i.isAlignVerticalCenter = !1), (i.isAlignTop = !1), (i.isAlignBottom = !0), (i.bottom = 155);
  376. this.text.getComponent(this.TEXT_PREFAB.name).setText(t, () => {
  377. this.text.off(cc.Node.EventType.TOUCH_END), (this._targetNode = null), e && e();
  378. });
  379. }
  380. onTouchStartGuideBtn() {
  381. this.applyFunc(r.GuideConst.OPEN_GUIDE);
  382. }
  383. close() {
  384. super.close(), (this.node.active = !1);
  385. }
  386. };
  387. e([u(cc.Prefab)], t.prototype, "FINGER_PREFAB", void 0),
  388. e([u(cc.Prefab)], t.prototype, "TEXT_PREFAB", void 0),
  389. e([u(cc.Node)], t.prototype, "skipBtn", void 0),
  390. e([u(cc.Prefab)], t.prototype, "storyPrefab", void 0),
  391. (t = e([d], t)),
  392. (i.default = t);