| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- /**
- * @description 互推banner 单个item
- * @author kaka
- */
- import JsbSystem from "../../../mk/system/JsbSystem";
- import { DataEventId } from "../../data/GameData";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class MoreGamePicItem extends cc.Component {
- @property(cc.Sprite)
- banner: cc.Sprite = null;
- @property(cc.Node)
- spRed: cc.Node = null;
- @property(cc.Sprite)
- spPro: cc.Sprite = null;
- @property(cc.Label)
- labPro: cc.Label = null;
- @property(cc.Node)
- btnStart: cc.Node = null;
- data = null
- cool = false
- init(data) {
- if (!CC_JSB) {
- return;
- }
- this.data = data
- cc.loader.load(data.banner2, (err, res) => {
- if (err) {
- console.log('err:', err);
- return;
- }
- if (this.banner) {
- let tex: cc.Texture2D = res as cc.Texture2D;
- this.banner.spriteFrame = new cc.SpriteFrame(tex);
- }
- })
- this.spPro.node.active = false
- this.btnStart.active = false
- this.labPro.string = ''
- //打开
- if (data.appType == 1) {
- if (JsbSystem.ifCanStartGame(data.packageName, false)) {
- this.spRed.active = false
- this.btnStart.active = true
- } else {
- if (JsbSystem.isFileExist(data.nebulaAppId)) {
- //安装
- this.spRed.active = false
- this.btnStart.active = true
- } else {
- //下载
- this.spRed.active = true
- }
- }
- }
- else if (data.appType == 2) {
- this.spRed.active = false
- this.btnStart.active = true
- }
- }
- creatorDownLoadTask() {
- if (!CC_JSB) {
- return;
- }
- if (this.cool) {
- return
- }
- mk.data.sendDataEvent(DataEventId.hutuiFunction,"互推推荐位banner下载");
- this.cool = true
- this.scheduleOnce(() => {
- this.cool = false
- }, 3)
- if (this.data.appType == 1) {
- let result = gData.moreGame.createNewTask(this.data, 3)
- if (result != null) {
- this.schedule(() => {
- this.showDownloadProgress()
- }, 0.5)
- }
- }
- else if (this.data.appType == 2) {
- cc.sys.openURL(this.data.recommendLink);
- }
- }
- showDownloadProgress() {
- let info = gData.moreGame.getTaskInfo(this.data.nebulaAppId)
- if (info != null) {
- if (info.progress >= 0) {
- // LogUtil.logV("showDownloadProgress", "three")
- this.spPro.node.active = true
- let proNum = info.progress / info.totalBytesReceives
- let pro = (proNum * 100).toFixed(1)
- this.spPro.fillRange = 1 - proNum
- this.labPro.string = `${pro}%`
- } else {
- this.init(this.data)
- }
- } else {
- this.init(this.data)
- }
- }
- }
|