GuideController.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. var s =
  5. (this && this.__awaiter) ||
  6. function (t, n, r, l) {
  7. return new (r = r || Promise)(function (i, e) {
  8. function s(t) {
  9. try {
  10. a(l.next(t));
  11. } catch (t) {
  12. e(t);
  13. }
  14. }
  15. function o(t) {
  16. try {
  17. a(l.throw(t));
  18. } catch (t) {
  19. e(t);
  20. }
  21. }
  22. function a(t) {
  23. var e;
  24. t.done
  25. ? i(t.value)
  26. : ((e = t.value) instanceof r
  27. ? e
  28. : new r(function (t) {
  29. t(e);
  30. })
  31. ).then(s, o);
  32. }
  33. a((l = l.apply(t, n || [])).next());
  34. });
  35. };
  36. Object.defineProperty(i, "__esModule", {value: !0});
  37. const o = t("App"),
  38. a = t("Actions"),
  39. n = t("SubTree"),
  40. l = t("GameText"),
  41. r = t("BaseController"),
  42. h = t("EffectUtils"),
  43. c = t("ViewAni"),
  44. d = t("ConfigManager"),
  45. u = t("NotificationConst"),
  46. p = (t("ViewConst"), t("LayerManager"), t("CurrencyService")),
  47. f = t("MachineService"),
  48. g = t("MapService"),
  49. m = t("SystemOpenConst"),
  50. _ = t("SystemOpenController"),
  51. y = t("B3Tree1"),
  52. v = t("GuideModel");
  53. class U extends r.default {
  54. constructor() {
  55. super(),
  56. (this._model = null),
  57. (this.godGuide = null),
  58. (this.isSkip = null),
  59. (this.curId = null),
  60. (this.tree = null),
  61. (this.blackboard = null),
  62. (this.notification = null),
  63. (this.cb = null),
  64. (this.param = null),
  65. (this._typerTimer = null),
  66. (this._isTest = !1),
  67. (this.eventRefMap = {}),
  68. (this.isCheckCd = !1),
  69. this.setModel(new v.GuideModel(this)),
  70. o.default.SaveManage.add(this._model, "GUIDE_DATA", !0, !0),
  71. this.addEventKeyMap(v.GuideConst),
  72. o.default.ViewManager.register(15, {prefabName: "GodGuide", zIndex: 200, dir: "guide", controller: this}),
  73. o.default.NotificationCenter.addListener(u.NotificationConst.INIT_GAME_FINISH, this.init, this);
  74. }
  75. init() {
  76. o.default.NotificationCenter.removeListener(u.NotificationConst.INIT_GAME_FINISH, this.init, this),
  77. this.initModuleEvent(),
  78. this.initNotificationEvent(),
  79. this.initData();
  80. }
  81. initData() {
  82. o.default.SaveManage.load("GUIDE_DATA"), this.loadTree();
  83. }
  84. setIsCanPlayAni(t) {
  85. (c.default.isCanPlayAni = t), (U.isGuide = !t);
  86. }
  87. listenNotifiaction(t) {
  88. this.notification &&
  89. "" != this.notification &&
  90. ((this.param = null),
  91. o.default.NotificationCenter.removeListener(this.notification, this.listenNotifiaction, this)),
  92. o.default.TimerManager.remove(this.listenNotifiaction, this),
  93. this.godGuide.clearCheckPosFuncTimer(),
  94. this.tick();
  95. }
  96. wait(t, e, i) {
  97. e &&
  98. "" != e &&
  99. ((this.notification = e),
  100. (this.param = i),
  101. o.default.NotificationCenter.addListener(e, this.listenNotifiaction, this)),
  102. t && o.default.TimerManager.doTimer(t, 1, this.listenNotifiaction, this);
  103. }
  104. showStory(n) {
  105. this.clearTyperTimer();
  106. let r = this.godGuide.getStoryObj(),
  107. t = r.items[r.index++];
  108. (t.node.active = !0), (r.label.string = ""), (t.img.frameIndex = 1);
  109. var e = () => {
  110. let a = n.i18 ? l.GameText.getTextByStr(n.i18) : n.str;
  111. if (
  112. (cc
  113. .tween(t.img.node)
  114. .call(() => {
  115. t.img.frameIndex = 0;
  116. })
  117. .delay(0.7)
  118. .call(() => {
  119. t.img.frameIndex = 1;
  120. })
  121. .delay(0.7)
  122. .union()
  123. .repeatForever()
  124. .start(),
  125. n.typerAniTime)
  126. ) {
  127. this.godGuide._targetNode = r.node;
  128. let e = a.split("|"),
  129. i = e.length,
  130. s = 0,
  131. o = !0,
  132. t = () => {
  133. let t = e[s];
  134. (o = !1),
  135. (this._typerTimer = h.default.instance.typerEffect(
  136. r.label,
  137. t.replace(/\\n/g, "\n"),
  138. n.typerAniTime,
  139. () => {
  140. (o = !0), i === ++s ? this.typerFinish() : (r.label.string = t);
  141. },
  142. this
  143. ));
  144. };
  145. t(),
  146. r.node.on(
  147. cc.Node.EventType.TOUCH_END,
  148. () => {
  149. this.clearTyperTimer(),
  150. i === s
  151. ? (this.typerFinish(),
  152. (this.godGuide._targetNode = null),
  153. (r.label.string = e[e.length - 1]))
  154. : o
  155. ? t()
  156. : ((o = !0), (r.label.string = e[s]), s++);
  157. },
  158. this
  159. );
  160. } else (r.label.string = a.replace(/\\n/g, "\n")), this.typerFinish();
  161. };
  162. r.index % 2 ? (t.node.x = -860) : (t.node.x = 860),
  163. cc.tween(t.node).to(0.7, {x: 0}, {easing: cc.easing.cubicOut}).call(e).start();
  164. }
  165. hideStory() {
  166. this.clearTyperTimer();
  167. let t = this.godGuide.getStoryObj();
  168. cc.tween(t.node)
  169. .to(0.7, {x: -cc.winSize.width}, {easing: cc.easing.cubicOut})
  170. .call(() => {
  171. (t.node.active = !1), this.tick();
  172. })
  173. .start();
  174. }
  175. removeStory() {
  176. this.clearTyperTimer();
  177. let t = this.godGuide.getStoryObj();
  178. cc.tween(t.node)
  179. .to(0.5, {x: -cc.winSize.width}, {easing: cc.easing.cubicOut})
  180. .call(() => {
  181. t.node.active = !1;
  182. })
  183. .start();
  184. }
  185. typerFinish() {
  186. o.default.TimerManager.setFrameOut(1, this.waitTouch, this),
  187. this.godGuide.getStoryObj().node.off(cc.Node.EventType.TOUCH_END),
  188. (this._typerTimer = null);
  189. }
  190. clearTyperTimer() {
  191. this._typerTimer && (o.default.TimerManager.remove(this._typerTimer, null), (this._typerTimer = null));
  192. }
  193. waitTouch(t) {
  194. this.godGuide._targetNode || (this.godGuide._targetNode = this.godGuide.node),
  195. t && this.godGuide.node.once(cc.Node.EventType.TOUCH_END, this.onTouchTarget, this),
  196. this.godGuide._targetNode.once(cc.Node.EventType.TOUCH_END, this.onTouchTarget, this);
  197. }
  198. onTouchTarget() {
  199. this.godGuide._targetNode &&
  200. ((this.godGuide._targetNode = null),
  201. this.godGuide.clearCheckPosFuncTimer(),
  202. o.default.TimerManager.setFrameOut(
  203. 1,
  204. () => {
  205. this.tick();
  206. },
  207. this
  208. ));
  209. }
  210. locatorTouchNode(t, e, i, s = 0) {
  211. this.godGuide.find(
  212. t,
  213. t => {
  214. (this.godGuide._targetNode = t), i(), this.tick();
  215. },
  216. s,
  217. e
  218. );
  219. }
  220. locatorTouchNodeAsync(e, i) {
  221. return s(this, void 0, void 0, function* () {
  222. var t = yield this.godGuide.findAsync(e);
  223. (this.godGuide._targetNode = t), i && i(), this.tick();
  224. });
  225. }
  226. hideMask() {
  227. this.godGuide && this.godGuide.hideMask();
  228. }
  229. showMask(t) {
  230. this.godGuide.showMask(t), (this.godGuide._targetNode = this.godGuide.node);
  231. }
  232. showSkip(t, e) {
  233. t && e
  234. ? o.default.TimerManager.doTimer(e, 1, this.delayShowSkip, this)
  235. : (o.default.TimerManager.remove(this.delayShowSkip, this), this.godGuide.showSkip(t));
  236. }
  237. delayShowSkip() {
  238. this.godGuide.showSkip(1);
  239. }
  240. setStep(t, e = this.curId) {
  241. this._model.setStep(this.curId, t),
  242. -1 === t &&
  243. (this.godGuide.stepFinish(this.curId),
  244. o.default.NotificationCenter.dispatch(u.NotificationConst.GUIDE_STEP_FINISH, e));
  245. }
  246. openGuideView() {
  247. h.default.instance.queueExecutor.regist(() => {
  248. this.setIsCanPlayAni(!1),
  249. o.default.NotificationCenter.dispatch(u.NotificationConst.START_GUIDE),
  250. o.default.TimerManager.doTimer(
  251. 1,
  252. 1,
  253. () => {
  254. o.default.ViewManager.open(15, !0), h.default.instance.queueExecutor.finishFunc();
  255. },
  256. this
  257. );
  258. }, this);
  259. }
  260. skinGuide(t) {
  261. return s(this, void 0, void 0, function* () {
  262. yield o.default.TimerManager.sleep(500),
  263. o.default.ViewManager.close(15),
  264. t
  265. ? this.testSkinGuide()
  266. : -1 < this.curId &&
  267. (this._model.setStep(this.curId, -1),
  268. (this.blackboard = new y.b3.Blackboard()),
  269. this.godGuide.reset(),
  270. this.tick());
  271. });
  272. }
  273. checkStep(t) {
  274. return this.isSkip && this._model.setStep(this.curId, -1), this._model.checkStep(this.curId, t);
  275. }
  276. showArrow(t) {}
  277. showTip(t) {
  278. this.godGuide.showText(t, () => {
  279. o.default.TimerManager.setFrameOut(1, this.tick, this);
  280. });
  281. }
  282. hideTip() {
  283. this.godGuide.hideText();
  284. }
  285. testSkinGuide() {
  286. (this.isSkip = !0), (this.blackboard = new y.b3.Blackboard()), this.tick();
  287. }
  288. loadTree() {
  289. this.tree = new y.b3.BehaviorTree();
  290. let i = o.default.ConfigManager.getConfig("guideConf");
  291. if (i.trees) {
  292. const s = /^\(?\d+\)/;
  293. n.default.setSubTreeLoadFunc(t => {
  294. for (const e of i.trees)
  295. if (e.title.replace(s, "") === t.properties.path || e.properties.path === t.properties.path) {
  296. t.loadDataFinish(e);
  297. break;
  298. }
  299. });
  300. for (const t of i.trees)
  301. if ("主树" == t.title || (t.properties && "主树" == t.properties.path)) {
  302. this.tree.load(t, a.Actions);
  303. break;
  304. }
  305. } else this.tree.load(i, a.Actions);
  306. this.blackboard = new y.b3.Blackboard();
  307. }
  308. tick() {
  309. this.tree &&
  310. (this.tree.tick(this, this.blackboard) === y.b3.RUNNING
  311. ? this.setIsCanPlayAni(!1)
  312. : U.isGuide && (this.setIsCanPlayAni(!0), o.default.ViewManager.close(15)));
  313. }
  314. onOpenView(t) {
  315. t.viewId,
  316. o.default.ViewManager.closeAll([4, 2, 6, 0, 15, 29, 23, 24, 39]),
  317. (c.default.isCanPlayAni = !1),
  318. o.default.TimerManager.doFrame(1, 1, this.tick, this);
  319. }
  320. on_OPEN_GUIDE(t) {
  321. isNaN(t) || this.setStep(0, t), this.tick();
  322. }
  323. addEvent(t, e) {
  324. this.eventRefMap[t]
  325. ? -1 === this.eventRefMap[t].indexOf(e) && this.eventRefMap[t].push(e)
  326. : ((this.eventRefMap[t] = [e]), o.default.NotificationCenter.addListener(t, this.checkIsGuide, this));
  327. }
  328. removeEvent(t, e) {
  329. !this.eventRefMap[t] ||
  330. (-1 !== (e = this.eventRefMap[t].indexOf(e)) &&
  331. (this.eventRefMap[t].splice(e, 1),
  332. 0 === this.eventRefMap[t].length &&
  333. (delete this.eventRefMap[t],
  334. o.default.NotificationCenter.removeListener(t, this.checkIsGuide, this))));
  335. }
  336. checkNewGuideIsOpen(t) {
  337. if (t.mapId && t.mapId !== g.default.ins.curId) return !1;
  338. if (this._model.checkIsFinish(t.id)) return !1;
  339. if (this.isSkip) return this._model.setStep(t.id, -1), !1;
  340. if (t.open) {
  341. if (!_.default.ins.checkSystemOpen(m.OpenTypeConst[t.open]))
  342. return this.addEvent(u.NotificationConst.SYS_OPEN, t.id), !1;
  343. this.removeEvent(u.NotificationConst.SYS_OPEN, t.id);
  344. }
  345. if (t.machinLvCnt) {
  346. if (t.machinLvCnt > f.default.ins.getMachinAllLvCnt())
  347. return this.addEvent(u.NotificationConst.MACHINE_UPDATE, t.id), !1;
  348. this.removeEvent(u.NotificationConst.MACHINE_UPDATE, t.id);
  349. }
  350. if (t.money) {
  351. if (!p.default.ins.checkMoneyEnough(t.money))
  352. return this.addEvent(u.NotificationConst.UPDATE_MONEY, t.id), !1;
  353. this.removeEvent(u.NotificationConst.UPDATE_MONEY, t.id);
  354. }
  355. return (this.curId = t.id), Log.trace("进入新手引导:", this.curId), !0;
  356. }
  357. initModuleEvent() {
  358. this.registerFunc(v.GuideConst.OPEN_GUIDE, this.on_OPEN_GUIDE, this),
  359. this.registerFunc(v.GuideConst.PLAY_RECORD, this.playRecordNodeTouch, this),
  360. this.registerFunc(v.GuideConst.START_RECORD, this.startRecordNodeTouch, this),
  361. this.registerFunc(v.GuideConst.STOP_RECORD, this.stopRecordNodeTouch, this),
  362. this.registerFunc(v.GuideConst.SKIN_GUIDE, this.skinGuide, this),
  363. this.registerFunc(v.GuideConst.NEXT_STEP, this.onNextStep, this),
  364. this.registerFunc(v.GuideConst.EXECUTE_FUNC, this.onExecuteFunc, this),
  365. this.registerFunc(v.GuideConst.CHECK_IS_GUIDE, this._model.checkIsFinish, this._model),
  366. this.registerFunc(v.GuideConst.SET_STEP, this.onSetStep, this),
  367. this.registerFunc(v.GuideConst.CHECK_STEP, this.checkStep, this);
  368. }
  369. onSetStep(t) {
  370. delete this._model.saveData[t];
  371. }
  372. onNextStep() {
  373. this.godGuide.reset(), this.tick();
  374. }
  375. finishGuide() {}
  376. step6() {}
  377. onExecuteFunc(t) {
  378. return this[t] && "function" == typeof this[t] ? this[t]() : y.b3.FAILURE;
  379. }
  380. playRecordNodeTouch(t, e) {
  381. this.godGuide.playRecordNodeTouch();
  382. }
  383. startRecordNodeTouch() {
  384. this.godGuide ? this.godGuide.startRecordNodeTouch() : o.default.ViewManager.open(15);
  385. }
  386. stopRecordNodeTouch() {
  387. this.godGuide.stopRecordNodeTouch();
  388. }
  389. setAutorun() {}
  390. checkIsGuide() {
  391. U.isGuide || this.tick();
  392. }
  393. addPet() {
  394. this.isCheckCd ||
  395. ((this.isCheckCd = !0),
  396. o.default.TimerManager.doFrame(
  397. 2,
  398. 1,
  399. () => {
  400. (this.isCheckCd = !1), this.checkIsGuide();
  401. },
  402. this
  403. ));
  404. }
  405. addItem(t, e, i, s) {
  406. (i || s) && this.checkIsGuide();
  407. }
  408. initNotificationEvent() {
  409. o.default.NotificationCenter.addListener(u.NotificationConst.ENTER_MAP, this.checkIsGuide, this);
  410. }
  411. removeNotificationEvent() {}
  412. }
  413. (i.default = U), (U.isGuide = !1), d.registerJSONConf("guideConf", "NewGuideTree");