import Loader from "../Loader"; import AdM from "../manager/AdM"; import GameM, { AUDIO_TYPE } from "../manager/GameM"; import UiM, { PANEL_NAME } from "../manager/UiM"; import { Utils } from "../utils/Utils"; import EffectNode from "./EffectNode"; /** 最新版本下载 */ const { ccclass, property } = cc._decorator; @ccclass export default class DownLoadUI extends cc.Component { @property(cc.Toggle) skipToggle: cc.Toggle = null @property(cc.Label) labUpdate: cc.Label = null @property(cc.Label) labFix: cc.Label = null @property(cc.Node) btnSure: cc.Node = null @property(cc.Node) btnCancel: cc.Node = null @property(cc.Sprite) fileProgress: cc.Sprite = null @property(cc.Label) labPro: cc.Label = null /** 是否显示“不再提醒” */ showToggle = false start() { this.setText() } init(showToggle) { this.skipToggle.node.active = showToggle this.showToggle = showToggle if (!showToggle) { this.btnSure.y = -366 } } clickDownLoad() { GameM.audioM.playEffect(AUDIO_TYPE.button) this.btnSure.active = false this.btnCancel.active = false this.skipToggle.node.active = false this.fileProgress.node.parent.active = true let apkUrl = GameM.commonData.installUrl let arr = apkUrl.split('/') let apkName = arr[arr.length - 1] let installUrl = Utils.checkHasApk(apkName) //已下载过 if (installUrl != '') { AdM.installApk(installUrl) } else { //未下载过 Utils.downFile2Local(apkUrl, apkName, (locaPath) => { AdM.installApk(locaPath) }, (locaPath) => { let str = '下载失败,请检查网络后重试' if (cc.director.getScene().name == 'Loader') { cc.find('Canvas').getComponent(Loader).PlayTip(str) } else { EffectNode.instance.PlayTip(str) } this.fileProgress.node.parent.active = false this.fileProgress.fillRange = 0 this.labPro.string = '0%' this.btnSure.active = true this.btnCancel.active = true this.skipToggle.node.active = this.showToggle }, (bytesReceived, totalBytesReceived, totalBytesExpected) => { let pro = totalBytesReceived / totalBytesExpected this.setPro(pro) }) } } //更新进度 setPro(pro) { this.labPro.string = `${Math.floor(pro * 100)}%` this.fileProgress.fillRange = pro } clickSkip() { GameM.audioM.playEffect(AUDIO_TYPE.button) if (this.skipToggle.isChecked) { let installVersion = GameM.commonData.installVersion GameM.globalStorage.setStorage('installVersion' + installVersion, 'skip', 1) } UiM.Instance.offPanel(PANEL_NAME.DownLoadUI) GameM.commonData.skipUpdate = true } /** 设置文本 */ setText() { this.labUpdate.string = GameM.commonData.updateDes this.labFix.string = GameM.commonData.fixDes } }