GuideSystem.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { DataEventId, GameProp } from "../../game/data/GameData";
  2. import { OpenActionType } from "./UISystem";
  3. /**
  4. * 新手引导模块
  5. */
  6. export default class GuideSystem {
  7. public crtGuideID: number;
  8. public ui: cc.Node;
  9. public curDes = '';
  10. //当前进行到哪一步的拼接字符串
  11. public curGuideIdStr: string = null;
  12. //判断继续当前步骤的回调函数
  13. public continueCallBack: Function = null;
  14. public open(id, curDes = '') {
  15. if (gData.gameData.configs.ServerConfig.NewUserGuide == '0') {
  16. return false;
  17. }
  18. this.curDes = curDes;
  19. this.crtGuideID = gData.gameData.getProp(GameProp.guideID);
  20. if (this.crtGuideID == undefined) {
  21. this.crtGuideID = 0;
  22. }
  23. // //测试永远新手引导,永远第一关
  24. // if (!cc.sys.isNative) {
  25. // this.crtGuideID = 1;
  26. // }
  27. //test
  28. // this.crtGuideID = 0
  29. if (this.crtGuideID >= 9999) {
  30. mk.console.log("新手引导已做完");
  31. return false;
  32. }
  33. if (id <= this.crtGuideID && this.crtGuideID > 0) {
  34. mk.console.log("当前引导已做过:" + id);
  35. return false;
  36. }
  37. gData.guideData.crtID = id;
  38. this.crtGuideID = id;
  39. mk.ui.openPanel("module/guide/guide", OpenActionType.normal, this.ui);
  40. this.setGuideID(this.crtGuideID++);
  41. return true;
  42. }
  43. /** 开启一个引导后直接默认已完成 */
  44. private setGuideID(id: number) {
  45. if (id == 14) {
  46. id = 9999;
  47. mk.data.sendXYEvent("guide_end", "新手引导结束");
  48. }
  49. gData.gameData.setProp(GameProp.guideID, id);
  50. }
  51. public close() {
  52. this.crtGuideID++;
  53. }
  54. /**
  55. * 引导是否完成
  56. * @returns true 已完成
  57. */
  58. public isGuideComplete(): boolean {
  59. let id = gData.gameData.getProp(GameProp.guideID);
  60. if (!this.crtGuideID || id === 9999) {
  61. return true;
  62. } else {
  63. return false;
  64. }
  65. }
  66. /**
  67. * 当前是否正在引导
  68. * @returns
  69. */
  70. public isGuiding(): boolean {
  71. return mk.ui.getCurOnPanel("guide") != null;
  72. }
  73. public getCurGuideIdString()
  74. {
  75. return this.curGuideIdStr;
  76. }
  77. }