pageMgr.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /**
  2. * @author uu
  3. * @file 通用页面控制器和适配
  4. */
  5. var AC = require('action')
  6. const ADSdk = require("ADSdk")
  7. cc.Class({
  8. extends: cc.Component,
  9. properties: {
  10. status: 0, //页面状态
  11. pages: [cc.Node],
  12. },
  13. // 0 开始游戏页面
  14. // 1 游戏页面
  15. // 2 helpUI页面
  16. // 3 过关页面
  17. // 4 失败页面
  18. // 5 复活页面
  19. // 6 排行榜页面
  20. start() {
  21. this.splash = this.node.getChildByName("splash");
  22. this.splash.active = false;
  23. this.splashIsOver = false; //闪屏已经执行 才可播放信息流
  24. this.lateStart()
  25. // TODO 广告 开屏
  26. if (AppConst.SHOWADUI) {
  27. if (AppConst.CHANNEL == AppConst.channel.ANDROID) {
  28. // 手Q没有关闭监听
  29. ADSdk.pay(9, this);
  30. } else {
  31. // this.showSplash();
  32. }
  33. }
  34. },
  35. lateStart() {
  36. this.width = cc.director.getWinSizeInPixels().width
  37. window.width = this.width
  38. this.height = cc.director.getWinSizeInPixels().height
  39. window.height = this.height
  40. // 存为全局变量
  41. this.adoptCanvas()
  42. },
  43. // 适配解决方案
  44. adoptCanvas() {
  45. let canvas = cc.director.getScene().getChildByName('Canvas').getComponent(cc.Canvas)
  46. // 设计分辨率比
  47. let rateR = canvas.designResolution.height / canvas.designResolution.width;
  48. // 显示分辨率比
  49. let rateV = this.height / this.width;
  50. if (rateV > rateR) {
  51. canvas.fitHeight = false;
  52. canvas.fitWidth = true;
  53. } else {
  54. canvas.fitHeight = true;
  55. canvas.fitWidth = false;
  56. }
  57. },
  58. showSplash() {
  59. // if(this.isRuningFade) return;
  60. // this.splash.runAction(
  61. // cc.sequence(
  62. // cc.callFunc(() => {
  63. // this.isRuningFade = true;
  64. // }),
  65. // cc.delayTime(1),
  66. // cc.fadeOut(1.0),
  67. // cc.callFunc(() => {
  68. // this.splashIsOver = true;
  69. // if (AppConst.CHANNEL == AppConst.channel.ANDROID) {
  70. this.splashIsOver = true;
  71. this.showNativeAD(0);
  72. // }
  73. // })
  74. // ));
  75. },
  76. onOpenPage(num, callFun) {
  77. this.closeAllPages()
  78. this.pages[num].active = true
  79. // if (callFun) {
  80. // this.callFun();
  81. // }
  82. this.showNativeAD(num);
  83. },
  84. addPage(num, callFun) {
  85. this.pages[num].scale = 0.5
  86. this.pages[num].active = true
  87. this.pages[num].runAction(AC.popOut(0.5))
  88. // if (callFun) {
  89. // this.callFun();
  90. // }
  91. this.showNativeAD(num);
  92. },
  93. openPageTarget(target) {
  94. target.scale = 0.5
  95. target.active = true
  96. target.runAction(AC.popOut(0.5))
  97. },
  98. removePage(num, callFun) {
  99. this.pages[num].runAction(cc.sequence(AC.popIn(0.5), cc.callFunc(() => {
  100. this.pages[num].active = false
  101. }, this)))
  102. // if (callFun) {
  103. // this.callFun();
  104. // }
  105. },
  106. onButtonOpenPage(event, cust) {
  107. this.onOpenPage(cust);
  108. },
  109. onButtonAddPage(event, cust) {
  110. this.addPage(cust);
  111. },
  112. onButtonRemovePage(event, cust) {
  113. this.removePage(cust);
  114. },
  115. closeAllPages() {
  116. this.pages.forEach(element => {
  117. element.active = false
  118. });
  119. },
  120. showNativeAD(id) {
  121. // TODO 先关闭原生广告
  122. // TODO 广告 原生广告/插屏广告
  123. let num = Utils.randomNum(0, 100);
  124. let nativeAD = AppConst.probabilityConfig.nativeAD;
  125. let time = 0;
  126. switch (id) {
  127. case 0:// 主界面
  128. if (num < nativeAD.mainUI.probability) {
  129. if (AppConst.SHOWADUI) {
  130. // cc.log("信息流")
  131. if (AppConst.CHANNEL == AppConst.channel.ANDROID) {
  132. if (this.splashIsOver) {
  133. time = nativeAD.mainUI.delayTime;
  134. this.scheduleOnce(() => {
  135. ADSdk.pay(5, this);
  136. }, time);
  137. }
  138. } else {
  139. ADSdk.showInsertAd();
  140. }
  141. }
  142. }
  143. break;
  144. case 5:// 复活界面
  145. if (num < nativeAD.gameFailUI.probability) {
  146. if (AppConst.SHOWADUI) {
  147. if (AppConst.CHANNEL == AppConst.channel.ANDROID) {
  148. time = nativeAD.gameFailUI.delayTime;
  149. this.scheduleOnce(() => {
  150. ADSdk.pay(7, this);
  151. }, time);
  152. } else {
  153. ADSdk.showInsertAd();
  154. }
  155. }
  156. }
  157. break;
  158. case 1:// 游戏界面
  159. // TODO 广告 banner
  160. // 玩家主动关闭40s后再次展示
  161. // 玩家未主动关闭30S自动销毁,再同步调用展示其他广告
  162. if (AppConst.SHOWADUI) {
  163. if (AppConst.CHANNEL == AppConst.channel.ANDROID) {
  164. // 手Q没有关闭监听
  165. ADSdk.pay(0, this);
  166. } else {
  167. ADSdk.showBanner();
  168. // this.scheduleOnce(() => {
  169. // ADSdk.hideBanner();
  170. // this.showBanner();
  171. // }, 30);
  172. }
  173. }
  174. break;
  175. case 3:// 过关界面
  176. if (num < nativeAD.gameSucessUI.probability) {
  177. if (AppConst.SHOWADUI) {
  178. if (AppConst.CHANNEL == AppConst.channel.ANDROID) {
  179. time = nativeAD.gameSucessUI.delayTime;
  180. this.scheduleOnce(() => {
  181. ADSdk.pay(11, this);
  182. }, time);
  183. } else {
  184. ADSdk.showInsertAd();
  185. }
  186. }
  187. }
  188. break;
  189. }
  190. },
  191. // 原生UI
  192. showNativeAdUI(id) {
  193. },
  194. });