| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- import DownloadApkData from "../datas/DownloadApkData";
- import AdM from "../manager/AdM";
- import GameM, { AUDIO_TYPE } from "../manager/GameM";
- import UiM from "../manager/UiM";
- import GuideInstallApkNode from "../ui/GuideInstallApkNode";
- import LogUtil from "../utils/LogUtil";
- import Sciencen_M from "../utils/Sciencen_M";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class GuideInstallApkItem extends cc.Component {
- @property(cc.Sprite)
- sp: cc.Sprite = null;
- @property(cc.Label)
- labName: cc.Label = null;
- @property(cc.Label)
- labState: cc.Label = null;
- @property(cc.Label)
- labGold: cc.Label = null;
- jsonObj = null
- init(jsonObj) {
- this.jsonObj = jsonObj
- let appName = this.jsonObj["appName"]
- let icon = this.jsonObj["icon"]
- let state = this.jsonObj['state']
- switch (state) {
- case 1:
- this.labState.string = "安装"
- break
- case 2:
- this.labState.string = "领奖"
- break
- case 3:
- this.labState.string = "启动"
- break
- case 4:
- this.labState.string = "领奖"
- break
- }
- let videoPrice = GameM.commonData.buyNumCfg[(GameM.commonData.buyTimeTotal + 1).toString()].gold;
- let gold = ''
- if (state <= 2) {
- gold = Sciencen_M.instance.accMul(videoPrice, DownloadApkData.Instance.installRatio)
- }
- else {
- gold = Sciencen_M.instance.accMul(videoPrice, DownloadApkData.Instance.openRatio)
- }
- this.labGold.string = Sciencen_M.instance.format(gold)
- cc.loader.load(icon, (err, res) => {
- if (err) {
- console.log('err:', err);
- return;
- }
- LogUtil.logV("GuideInstallApkNode", "two ")
- let tex: cc.Texture2D = res as cc.Texture2D;
- this.sp.spriteFrame = new cc.SpriteFrame(tex);
- })
- this.labName.string = appName
- }
- /** 刷新显示状态 */
- freshItem(addState) {
- if (addState == 1) {
- LogUtil.logV("GuideInstallApkNode path ", this.jsonObj["path"])
- if (AdM.canStartGame(this.jsonObj["packageName"], false)) {
- LogUtil.logV("GuideInstallApkNode path 22222 ", this.jsonObj["path"])
- this.jsonObj["state"] = 2
- this.init(this.jsonObj)
- DownloadApkData.Instance.installPackageName = ''
- DownloadApkData.Instance.updatePackage(this.jsonObj)
- }
- }
- else if (addState == 2) {
- this.jsonObj["state"] = 4
- this.init(this.jsonObj)
- DownloadApkData.Instance.openPackageName = ''
- DownloadApkData.Instance.updatePackage(this.jsonObj)
- }
- }
- /** 获取奖励返回 */
- freshGetAward() {
- let state = this.jsonObj['state']
- switch (state) {
- case 2:
- // DownloadApkData.Instance.updateRewards(0)
- this.jsonObj["state"] = 3
- this.init(this.jsonObj)
- DownloadApkData.Instance.updatePackage(this.jsonObj)
- break
- case 4:
- // DownloadApkData.Instance.updateRewards(1)
- this.jsonObj["state"] = 5
- DownloadApkData.Instance.updatePackage(this.jsonObj)
- this.node.parent = null
- this.node.destroy()
- break
- }
- }
- clickBtn() {
- GameM.audioM.playEffect(AUDIO_TYPE.button)
- let state = this.jsonObj['state']
- switch (state) {
- case 1:
- AdM.onSendEvent('Gourd_Install_icon', '宝葫芦安装按钮点击', 'Gourd')
- DownloadApkData.Instance.installPackageName = this.jsonObj["packageName"]
- AdM.installApk(this.jsonObj['path'])
- LogUtil.logV("GuideInstallApkNode installPackageName ", DownloadApkData.Instance.installPackageName)
- break
- case 2:
- // DownloadApkData.Instance.updateRewards(0)
- // this.jsonObj["state"] = 3
- // this.init(this.jsonObj)
- // DownloadApkData.Instance.updatePackage(this.jsonObj["packageName"], this.jsonObj["state"])
- if (UiM.Instance.guideInstallApkNode) {
- UiM.Instance.guideInstallApkNode.getComponent(GuideInstallApkNode).openRewardPanel(1)
- DownloadApkData.Instance.curGuideInstallItem = this
- }
- break
- case 3:
- DownloadApkData.Instance.openPackageName = this.jsonObj["packageName"]
- let isExit = AdM.canStartGame(this.jsonObj["packageName"], true)
- //安装的应用已被删除
- if (!isExit) {
- this.jsonObj['state'] = 4
- this.freshGetAward()
- }
- break
- case 4:
- // DownloadApkData.Instance.updateRewards(1)
- // this.jsonObj["state"] = 5
- // this.init(this.jsonObj)
- // DownloadApkData.Instance.updatePackage(this.jsonObj["packageName"], this.jsonObj["state"])
- // this.node.destroy()
- if (UiM.Instance.guideInstallApkNode) {
- UiM.Instance.guideInstallApkNode.getComponent(GuideInstallApkNode).openRewardPanel(2)
- DownloadApkData.Instance.curGuideInstallItem = this
- }
- break
- }
- }
- }
|