GuideInstallApkItem.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import DownloadApkData from "../datas/DownloadApkData";
  2. import AdM from "../manager/AdM";
  3. import GameM, { AUDIO_TYPE } from "../manager/GameM";
  4. import UiM from "../manager/UiM";
  5. import GuideInstallApkNode from "../ui/GuideInstallApkNode";
  6. import LogUtil from "../utils/LogUtil";
  7. import Sciencen_M from "../utils/Sciencen_M";
  8. const { ccclass, property } = cc._decorator;
  9. @ccclass
  10. export default class GuideInstallApkItem extends cc.Component {
  11. @property(cc.Sprite)
  12. sp: cc.Sprite = null;
  13. @property(cc.Label)
  14. labName: cc.Label = null;
  15. @property(cc.Label)
  16. labState: cc.Label = null;
  17. @property(cc.Label)
  18. labGold: cc.Label = null;
  19. jsonObj = null
  20. init(jsonObj) {
  21. this.jsonObj = jsonObj
  22. let appName = this.jsonObj["appName"]
  23. let icon = this.jsonObj["icon"]
  24. let state = this.jsonObj['state']
  25. switch (state) {
  26. case 1:
  27. this.labState.string = "安装"
  28. break
  29. case 2:
  30. this.labState.string = "领奖"
  31. break
  32. case 3:
  33. this.labState.string = "启动"
  34. break
  35. case 4:
  36. this.labState.string = "领奖"
  37. break
  38. }
  39. let videoPrice = GameM.commonData.buyNumCfg[(GameM.commonData.buyTimeTotal + 1).toString()].gold;
  40. let gold = ''
  41. if (state <= 2) {
  42. gold = Sciencen_M.instance.accMul(videoPrice, DownloadApkData.Instance.installRatio)
  43. }
  44. else {
  45. gold = Sciencen_M.instance.accMul(videoPrice, DownloadApkData.Instance.openRatio)
  46. }
  47. this.labGold.string = Sciencen_M.instance.format(gold)
  48. cc.loader.load(icon, (err, res) => {
  49. if (err) {
  50. console.log('err:', err);
  51. return;
  52. }
  53. LogUtil.logV("GuideInstallApkNode", "two ")
  54. let tex: cc.Texture2D = res as cc.Texture2D;
  55. this.sp.spriteFrame = new cc.SpriteFrame(tex);
  56. })
  57. this.labName.string = appName
  58. }
  59. /** 刷新显示状态 */
  60. freshItem(addState) {
  61. if (addState == 1) {
  62. LogUtil.logV("GuideInstallApkNode path ", this.jsonObj["path"])
  63. if (AdM.canStartGame(this.jsonObj["packageName"], false)) {
  64. LogUtil.logV("GuideInstallApkNode path 22222 ", this.jsonObj["path"])
  65. this.jsonObj["state"] = 2
  66. this.init(this.jsonObj)
  67. DownloadApkData.Instance.installPackageName = ''
  68. DownloadApkData.Instance.updatePackage(this.jsonObj)
  69. }
  70. }
  71. else if (addState == 2) {
  72. this.jsonObj["state"] = 4
  73. this.init(this.jsonObj)
  74. DownloadApkData.Instance.openPackageName = ''
  75. DownloadApkData.Instance.updatePackage(this.jsonObj)
  76. }
  77. }
  78. /** 获取奖励返回 */
  79. freshGetAward() {
  80. let state = this.jsonObj['state']
  81. switch (state) {
  82. case 2:
  83. // DownloadApkData.Instance.updateRewards(0)
  84. this.jsonObj["state"] = 3
  85. this.init(this.jsonObj)
  86. DownloadApkData.Instance.updatePackage(this.jsonObj)
  87. break
  88. case 4:
  89. // DownloadApkData.Instance.updateRewards(1)
  90. this.jsonObj["state"] = 5
  91. DownloadApkData.Instance.updatePackage(this.jsonObj)
  92. this.node.parent = null
  93. this.node.destroy()
  94. break
  95. }
  96. }
  97. clickBtn() {
  98. GameM.audioM.playEffect(AUDIO_TYPE.button)
  99. let state = this.jsonObj['state']
  100. switch (state) {
  101. case 1:
  102. AdM.onSendEvent('Gourd_Install_icon', '宝葫芦安装按钮点击', 'Gourd')
  103. DownloadApkData.Instance.installPackageName = this.jsonObj["packageName"]
  104. AdM.installApk(this.jsonObj['path'])
  105. LogUtil.logV("GuideInstallApkNode installPackageName ", DownloadApkData.Instance.installPackageName)
  106. break
  107. case 2:
  108. // DownloadApkData.Instance.updateRewards(0)
  109. // this.jsonObj["state"] = 3
  110. // this.init(this.jsonObj)
  111. // DownloadApkData.Instance.updatePackage(this.jsonObj["packageName"], this.jsonObj["state"])
  112. if (UiM.Instance.guideInstallApkNode) {
  113. UiM.Instance.guideInstallApkNode.getComponent(GuideInstallApkNode).openRewardPanel(1)
  114. DownloadApkData.Instance.curGuideInstallItem = this
  115. }
  116. break
  117. case 3:
  118. DownloadApkData.Instance.openPackageName = this.jsonObj["packageName"]
  119. let isExit = AdM.canStartGame(this.jsonObj["packageName"], true)
  120. //安装的应用已被删除
  121. if (!isExit) {
  122. this.jsonObj['state'] = 4
  123. this.freshGetAward()
  124. }
  125. break
  126. case 4:
  127. // DownloadApkData.Instance.updateRewards(1)
  128. // this.jsonObj["state"] = 5
  129. // this.init(this.jsonObj)
  130. // DownloadApkData.Instance.updatePackage(this.jsonObj["packageName"], this.jsonObj["state"])
  131. // this.node.destroy()
  132. if (UiM.Instance.guideInstallApkNode) {
  133. UiM.Instance.guideInstallApkNode.getComponent(GuideInstallApkNode).openRewardPanel(2)
  134. DownloadApkData.Instance.curGuideInstallItem = this
  135. }
  136. break
  137. }
  138. }
  139. }