BgUpdateProgress.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. const UpdateProgress = require('UpdateProgress');
  2. // 顶部后台热更新进度条
  3. cc.Class({
  4. editor: {
  5. menu: 'Launch/BgUpdateProgress'
  6. },
  7. extends: cc.Component,
  8. properties: {
  9. updateProgress: UpdateProgress,
  10. button: cc.Button
  11. },
  12. onLoad () {
  13. let y = cc.winSize.height - this.node.height / 2 - 5;
  14. let x = cc.winSize.width / 2;
  15. let newVec2 = this.node.convertToNodeSpaceAR(cc.v2(x, y));
  16. this.node.y = newVec2.y;
  17. this.node.x = newVec2.x;
  18. },
  19. onEnable () {
  20. cc.game.on('e_mgr_launch_update_progression', this._handleUpdateProgression, this);
  21. cc.game.on('e_mgr_launch_update_finished', this._handleUpdateFinished, this);
  22. cc.game.on('e_mgr_launch_update_failed', this._handleUpdateFailed, this);
  23. cc.game.on('e_mgr_launch_version_update_downloading', this._handleVersionDownloading, this);
  24. cc.game.on('e_mgr_launch_version_update_pause', this._handleVersionPause, this);
  25. cc.game.on('e_mgr_launch_version_update_finished', this._handleVersionFinished, this);
  26. cc.game.on('e_mgr_launch_version_update_failed', this._handleVersionFailed, this);
  27. if (G.RemoteUpdateInfoMgr.isHotUpdate) {
  28. this.reloadHotUpdateView();
  29. } else if (G.RemoteUpdateInfoMgr.isVersionUpdate) {
  30. this.reloadVersionUpdateView();
  31. }
  32. },
  33. onDisable () {
  34. cc.game.targetOff(this);
  35. },
  36. reloadHotUpdateView () {
  37. this.button.interactable = true;
  38. this.updateProgress.setDownloadStatus(G.HotUpdateMgr.status);
  39. this.updateProgress.setProgress(G.HotUpdateMgr.downloadedBytes, G.HotUpdateMgr.realTotalBytes);
  40. if (G.HotUpdateMgr.status == JMC.UPDATE_STATUS.DOWNLOAD_FINISHED) {
  41. this.updateProgress.doFinishAnim();
  42. }
  43. },
  44. reloadVersionUpdateView () {
  45. this.button.interactable = true;
  46. this.updateProgress.setDownloadStatus(G.VersionUpdateMgr.status);
  47. let downloadedBytes = (G.VersionUpdateMgr.downloadProgress / 100) * G.VersionUpdateMgr.totalBytes;
  48. this.updateProgress.setProgress(downloadedBytes, G.VersionUpdateMgr.totalBytes);
  49. if (G.VersionUpdateMgr.status == JMC.UPDATE_STATUS.DOWNLOAD_FINISHED) {
  50. this.updateProgress.doFinishAnim();
  51. }
  52. },
  53. onClicked () {
  54. this._onClicked();
  55. setTimeout (() => {
  56. cc.game.emit('e_launch_touch_update_node');
  57. }, 0);
  58. },
  59. // 热更新 进度更新
  60. _handleUpdateProgression () {
  61. this.reloadHotUpdateView();
  62. },
  63. // 热更新 更新完成
  64. _handleUpdateFinished () {
  65. this.reloadHotUpdateView();
  66. cc.game.emit('e_launch_hot_update_show_alert');
  67. },
  68. // 热更新 更新失败
  69. _handleUpdateFailed () {
  70. this.reloadHotUpdateView();
  71. },
  72. // 版本更新下载
  73. _handleVersionDownloading () {
  74. this.reloadVersionUpdateView();
  75. },
  76. // 版本更新暂停
  77. _handleVersionPause () {
  78. this.reloadVersionUpdateView();
  79. },
  80. // 版本更新结束
  81. _handleVersionFinished () {
  82. this.reloadVersionUpdateView();
  83. },
  84. // 版本更新失败
  85. _handleVersionFailed () {
  86. this.reloadVersionUpdateView();
  87. },
  88. /**
  89. * 收到点击事件
  90. *
  91. * @author Pyden
  92. * @date 2019-03-21
  93. * @param {cc.Button} sender
  94. */
  95. _onClicked (sender) {
  96. G.AudioMgr.playEffect('res_audio/mp3/sound/click', false);
  97. }
  98. });