UpdateCtrl.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // '所有更新事件处理类',
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. updateAlert: cc.Node,
  6. updateAwardAlert: cc.Node,
  7. updateBannerAlert: cc.Node,
  8. updateAwardBannerAlert: cc.Node,
  9. hotupdateProgressNode: cc.Node,
  10. hotupdateAlertNode: cc.Node,
  11. curUpdateAlert: cc.Node,
  12. curHotUpdateAlert: cc.Node
  13. },
  14. onLoad () {
  15. if (!G.UpdateCtrl) {
  16. G.UpdateCtrl = cc.game.addPersistRootNode(this.node);
  17. }
  18. this._updateCtr = this.getComponent('UpdateCtrl');
  19. this._bgMask = this.node.getChildByName('bgMask');
  20. this._bgUpdateProgressNode = this.node.getChildByName('bgUpdateProgress');
  21. this._bgUpdateProgress = this._bgUpdateProgressNode.getComponent('BgUpdateProgress');
  22. let y = cc.winSize.height / 2;
  23. let x = cc.winSize.width / 2;
  24. let newVec2 = this.node.convertToNodeSpaceAR(cc.v2(x, y));
  25. this._bgMask.y = newVec2.y;
  26. this._bgMask.x = newVec2.x;
  27. this._bgMask.width = cc.winSize.width;
  28. this._bgMask.height = cc.winSize.height;
  29. cc.game.on('e_launch_touch_update_node', this.handleTouch, this);
  30. cc.game.on('e_app_update_show_alert', this.handleShowAppUpdateAlert, this);
  31. cc.game.on('e_launch_update_show_alert', this.handleShowUpdateAlert, this);
  32. cc.game.on('e_launch_update_show_progress', this.handleShowUpdateProgress, this);
  33. cc.game.on('e_launch_hot_update_show_alert', this.handleShowHotUpdateAlert, this);
  34. },
  35. showCurUpdateAlert () {
  36. let remoteUpdateInfo = G.RemoteUpdateInfoMgr.remoteUpdateInfo;
  37. // 有无更新奖励判断
  38. this.haveAward = remoteUpdateInfo.newAppAward == '' ? false : true;
  39. // 有无banner判断
  40. this.haveBanner = remoteUpdateInfo.newAppBanner == '' ? false : true;
  41. // 是否强制更新判断
  42. this.isForceUpdate = remoteUpdateInfo.newAppForce == 0 ? false : true;
  43. // 是否静默更新判断
  44. this.isSilentUpdate = remoteUpdateInfo.newAppSilence == 0 ? false : true;
  45. let updateCtr = this;
  46. let updateType = 0;
  47. // 显示 无奖励 无banner 布局
  48. if (this.haveAward == false && this.haveBanner == false) {
  49. updateType = 1;
  50. }
  51. // 显示 有奖励 无banner 布局
  52. if (this.haveAward == true && this.haveBanner == false) {
  53. updateType = 2;
  54. }
  55. // 显示 无奖励 有banner 布局
  56. if (this.haveAward == false && this.haveBanner == true) {
  57. updateType = 3;
  58. }
  59. // 显示 有奖励 有banner 布局
  60. if (this.haveAward == true && this.haveBanner == true) {
  61. updateType = 4;
  62. }
  63. this.updateAlert.active = false;
  64. this.updateAwardAlert.active = false;
  65. this.updateBannerAlert.active = false;
  66. this.updateAwardBannerAlert.active = false;
  67. // 为了静默下载也获得bgUpdateProgress当前依赖弹窗
  68. switch (updateType) {
  69. case 1:
  70. updateCtr.curUpdateAlert = this.updateAlert;
  71. break;
  72. case 2:
  73. updateCtr.curUpdateAlert = this.updateAwardAlert;
  74. break;
  75. case 3:
  76. updateCtr.curUpdateAlert = this.updateBannerAlert;
  77. break;
  78. case 4:
  79. updateCtr.curUpdateAlert = this.updateAwardBannerAlert;
  80. break;
  81. default:
  82. break;
  83. }
  84. if (updateCtr.curUpdateAlert !== null) {
  85. updateCtr.curUpdateAlert.active = true;
  86. this._bgMask.active = true;
  87. }
  88. },
  89. updateProgress (isShow) {
  90. this._bgUpdateProgressNode.active = isShow;
  91. if (isShow)
  92. this._bgUpdateProgressNode.opacity = 255;
  93. },
  94. // 点击顶部更新按钮处理
  95. handleTouch () {
  96. this.updateProgress(false);
  97. if (this.curHotUpdateAlert !== null) {
  98. this._bgMask.active = true;
  99. this.curHotUpdateAlert.active = true;
  100. return;
  101. }
  102. if (this.curUpdateAlert !== null) {
  103. this._bgMask.active = true;
  104. this.curUpdateAlert.active = true;
  105. return;
  106. }
  107. },
  108. handleShowUpdateAlert () {
  109. if (this.curUpdateAlert) {
  110. this.curUpdateAlert.active = true;
  111. this._bgMask.active = true;
  112. return;
  113. } else {
  114. this.updateProgress(false);
  115. if (this.curHotUpdateAlert) {
  116. this.curHotUpdateAlert.active = false;
  117. } else {
  118. this.showCurUpdateAlert();
  119. }
  120. }
  121. },
  122. handleShowAppUpdateAlert () {
  123. if (this.curUpdateAlert) {
  124. this.curUpdateAlert.active = false;
  125. this.curUpdateAlert = null;
  126. }
  127. G.RemoteUpdateInfoMgr.remoteUpdateInfo.newAppSilence = 1;
  128. this.updateProgress(false);
  129. this.showCurUpdateAlert();
  130. },
  131. handleShowUpdateProgress () {
  132. this.updateProgress(true);
  133. this._bgMask.active = false;
  134. },
  135. handleShowHotUpdateAlert () {
  136. this.curHotUpdateAlert = this.hotupdateAlertNode;
  137. this.hotupdateAlertNode.active = true;
  138. this._bgMask.active = true;
  139. }
  140. });