GuideSystem.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import GamePlay from "../../before/GamePlay";
  2. import { DataEventId, GameProp } from "../../game/data/GameData";
  3. import { OpenActionType } from "./UISystem";
  4. /**
  5. * 新手引导模块
  6. */
  7. export default class GuideSystem {
  8. public crtGuideID: number;
  9. public ui: cc.Node;
  10. public open(id) {
  11. if (id == 3) {
  12. console.log('BBB 111111 ', gData.guideToWxData.guideToWxSwith)
  13. if (!gData.guideToWxData.guideToWxSwith) {
  14. return;
  15. }
  16. let can = (mk.storage.getStorage('canShowGuideToWx') == '1');
  17. console.log('BBB 222222 ', can)
  18. if (!can) {
  19. return
  20. }
  21. let state = gData.gameData.getProp(GameProp.guideToWx);
  22. console.log('BBB 3333333 ', state)
  23. if (!state) {
  24. console.log('BBB 444444 ')
  25. gData.gameData.setProp(GameProp.guideToWx, 1);
  26. gData.guideToWxData.init_state = true;
  27. mk.ui.closeAllUI();
  28. if (GamePlay.Inst && GamePlay.Inst.node && GamePlay.Inst.node.active) {
  29. GamePlay.Inst.restart();//退出不扣体力
  30. GamePlay.Inst.node.active = false;
  31. }
  32. }
  33. }
  34. this.crtGuideID = gData.gameData.getProp(GameProp.guideID);
  35. // //test
  36. // if (this.crtGuideID > id)
  37. // return;
  38. // //测试永远新手引导,永远第一关
  39. // if (!cc.sys.isNative) {
  40. // this.crtGuideID = 1;
  41. // gData.gameData.setProp(GameProp.levelNum, 0);
  42. // }
  43. if (this.crtGuideID >= 9999) {
  44. mk.console.log("新手引导已做完");
  45. return;
  46. }
  47. if (id <= this.crtGuideID && this.crtGuideID > 0) {
  48. mk.console.log("当前引导已做过:" + id);
  49. return;
  50. }
  51. gData.guideData.crtID = id;
  52. this.crtGuideID = id;
  53. mk.ui.openPanel("module/guide/guide", OpenActionType.normal, this.ui);
  54. this.setGuideID(this.crtGuideID++);
  55. return true
  56. }
  57. /** 开启一个引导后直接默认已完成 */
  58. private setGuideID(id: number) {
  59. if (id == 5) {
  60. id = 9999;
  61. mk.data.sendXYEvent("guide_end", "新手引导结束");
  62. }
  63. gData.gameData.setProp(GameProp.guideID, id);
  64. }
  65. public close() {
  66. this.crtGuideID++;
  67. }
  68. /**
  69. * 引导是否完成
  70. * @returns true 已完成
  71. */
  72. public isGuideComplete(): boolean {
  73. if (!this.crtGuideID || this.crtGuideID === 9999) {
  74. return true;
  75. } else {
  76. return false;
  77. }
  78. }
  79. /**
  80. * 当前是否正在引导
  81. * @returns
  82. */
  83. public isGuiding(): boolean {
  84. return mk.ui.getCurOnPanel("guide") != null;
  85. }
  86. }