// Learn TypeScript: // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html import MoreGameData from "../datas/MoreGameData"; import AdM from "../manager/AdM"; import GameM, { AUDIO_TYPE } from "../manager/GameM"; import UiM from "../manager/UiM"; import MoreGameNode from "../ui/MoreGameNode"; import LogUtil from "../utils/LogUtil"; import { Utils } from "../utils/Utils"; const { ccclass, property } = cc._decorator; @ccclass export default class MoreNormalGameItem extends cc.Component { @property(cc.Sprite) iconNode: cc.Sprite = null; @property(cc.Label) progressLabel: cc.Label = null; @property(cc.Node) btnDown: cc.Node = null; @property(cc.Node) btnOpen: cc.Node = null; @property(cc.Label) labName: cc.Label = null; @property(cc.Label) labDes: cc.Label = null; @property(cc.Node) spRed: cc.Node = null; // LIFE-CYCLE CALLBACKS: // onLoad () {} private data = null start() { } setInfo(data) { this.data = data if (cc.sys.os == cc.sys.OS_ANDROID) { cc.loader.load(data.icon, (err, res) => { if (err) { console.log('err:', err); return; } if (cc.isValid(this.iconNode)) { let tex: cc.Texture2D = res as cc.Texture2D; this.iconNode.spriteFrame = new cc.SpriteFrame(tex); } }) } this.labName.string = data.title this.labDes.string = data.introduction this.spRed.active = false if (AdM.canStartGame(data.packageName, false)) { this.btnDown.active = false this.btnOpen.active = true } else { if (Utils.checkHasApk(data.nebulaAppId + ".apk") != "") { this.btnDown.active = false this.btnOpen.active = true } else { this.btnDown.active = true this.btnOpen.active = false // this.spRed.active = true let info = MoreGameData.Instance.getTaskInfo(data.nebulaAppId) if (info != null) { this.schedule(() => { this.showDownloadProgress() }, 0.5) } else { this.progressLabel.string = "下载" } } } } // clickPic() { // GameM.audioM.playEffect(AUDIO_TYPE.button) // let index = parseInt(this.node.name) // if (UiM.Instance.moreGameNode) { // UiM.Instance.moreGameNode.getComponent(MoreGameNode).onOpenBigPicNode(index) // } // } cool = false creatorDownLoadTask() { GameM.audioM.playEffect(AUDIO_TYPE.button) if (this.cool) { return } this.cool = true this.scheduleOnce(() => { this.cool = false }, 3) let result = MoreGameData.Instance.createNewTask(this.data) if (result != null) { this.schedule(() => { this.showDownloadProgress() }, 0.5) } else { this.progressLabel.string = "" } } showDownloadProgress() { let info = MoreGameData.Instance.getTaskInfo(this.data.nebulaAppId) if (info != null) { if (info.progress >= 0) { LogUtil.logV("showDownloadProgress", "three") this.progressLabel.string = ((info.progress / info.totalBytesReceives) * 100).toFixed(1) + "%" } else { this.setInfo(this.data) } } else { this.setInfo(this.data) } } update(dt) { } }