import DownloadApkData from "../datas/DownloadApkData"; import Main from "../Main"; import AdM from "../manager/AdM"; import GameM, { AUDIO_TYPE } from "../manager/GameM"; import UiM, { PANEL_NAME } from "../manager/UiM"; import GuideInstallApkItem from "../prefabs/GuideInstallApkItem"; import LogUtil from "../utils/LogUtil"; import Sciencen_M from "../utils/Sciencen_M"; import EffectNode from "./EffectNode"; const { ccclass, property } = cc._decorator; @ccclass export default class GuideInstallApkNode extends cc.Component { // LIFE-CYCLE CALLBACKS: @property(cc.Node) listContent: cc.Node = null @property(cc.Node) awardContent: cc.Node = null @property(cc.Node) contentNode: cc.Node = null @property(cc.Prefab) itemPrefab: cc.Prefab = null @property(cc.Label) labGold: cc.Label = null @property(cc.Node) btnLeft: cc.Node = null @property(cc.Node) btnRight: cc.Node = null @property(cc.ScrollView) sv: cc.ScrollView = null @property(cc.Node) svContent: cc.Node = null private _n = 0 private _dis = 3 private total = 0 private count = 0 private data = null private rewardsType = 0 private rewardsNum = '0' private itemW = 190 private scrollW = 1000 cool = false // onLoad () {} start() { this.sv.node.on('scrolling', this.onScroll, this) AdM.checkPathApk() this.btnLeft.active = false } initView() { this.contentNode.destroyAllChildren() this.total = 0 this._n = 0 this.data = DownloadApkData.Instance.checkApkData() this.total = this.data.length if (this.total <= 3) { this.btnRight.active = false } LogUtil.logV('GuideInstallApkNode this.total', this.total) if (this.total <= 0) { UiM.Instance.offPanel(PANEL_NAME.GuideInstallApkNode) UiM.Instance.hallNode.getComponent(Main).setGuideInstallVisible(false) } } addItem() { let jsonObj = this.data[this.count] let packageName = jsonObj["packageName"] let node = cc.instantiate(this.itemPrefab) node.name = packageName node.getComponent(GuideInstallApkItem).init(jsonObj) node.parent = this.contentNode this._n = 0 this.count++ if (this.count == this.total) { this.scrollW = this.svContent.width - this.sv.node.width } } update() { if (this.count < this.total) { if (this._n <= this._dis) { this._n++ } else { this.addItem() } } } /** 安装或打开后返回 */ freshItem() { if (DownloadApkData.Instance.installPackageName != '') { LogUtil.logV("GuideInstallApkNode freshItem ", DownloadApkData.Instance.installPackageName) let node = this.contentNode.getChildByName(DownloadApkData.Instance.installPackageName) node.getComponent(GuideInstallApkItem).freshItem(1) } else if (DownloadApkData.Instance.openPackageName != '') { let node = this.contentNode.getChildByName(DownloadApkData.Instance.openPackageName) node.getComponent(GuideInstallApkItem).freshItem(2) } } openRewardPanel(rewardsType) { this.rewardsType = rewardsType let videoPrice = GameM.commonData.buyNumCfg[(GameM.commonData.buyTimeTotal + 1).toString()].gold; if (rewardsType == 1) { this.rewardsNum = Sciencen_M.instance.accMul(videoPrice, DownloadApkData.Instance.installRatio) } else if (rewardsType == 2) { this.rewardsNum = Sciencen_M.instance.accMul(videoPrice, DownloadApkData.Instance.openRatio) } this.listContent.active = false this.awardContent.active = true this.labGold.string = Sciencen_M.instance.format(this.rewardsNum) } onScroll(sc) { console.log(sc) if (this.svContent.x >= -1) { this.btnLeft.active = false } else if (this.svContent.x <= -this.scrollW + 1) { this.btnRight.active = false } else { this.btnLeft.active = true this.btnRight.active = true } } clickGetGold() { GameM.audioM.playEffect(AUDIO_TYPE.button); if (this.cool) { return } this.cool = true this.scheduleOnce(() => { this.cool = false }, 3) if (this.rewardsType == 1) { AdM.onSendEvent('Gourd_Install_reward', '宝葫芦安装领奖', 'Gourd') } else if (this.rewardsType == 2) { AdM.onSendEvent('Gourd_Start_reward', '宝葫芦启动领奖', 'Gourd') } DownloadApkData.Instance.updateRewards(this.rewardsType) } getGoldBack() { this.cool = false GameM.commonData.updateGold(this.rewardsNum) GameM.audioM.playEffect(AUDIO_TYPE.getGold, false) EffectNode.instance.PlayCoinAnim(0, 20, cc.v2(0, -300)); this.awardContent.active = false this.listContent.active = true if (this.contentNode.childrenCount <= 0) { UiM.Instance.hallNode.getComponent(Main).setGuideInstallVisible(false) UiM.Instance.offPanel(PANEL_NAME.GuideInstallApkNode) } } clickLeft() { GameM.audioM.playEffect(AUDIO_TYPE.button); let offsetX = Math.abs(this.svContent.x) - this.itemW let toX = cc.v2(offsetX / this.scrollW, 0) this.sv.scrollTo(toX, 0.3) } clickRight() { GameM.audioM.playEffect(AUDIO_TYPE.button); let offsetX = Math.abs(this.svContent.x) + this.itemW let toX = cc.v2(offsetX / this.scrollW, 0) this.sv.scrollTo(toX, 0.3) } clickClose() { if (this.cool) { return } GameM.audioM.playEffect(AUDIO_TYPE.button); UiM.Instance.offPanel(PANEL_NAME.GuideInstallApkNode) } onDestroy() { this.sv.node.off('scrolling', this.onScroll, this) } }