/** * @description 互推界面常规item * @author kaka */ import JsbSystem from "../../../mk/system/JsbSystem"; import { DataEventId } from "../../data/GameData"; const { ccclass, property } = cc._decorator; @ccclass export default class MoreGameNormalItem 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; private data = null /** * list_data * @param data item数据 */ public async setItemData(bData) { if (!CC_JSB) { return; } this.setInfo(bData.item_data) } setInfo(data) { this.data = data; cc.loader.load(this.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 = this.data.title this.labDes.string = this.data.introduction this.spRed.active = false if (this.data.appType == 1) { if (JsbSystem.ifCanStartGame(this.data.packageName, false)) { this.btnDown.active = false this.btnOpen.active = true } else { if (JsbSystem.isFileExist(this.data.nebulaAppId)) { this.btnDown.active = false this.btnOpen.active = true } else { this.btnDown.active = true this.btnOpen.active = false // this.spRed.active = true let info = gData.moreGame.getTaskInfo(this.data.nebulaAppId) if (info != null) { this.schedule(() => { this.showDownloadProgress() }, 0.5) } else { this.progressLabel.string = "下载" } } } } else if (this.data.appType == 2) { this.btnDown.active = false this.btnOpen.active = true } } cool = false creatorDownLoadTask() { mk.audio.playEffect('button'); if (!CC_JSB) { return; } if (this.cool) { return } mk.data.sendDataEvent(DataEventId.hutuiFunction,"互推格子位下载"); this.cool = true this.scheduleOnce(() => { this.cool = false }, 3) if (this.data.appType == 1) { let result = gData.moreGame.createNewTask(this.data) if (result != null) { this.schedule(() => { this.showDownloadProgress() }, 0.5) } else { this.progressLabel.string = "" } } else if (this.data.appType == 2) { cc.sys.openURL(this.data.recommendLink); // JsbSystem.sendEvent('hutuiEventLaunch_' + this.data.nebulaAppId, "互推启动" + this.data.title, 'hutuiEventLaunch') } } showDownloadProgress() { let info = gData.moreGame.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) } } }