GuideSystem.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { DataEventId, GameProp } from "../../game/data/GameData";
  2. import { OpenActionType } from "./UISystem";
  3. /**
  4. * 新手引导模块
  5. */
  6. export default class GuideSystem {
  7. private crtGuideID: number;
  8. public ui: cc.Node;
  9. public open(id) {
  10. if (gData.gameData.funOpenData['6'] != 1) {
  11. this.crtGuideID = 9999;
  12. gData.gameData.setProp(GameProp.guideID, this.crtGuideID);
  13. }
  14. else {
  15. this.crtGuideID = gData.gameData.getProp(GameProp.guideID);
  16. }
  17. //测试永远新手引导,永远第一关
  18. if (!cc.sys.isNative) {
  19. this.crtGuideID = 1;
  20. gData.gameData.setProp(GameProp.levelNum, 0);
  21. }
  22. if (this.crtGuideID >= 9999) {
  23. mk.console.log("新手引导已做完");
  24. return;
  25. }
  26. if (id <= this.crtGuideID && this.crtGuideID > 0) {
  27. mk.console.log("当前引导已做过:" + id);
  28. return;
  29. }
  30. gData.guideData.crtID = id;
  31. this.crtGuideID = id;
  32. mk.ui.openPanel("module/guide/guide", OpenActionType.normal, this.ui);
  33. this.setGuideID(this.crtGuideID++);
  34. return true
  35. }
  36. /** 开启一个引导后直接默认已完成 */
  37. private setGuideID(id: number) {
  38. let guide = gData.guideData.getGuidesByID(id);
  39. if (id == 2) {
  40. id = 9999;
  41. mk.data.sendXYEvent("guide_end", "新手引导结束");
  42. }
  43. gData.gameData.setProp(GameProp.guideID, id);
  44. }
  45. public close() {
  46. this.crtGuideID++;
  47. }
  48. /**
  49. * 引导是否完成
  50. * @returns true 已完成
  51. */
  52. public isGuideComplete(): boolean {
  53. if (!this.crtGuideID || this.crtGuideID === 9999) {
  54. return true;
  55. } else {
  56. return false;
  57. }
  58. }
  59. /**
  60. * 当前是否正在引导
  61. * @returns
  62. */
  63. public isGuiding(): boolean {
  64. return mk.ui.getCurOnPanel("guide") != null;
  65. }
  66. }