GuideSystem.ts 2.7 KB

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