GuideSystem.ts 2.6 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 && 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. let guide = gData.guideData.getGuidesByID(id);
  52. if (id == 3) {
  53. id = 9999;
  54. mk.data.sendXYEvent("guide_end", "新手引导结束");
  55. }
  56. gData.gameData.setProp(GameProp.guideID, id);
  57. }
  58. public close() {
  59. this.crtGuideID++;
  60. }
  61. /**
  62. * 引导是否完成
  63. * @returns true 已完成
  64. */
  65. public isGuideComplete(): boolean {
  66. if (!this.crtGuideID || this.crtGuideID === 9999) {
  67. return true;
  68. } else {
  69. return false;
  70. }
  71. }
  72. /**
  73. * 当前是否正在引导
  74. * @returns
  75. */
  76. public isGuiding(): boolean {
  77. return mk.ui.getCurOnPanel("guide") != null;
  78. }
  79. }