controller.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /**
  2. * @author uu
  3. * @file 主控制器
  4. */
  5. const ADSdk = require("ADSdk");
  6. cc.Class({
  7. extends: cc.Component,
  8. properties: {
  9. musicMgr: require('musicMgr'), //音乐控制组件
  10. game: require('game'), //主游戏控制器
  11. pageMgr: require('pageMgr'), //页面控制器
  12. // social: require('social'), //排行榜、广告控制器
  13. config: cc.JsonAsset,
  14. gameData: cc.JsonAsset,
  15. scoreMgr: require('score'), //分数 特效控制
  16. totalRank: cc.Node,
  17. groupRank: cc.Node,
  18. startPage: require('startPage'),
  19. navNode: cc.Node,
  20. pictorial: cc.Node,
  21. helpPage: cc.Node,
  22. redBag: require('redBag'),
  23. singnInPage:require('signIn'),
  24. },
  25. onLoad() {
  26. // 远程config配置
  27. // Utils.getConfig((data) => {
  28. // let obj = JSON.parse(data)
  29. // AppConst.probabilityConfig = obj
  30. // });
  31. ADSdk.init();
  32. },
  33. start() {
  34. this.totalRank.active = false
  35. this.pictorial.active = false
  36. this.game.init(this)
  37. // if (this.social.node.active) {
  38. // this.social.init(this)
  39. // }
  40. this.musicMgr.init()
  41. this.lateStart()
  42. },
  43. lateStart() {
  44. // if (this.social.node.active) {
  45. // this.social.closeBannerAdv()
  46. // }
  47. this.game._status = 0
  48. this.pictorial.getComponent('pictorial').init(this)
  49. this.startPage.bannerNode.scale = 1
  50. this.pageMgr.onOpenPage(0)
  51. },
  52. onGameStartButton() {
  53. // TODO: 增加一个动画
  54. // if (this.social.node.active) {
  55. // this.social.openBannerAdv()
  56. // }
  57. this.startPage.showAnimation().then(() => {
  58. this.gameStart()
  59. })
  60. },
  61. gameStart() {
  62. this.pageMgr.onOpenPage(1)
  63. this.game.gameStart()
  64. },
  65. closeRank() {
  66. this.totalRank.active = false
  67. this.navNode.active = true
  68. // if (this.social.node.active) {
  69. // this.social.closeRank()
  70. // }
  71. },
  72. openRank() {
  73. this.totalRank.active = true
  74. this.navNode.active = false
  75. // if (this.social.node.active) {
  76. // this.social.showRank()
  77. // }
  78. },
  79. openGroupRank() {
  80. this.groupRank.active = true
  81. // if (this.social.node.active) {
  82. // this.social.showGroupRank()
  83. // this.pageMgr.addPage(6)
  84. // }
  85. },
  86. closeGroupRank() {
  87. this.groupRank.active = false
  88. this.navNode.active = true
  89. // if (this.social.node.active) {
  90. // this.social.closeGroupRank()
  91. // this.pageMgr.removePage(6)
  92. // }
  93. },
  94. openPictorial() {
  95. this.pageMgr.addPage(7)
  96. this.pictorial.active = true
  97. },
  98. closePictorial() {
  99. this.pictorial.active = false
  100. },
  101. openHelpPage() {
  102. this.pageMgr.addPage(2)
  103. this.helpPage.active = true
  104. let num = Utils.randomNum(0, 100);
  105. let nativeAD = AppConst.probabilityConfig.nativeAD;
  106. let time = 0;
  107. if (num < nativeAD.helpUI.probability) {
  108. if (AppConst.SHOWADUI) {
  109. // cc.log("信息流")
  110. if (AppConst.CHANNEL == AppConst.channel.ANDROID) {
  111. time = nativeAD.helpUI.delayTime;
  112. this.scheduleOnce(() => {
  113. ADSdk.pay(6, this);
  114. }, time);
  115. } else {
  116. ADSdk.showInsertAd();
  117. }
  118. }
  119. }
  120. },
  121. closeHelpPage() {
  122. this.pageMgr.removePage(2)
  123. this.helpPage.active = false
  124. },
  125. showRedBag() {
  126. if (Utils.hadRedPacket()) {
  127. // 开红包界面
  128. this.redBag.init(0,this);
  129. } else {
  130. // 余额界面
  131. this.redBag.init(2,this);
  132. }
  133. },
  134. showSignIn() {
  135. this.singnInPage.init(this);
  136. },
  137. });