GuideSystem.ts 2.5 KB

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