const UpdateProgress = require('UpdateProgress'); // 顶部后台热更新进度条 cc.Class({ editor: { menu: 'Launch/BgUpdateProgress' }, extends: cc.Component, properties: { updateProgress: UpdateProgress, button: cc.Button }, onLoad () { let y = cc.winSize.height - this.node.height / 2 - 5; let x = cc.winSize.width / 2; let newVec2 = this.node.convertToNodeSpaceAR(cc.v2(x, y)); this.node.y = newVec2.y; this.node.x = newVec2.x; }, onEnable () { cc.game.on('e_mgr_launch_update_progression', this._handleUpdateProgression, this); cc.game.on('e_mgr_launch_update_finished', this._handleUpdateFinished, this); cc.game.on('e_mgr_launch_update_failed', this._handleUpdateFailed, this); cc.game.on('e_mgr_launch_version_update_downloading', this._handleVersionDownloading, this); cc.game.on('e_mgr_launch_version_update_pause', this._handleVersionPause, this); cc.game.on('e_mgr_launch_version_update_finished', this._handleVersionFinished, this); cc.game.on('e_mgr_launch_version_update_failed', this._handleVersionFailed, this); if (G.RemoteUpdateInfoMgr.isHotUpdate) { this.reloadHotUpdateView(); } else if (G.RemoteUpdateInfoMgr.isVersionUpdate) { this.reloadVersionUpdateView(); } }, onDisable () { cc.game.targetOff(this); }, reloadHotUpdateView () { this.button.interactable = true; this.updateProgress.setDownloadStatus(G.HotUpdateMgr.status); this.updateProgress.setProgress(G.HotUpdateMgr.downloadedBytes, G.HotUpdateMgr.realTotalBytes); if (G.HotUpdateMgr.status == JMC.UPDATE_STATUS.DOWNLOAD_FINISHED) { this.updateProgress.doFinishAnim(); } }, reloadVersionUpdateView () { this.button.interactable = true; this.updateProgress.setDownloadStatus(G.VersionUpdateMgr.status); let downloadedBytes = (G.VersionUpdateMgr.downloadProgress / 100) * G.VersionUpdateMgr.totalBytes; this.updateProgress.setProgress(downloadedBytes, G.VersionUpdateMgr.totalBytes); if (G.VersionUpdateMgr.status == JMC.UPDATE_STATUS.DOWNLOAD_FINISHED) { this.updateProgress.doFinishAnim(); } }, onClicked () { this._onClicked(); setTimeout (() => { cc.game.emit('e_launch_touch_update_node'); }, 0); }, // 热更新 进度更新 _handleUpdateProgression () { this.reloadHotUpdateView(); }, // 热更新 更新完成 _handleUpdateFinished () { this.reloadHotUpdateView(); cc.game.emit('e_launch_hot_update_show_alert'); }, // 热更新 更新失败 _handleUpdateFailed () { this.reloadHotUpdateView(); }, // 版本更新下载 _handleVersionDownloading () { this.reloadVersionUpdateView(); }, // 版本更新暂停 _handleVersionPause () { this.reloadVersionUpdateView(); }, // 版本更新结束 _handleVersionFinished () { this.reloadVersionUpdateView(); }, // 版本更新失败 _handleVersionFailed () { this.reloadVersionUpdateView(); }, /** * 收到点击事件 * * @author Pyden * @date 2019-03-21 * @param {cc.Button} sender */ _onClicked (sender) { G.AudioMgr.playEffect('res_audio/mp3/sound/click', false); } });