UIGuideView.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. import { default as gameCfg, default as Gamecfg } from "../../../common/gameCfg";
  2. import { gameMethod } from "../../../common/gameMethod";
  3. import { xlsGuideInfo } from "../../../common/xlsConfig";
  4. import auto_guideView from "../../../data/autoui/guide/auto_guideView";
  5. import { GameEvent, GuideEvent, HomeEvent, MapEvent } from "../../../data/const/EventConst";
  6. import { AudioConst, GuideType, HdBanBenFuLiCard, OpenType, TaskKind } from "../../../data/const/TypeConst";
  7. import { ViewZOrder } from "../../../data/const/ViewZOrder";
  8. import GameDataCenter from "../../../data/GameDataCenter";
  9. import ResSpine from "../../../frameWork/compment/ResSpine";
  10. import FguiMgr from "../../../frameWork/fgui/FguiMgr";
  11. import EventMng from "../../../manager/EventMng";
  12. import { I18n } from "../../../utils/I18nUtil";
  13. import Load from "../../../utils/Load";
  14. import { uiCommon } from "../../../utils/UICommon";
  15. const { ccclass, property } = cc._decorator;
  16. @ccclass
  17. export default class UIGuideView extends cc.Component {
  18. @property(cc.SpriteFrame)
  19. taskzhezhao: cc.SpriteFrame = null
  20. @property(cc.SpriteFrame)
  21. btnzhezhao: cc.SpriteFrame = null
  22. @property(cc.SpriteFrame)
  23. fudi: cc.SpriteFrame = null
  24. @property(cc.SpriteFrame)
  25. jianghu: cc.SpriteFrame = null
  26. @property(cc.SpriteFrame)
  27. shilian: cc.SpriteFrame = null
  28. @property(cc.SpriteFrame)
  29. tongyong: cc.SpriteFrame = null
  30. @property(cc.SpriteFrame)
  31. tupo: cc.SpriteFrame = null
  32. @property(cc.SpriteFrame)
  33. xiuxing: cc.SpriteFrame = null
  34. @property(cc.SpriteFrame)
  35. zhaomu: cc.SpriteFrame = null
  36. @property(cc.SpriteFrame)
  37. zhenfa: cc.SpriteFrame = null
  38. @property(cc.SpriteFrame)
  39. guanbi: cc.SpriteFrame = null
  40. @property(cc.SpriteFrame)
  41. imgMask: cc.SpriteFrame = null
  42. @property(cc.SpriteFrame)
  43. shouling: cc.SpriteFrame = null
  44. @property(cc.Node)
  45. SkipPanel: cc.Node = null
  46. @property(cc.Node)
  47. SkipBtn: cc.Node = null;
  48. @property(cc.Node)
  49. SkipGuideAllBtn: cc.Node = null;
  50. ui: auto_guideView = null;
  51. private needUiName: string = "" //需要此UI才能继续引导
  52. private guideUiName: string = "" //当前引导的UI
  53. private delayTime: number = -1 //guide延迟时间
  54. private handTime: number = -1 //手势延迟时间
  55. private fixTime: number = -1 //修正延迟时间
  56. private fixCount: number = 0 //修正次数
  57. private msgOffsetY: number = 0 //对话框偏移量
  58. private targetNodeScale: number = 1 //目标节点真实sacle
  59. private finishTyping = false //打字完成
  60. private event: GuideType = null //当前引导事件
  61. private type: number = 1 //引导类型
  62. callBack: Function;
  63. yType: number;
  64. startMoveHand: boolean = false;
  65. handWolrdPos: cc.Vec2;
  66. plotResSpine: ResSpine;
  67. isSkipPlot: boolean = false;//是否已经跳过剧情漫画
  68. private canSkipPlot: boolean = false;//是否可以跳过漫画
  69. skipCheckCount: number = 0;//检测点击次数跳过
  70. protected onEnable() {
  71. this.ui = this.node.addComponent(auto_guideView);
  72. cc.game.addPersistRootNode(this.node)
  73. this.node.zIndex = ViewZOrder.Guide
  74. uiCommon.onRegisterEvent(this.ui.dialog, this.onClickDialog, this)
  75. uiCommon.onRegisterEvent(this.SkipBtn, this.onClickSkipPlot, this)
  76. uiCommon.onRegisterEvent(this.ui.plot, this.onClickPlot, this)
  77. uiCommon.onRegisterEvent(this.SkipGuideAllBtn, this.onClickSkipGuideAllBtn, this)
  78. EventMng.on(GuideEvent.GUIDE_EVENT, this.onGuideEvent, this)
  79. EventMng.on(GuideEvent.CLOSE_GUIDE, this.onClose, this)
  80. EventMng.on(GameEvent.ON_CLICK, this.checkOpen, this)
  81. EventMng.on(GuideEvent.UPDATE_TXTMSG, this.updateTxtMsg, this)
  82. EventMng.on(GuideEvent.HIDE_HAND, this.hideHand, this)
  83. this.ui.mask2.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
  84. cc.tween(this.ui.imgQuan).repeatForever(cc.tween(this.ui.imgQuan).to(0.45, { scale: 1.2 }).to(0.45, { scale: 1 })).start()
  85. }
  86. protected onDisable() {
  87. uiCommon.unRegisterEvent(this.ui.dialog)
  88. uiCommon.unRegisterEvent(this.SkipBtn)
  89. EventMng.off(GuideEvent.GUIDE_EVENT, this.onGuideEvent, this)
  90. EventMng.off(GuideEvent.CLOSE_GUIDE, this.onClose, this)
  91. EventMng.off(GameEvent.ON_CLICK, this.checkOpen, this)
  92. EventMng.off(GuideEvent.UPDATE_TXTMSG, this.updateTxtMsg, this)
  93. EventMng.off(GuideEvent.HIDE_HAND, this.hideHand, this)
  94. this.ui.mask2.off(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this);
  95. }
  96. private onTouchEnd(event: cc.Event.EventTouch) {
  97. if (!this.ui.imgHand.active || this.startMoveHand || gameMethod.isEmpty(this.handWolrdPos)) {
  98. return
  99. }
  100. this.skipCheckCount++;
  101. let lastPos: cc.Vec2 = cc.v2()
  102. lastPos.x = this.ui.imgHand.x
  103. lastPos.y = this.ui.imgHand.y
  104. let touchPos = event.getLocation();
  105. cc.tween(this.ui.imgHand).stop()
  106. uiCommon.setWorldPos(this.ui.imgHand, touchPos)
  107. this.startMoveHand = true
  108. cc.tween(this.ui.imgHand).to(0.5, { x: lastPos.x, y: lastPos.y }).call(() => {
  109. uiCommon.setWorldPos(this.ui.imgHand, this.handWolrdPos)
  110. this.startMoveHand = false
  111. }).start()
  112. if (this.skipCheckCount >= 3 && GameDataCenter.guide.isFinishGuide() && this.event != GuideType.evt_guide_150) {
  113. this.SkipGuideAllBtn.active = true;
  114. }
  115. }
  116. checkOpen() {
  117. if (GameDataCenter.guide.isShowing) {
  118. let conf = Gamecfg.guideInfo.getItem(GameDataCenter.guide.guideId)
  119. if (conf?.ytype == 2) {
  120. GameDataCenter.guide.saveGuide(() => {
  121. EventMng.emit(GuideEvent.CLOSE_GUIDE)
  122. EventMng.emit(GuideEvent.GUIDE_EVENT, conf.event)
  123. })
  124. }
  125. }
  126. }
  127. //监听剧情触发事件
  128. onGuideEvent(event: GuideType, callBack?: Function) {
  129. //暂时先关闭所有引导
  130. if (!GameDataCenter.guide.isOpenGuide) {
  131. return
  132. }
  133. this.event = event
  134. this.callBack = callBack
  135. let confDramaList = gameCfg.guideInfoList.getItemList(event)
  136. let isfinish: boolean = false
  137. for (const key in confDramaList) {
  138. const element = confDramaList[key];
  139. //新手引导如果保存了步骤要过滤
  140. if (!GameDataCenter.guide.checkIsSave(element.id) && GameDataCenter.guide.checkCanDrama(element.id)) {
  141. this.showGuide(element.id)
  142. EventMng.emit(HomeEvent.UP_HD_FLYBIRD);
  143. isfinish = true
  144. this.fixCount = 0;//重置修正次数
  145. this.skipCheckCount = 0;
  146. this.SkipGuideAllBtn.active = false;
  147. break
  148. }
  149. }
  150. }
  151. onClickPlot() {
  152. if (!this.canSkipPlot) return;
  153. if (this.SkipPanel.active) {
  154. this.ShowPlotSkip(false);
  155. } else {
  156. this.ShowPlotSkip(true);
  157. }
  158. }
  159. onClickSkipPlot() {
  160. if (this.isSkipPlot) return;
  161. this.isSkipPlot = true;
  162. this.SkipPanel.active = false;
  163. if (!GameDataCenter.guide.isFinishGuide()) {
  164. GameDataCenter.guide.nextGuide(this.event)
  165. }
  166. cc.tween(this.ui.plot)
  167. .to(1, { opacity: 0 })
  168. .delay(0.5)
  169. .call(() => {
  170. this.ui.plot.active = false
  171. this.plotResSpine.resetRes();
  172. GameDataCenter.audio.playMusic(AudioConst.bgm_base)
  173. }).start();
  174. }
  175. ShowPlotSkip(isShow: boolean) {
  176. cc.Tween.stopAllByTarget(this.SkipPanel);
  177. if (isShow) {
  178. this.SkipPanel.active = true;
  179. cc.tween(this.SkipPanel)
  180. .to(0.25, { y: this.SkipPanel.height })
  181. .start();
  182. } else {
  183. cc.tween(this.SkipPanel)
  184. .to(0.25, { y: 0 })
  185. .call(() => {
  186. this.SkipPanel.active = false;
  187. })
  188. .start();
  189. }
  190. }
  191. showGuide(id: string) {
  192. if (GameDataCenter.guide.isShowing) {
  193. return
  194. }
  195. console.log("showGuide:" + id)
  196. GameDataCenter.guide.isShowing = true
  197. GameDataCenter.guide.guideId = id
  198. GameDataCenter.guide.guideIndex = 0
  199. this.ui.gGuide.active = true
  200. let conf = gameCfg.guideInfo.getItem(GameDataCenter.guide.guideId)
  201. if (GameDataCenter.guide.isFinishGuide() && conf.event == GuideType.new) {//如果已完成了新手引导,但是仍然触发了新手引导的步骤,直接跳过
  202. GameDataCenter.guide.saveGuideArray(GuideType.new, [GameDataCenter.guide.guideId], () => { });
  203. return;
  204. }
  205. this.type = conf.type
  206. this.yType = conf.ytype
  207. if (this.type == 1) {
  208. if (!GameDataCenter.guide.isFinishGuide()) {
  209. GameDataCenter.guide.nextGuide(this.event)
  210. }
  211. } else if (this.type == 3) {
  212. //单纯对话框引导
  213. this.ui.btnMask.active = false
  214. this.ui.dialog.active = true
  215. this.showDialog()
  216. } else if (this.type == 5) {
  217. //正常下一步引导
  218. if (conf.way == "5") {
  219. GameDataCenter.guide.isShowing = true
  220. this.ui.gGuide.active = true
  221. this.ui.btnMask.active = true
  222. EventMng.emit(GuideEvent.GUIDE_SLOT, conf.pram[0]);
  223. } else {
  224. this.playGuide()
  225. }
  226. } else {
  227. //正常下一步引导
  228. this.guideUiName = conf.pram[0][0];
  229. this.playGuide()
  230. }
  231. }
  232. showDialog() {
  233. let conf = gameCfg.guideInfo.getItem(GameDataCenter.guide.guideId)
  234. let roleImgName = conf.pram[2]
  235. Load.loadTexture(this.ui.imgRole1, `guide/res/${roleImgName}`);
  236. uiCommon.setLabel(this.ui.txtName, I18n.getI18nLang(conf.pram[3]))
  237. if (conf.pram[0][GameDataCenter.guide.guideIndex] == null) {
  238. GameDataCenter.guide.saveGuide(() => {
  239. this.onClose()
  240. if (this.callBack) {
  241. //当前引导组结束回调
  242. GameDataCenter.guide.isShowing = true
  243. this.ui.gGuide.active = true
  244. this.ui.btnMask.active = true
  245. this.callBack()
  246. this.callBack = null
  247. } else {
  248. this.onGuideEvent(this.event)
  249. }
  250. })
  251. return
  252. }
  253. //播放配音
  254. GameDataCenter.audio.stopAllEffects()
  255. //GameDataCenter.audio.playEffect(conf.pram?.[0]?.[GameDataCenter.guide.guideIndex])
  256. uiCommon.typingAni(this.ui.txtDialog.getComponent(cc.RichText), I18n.getI18nLang(conf.pram?.[0]?.[GameDataCenter.guide.guideIndex]), 1 / 45, () => {
  257. this.finishTyping = true
  258. })
  259. }
  260. onClickDialog() {
  261. if (this.finishTyping) {
  262. this.finishTyping = false
  263. GameDataCenter.guide.guideIndex++
  264. this.showDialog()
  265. } else {
  266. this.finishTyping = true
  267. this.ui.txtDialog.getComponent(cc.RichText).unscheduleAllCallbacks()
  268. let conf = gameCfg.guideInfo.getItem(GameDataCenter.guide.guideId)
  269. uiCommon.setLabel(this.ui.txtDialog, I18n.getI18nLang(conf.pram?.[0]?.[GameDataCenter.guide.guideIndex]))
  270. GameDataCenter.audio.stopAllEffects()
  271. }
  272. }
  273. onClickSkipGuideAllBtn() {
  274. let confDramaList = gameCfg.guideInfoList.getItemList(this.event)
  275. let guideIds = [];
  276. confDramaList.forEach(element => {
  277. guideIds.push(element.id);
  278. });
  279. GameDataCenter.guide.saveGuideArray(this.event, guideIds, () => {
  280. this.SkipGuideAllBtn.active = false;
  281. this.skipCheckCount = 0;
  282. this.onClose();
  283. })
  284. }
  285. playGuide() {
  286. if (this.delayTime >= 0) { return }
  287. let conf = gameCfg.guideInfo.getItem(GameDataCenter.guide.guideId)
  288. let guideInfo = conf.pram[GameDataCenter.guide.guideIndex]
  289. // console.log("guideInfo===", guideInfo)
  290. if (guideInfo != null) {
  291. switch (guideInfo[0]) {
  292. case "name":
  293. this.ui.btnMask.active = this.yType != 2 //弱引导,不开启遮罩
  294. this.handTime = guideInfo[1] < 0 ? 0 : guideInfo[1]
  295. this.msgOffsetY = guideInfo[6] != null ? guideInfo[6] : 140
  296. break
  297. default:
  298. this.ui.btnMask.active = this.yType != 2 //弱引导,不开启遮罩
  299. this.needUiName = this.changeUiName(guideInfo[0], conf);
  300. this.delayTime = guideInfo[1]
  301. break
  302. }
  303. } else {
  304. GameDataCenter.guide.nextGuide(this.event)
  305. }
  306. }
  307. handCall(isFix: boolean = false) {
  308. if (isFix) {
  309. return
  310. }
  311. let conf = Gamecfg.guideInfo.getItem(GameDataCenter.guide.guideId)
  312. let guideInfo = conf.pram[GameDataCenter.guide.guideIndex]
  313. if (guideInfo == null || gameMethod.isEmpty(guideInfo[2])) {
  314. return
  315. }
  316. this.fixTime = 0.5 //每0.5s修正一次位置
  317. this.ui.btnMask.active = false
  318. this.ui.mask.active = this.yType != 2 //弱引导,不开启遮罩
  319. //这里需要查找节点的话,conf.pram[0][0]必须配置uiview
  320. let uiViewName = this.changeUiName(conf.pram[0][0], conf);
  321. let targetNode: cc.Node = FguiMgr.Instance.findNodeByName(uiViewName, guideInfo[2]);
  322. if (targetNode == null) {
  323. console.error(`找不到目标节点: ${guideInfo[2]}`)
  324. this.onClose();
  325. return
  326. }
  327. let targetWolrdPos = uiCommon.getWorldPosCenter(targetNode)
  328. this.targetNodeScale = targetNode.scale
  329. let maskScale = 1
  330. if (!gameMethod.isEmpty(guideInfo[7])) {
  331. maskScale = guideInfo[7]
  332. }
  333. this.getRealScale(targetNode)
  334. this.ui.mask.width = targetNode.width * this.targetNodeScale * maskScale
  335. this.ui.mask.height = targetNode.height * this.targetNodeScale * maskScale
  336. this.ui.mask.angle = targetNode.angle
  337. uiCommon.setWorldPos(this.ui.mask, targetWolrdPos)
  338. cc.Tween.stopAllByTarget(this.ui.imgHand)
  339. this.ui.imgHand.active = true//guideInfo[2] != "MaskBgBtn" //点击空白处关闭的,无需显示手指跟光圈
  340. if (!gameMethod.isEmpty(guideInfo[3])) {
  341. targetWolrdPos.y -= parseInt(guideInfo[3])
  342. }
  343. this.handWolrdPos = targetWolrdPos
  344. if (conf.type == 15 && !gameMethod.isEmpty(conf.pram?.[2]?.[2])) {//拖动类型的引导
  345. let targetNode2: cc.Node = FguiMgr.Instance.findNodeByName(uiViewName, conf.pram[2][2]);
  346. if (targetNode2 == null) {
  347. console.error(`找不到目标节点: ${conf.pram[2][2]}`)
  348. this.onClose();
  349. return
  350. }
  351. uiCommon.setWorldPos(this.ui.imgQuan, cc.v2(targetWolrdPos.x, targetWolrdPos.y))
  352. uiCommon.setWorldPos(this.ui.imgHand, targetWolrdPos)
  353. this.ui.msgBg.active = !gameMethod.isEmpty(guideInfo[5])
  354. this.ui.imgQuan.active = false;
  355. if (!gameMethod.isEmpty(conf.pram?.[GameDataCenter.guide.guideIndex]?.[5])) {
  356. uiCommon.setLabel(this.ui.txtMsg, I18n.getI18nLang(conf.pram?.[GameDataCenter.guide.guideIndex]?.[5]))
  357. }
  358. this.ui.msgBg.y = this.ui.imgQuan.y + this.msgOffsetY
  359. let msgBgX = this.ui.imgQuan.x
  360. if (this.ui.imgQuan.x < -155) {
  361. msgBgX = -155
  362. } else if (this.ui.imgQuan.x > 155) {
  363. msgBgX = 155
  364. }
  365. this.ui.msgBg.x = msgBgX
  366. let targetPos = uiCommon.transPos(targetNode2, this.ui.gGuide);
  367. cc.tween(this.ui.imgHand).repeatForever(cc.tween(this.ui.imgHand).to(0.5, { position: targetPos }).delay(0.3).call(() => {
  368. uiCommon.setWorldPos(this.ui.imgHand, targetWolrdPos)
  369. })).start()
  370. }
  371. else {
  372. uiCommon.setWorldPos(this.ui.imgHand, targetWolrdPos)
  373. this.guideHandEnd(guideInfo, conf, targetWolrdPos)
  374. }
  375. }
  376. guideHandEnd(guideInfo: any[], conf: xlsGuideInfo, targetWolrdPos: cc.Vec2) {
  377. this.ui.msgBg.active = !gameMethod.isEmpty(guideInfo[5])
  378. this.ui.imgQuan.active = true//guideInfo[2] != "MaskBgBtn" //点击空白处关闭的,无需显示光圈
  379. //播放配音
  380. if (!gameMethod.isEmpty(conf.pram?.[GameDataCenter.guide.guideIndex]?.[5])) {
  381. uiCommon.setLabel(this.ui.txtMsg, I18n.getI18nLang(conf.pram?.[GameDataCenter.guide.guideIndex]?.[5]))
  382. GameDataCenter.audio.stopAllEffects()
  383. //GameDataCenter.audio.playEffect(conf.pram?.[GameDataCenter.guide.guideIndex]?.[5])
  384. }
  385. uiCommon.setWorldPos(this.ui.imgQuan, cc.v2(targetWolrdPos.x, targetWolrdPos.y))
  386. uiCommon.setWorldPos(this.ui.imgHand, cc.v2(targetWolrdPos.x, targetWolrdPos.y))
  387. this.ui.msgBg.y = this.ui.imgQuan.y + this.msgOffsetY
  388. let msgBgX = this.ui.imgQuan.x
  389. if (this.ui.imgQuan.x < -155) {
  390. msgBgX = -155
  391. } else if (this.ui.imgQuan.x > 155) {
  392. msgBgX = 155
  393. }
  394. this.ui.msgBg.x = msgBgX
  395. }
  396. updateTxtMsg(txt: string) {
  397. uiCommon.setLabel(this.ui.txtMsg, txt)
  398. }
  399. //获取目标节点真实sacle
  400. getRealScale(root: cc.Node) {
  401. if (root.parent != null) {
  402. this.targetNodeScale *= root.parent.scale
  403. this.getRealScale(root.parent)
  404. }
  405. }
  406. update(dt: number) {
  407. if (this.delayTime >= 0) {
  408. this.ui.btnMask.active = this.yType != 2 //弱引导,不开启遮罩
  409. if (this.needUiName.length > 0) {
  410. if (FguiMgr.Instance.isShowingByName(this.needUiName) && FguiMgr.Instance.getShowingViewByName(this.needUiName)?.isFinishOpenAni) {
  411. this.delayTime -= dt
  412. if (this.delayTime < 0) {
  413. this.ui.btnMask.active = false
  414. this.needUiName = ""
  415. if (this.type == 1) {
  416. this.ui.dialog.active = true
  417. this.showDialog()
  418. } else {
  419. GameDataCenter.guide.guideIndex++
  420. this.playGuide()
  421. }
  422. }
  423. }
  424. } else {
  425. this.delayTime -= dt
  426. if (this.delayTime < 0) {
  427. this.ui.btnMask.active = false
  428. if (this.type == 1) {
  429. this.ui.dialog.active = true
  430. this.showDialog()
  431. } else {
  432. this.playGuide()
  433. }
  434. }
  435. }
  436. }
  437. //手势引导延迟
  438. if (this.handTime >= 0) {
  439. if (FguiMgr.Instance.isShowingByName(this.guideUiName)) {
  440. this.handTime -= dt
  441. if (this.handTime < 0) {
  442. this.handCall()
  443. }
  444. }
  445. }
  446. //修正位置
  447. if (this.fixTime >= 0) {
  448. if (FguiMgr.Instance.isShowingByName(this.guideUiName)) {
  449. this.fixTime -= dt
  450. if (this.fixTime < 0) {
  451. this.handCall(true)
  452. }
  453. }
  454. }
  455. }
  456. changeUiName(uiName: string, conf: xlsGuideInfo) {
  457. return uiName;
  458. }
  459. hideHand() {
  460. this.ui.imgQuan.active = false
  461. this.ui.imgHand.active = false
  462. }
  463. onClose() {
  464. GameDataCenter.guide.init()
  465. this.ui.gGuide.active = false
  466. this.ui.dialog.active = false
  467. this.ui.mask.active = false
  468. this.ui.msgBg.active = false
  469. this.ui.imgQuan.active = false
  470. this.ui.imgHand.active = false
  471. this.needUiName = ""
  472. this.guideUiName = ""
  473. this.delayTime = -1
  474. this.handTime = -1
  475. this.fixTime = -1
  476. this.targetNodeScale = 1
  477. }
  478. }