GuideInstallApkNode.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. import DownloadApkData from "../datas/DownloadApkData";
  2. import Main from "../Main";
  3. import AdM from "../manager/AdM";
  4. import GameM, { AUDIO_TYPE } from "../manager/GameM";
  5. import UiM, { PANEL_NAME } from "../manager/UiM";
  6. import GuideInstallApkItem from "../prefabs/GuideInstallApkItem";
  7. import LogUtil from "../utils/LogUtil";
  8. import Sciencen_M from "../utils/Sciencen_M";
  9. import EffectNode from "./EffectNode";
  10. const { ccclass, property } = cc._decorator;
  11. @ccclass
  12. export default class GuideInstallApkNode extends cc.Component {
  13. // LIFE-CYCLE CALLBACKS:
  14. @property(cc.Node)
  15. listContent: cc.Node = null
  16. @property(cc.Node)
  17. awardContent: cc.Node = null
  18. @property(cc.Node)
  19. contentNode: cc.Node = null
  20. @property(cc.Prefab)
  21. itemPrefab: cc.Prefab = null
  22. @property(cc.Label)
  23. labGold: cc.Label = null
  24. @property(cc.Node)
  25. btnLeft: cc.Node = null
  26. @property(cc.Node)
  27. btnRight: cc.Node = null
  28. @property(cc.ScrollView)
  29. sv: cc.ScrollView = null
  30. @property(cc.Node)
  31. svContent: cc.Node = null
  32. private _n = 0
  33. private _dis = 3
  34. private total = 0
  35. private count = 0
  36. private data = null
  37. private rewardsType = 0
  38. private rewardsNum = '0'
  39. private itemW = 190
  40. private scrollW = 1000
  41. cool = false
  42. // onLoad () {}
  43. start() {
  44. this.sv.node.on('scrolling', this.onScroll, this)
  45. AdM.checkPathApk()
  46. this.btnLeft.active = false
  47. }
  48. initView() {
  49. this.contentNode.destroyAllChildren()
  50. this.total = 0
  51. this._n = 0
  52. this.data = DownloadApkData.Instance.checkApkData()
  53. this.total = this.data.length
  54. if (this.total <= 3) {
  55. this.btnRight.active = false
  56. }
  57. LogUtil.logV('GuideInstallApkNode this.total', this.total)
  58. if (this.total <= 0) {
  59. UiM.Instance.offPanel(PANEL_NAME.GuideInstallApkNode)
  60. UiM.Instance.hallNode.getComponent(Main).setGuideInstallVisible(false)
  61. }
  62. }
  63. addItem() {
  64. let jsonObj = this.data[this.count]
  65. let packageName = jsonObj["packageName"]
  66. let node = cc.instantiate(this.itemPrefab)
  67. node.name = packageName
  68. node.getComponent(GuideInstallApkItem).init(jsonObj)
  69. node.parent = this.contentNode
  70. this._n = 0
  71. this.count++
  72. if (this.count == this.total) {
  73. this.scrollW = this.svContent.width - this.sv.node.width
  74. }
  75. }
  76. update() {
  77. if (this.count < this.total) {
  78. if (this._n <= this._dis) {
  79. this._n++
  80. }
  81. else {
  82. this.addItem()
  83. }
  84. }
  85. }
  86. /** 安装或打开后返回 */
  87. freshItem() {
  88. if (DownloadApkData.Instance.installPackageName != '') {
  89. LogUtil.logV("GuideInstallApkNode freshItem ", DownloadApkData.Instance.installPackageName)
  90. let node = this.contentNode.getChildByName(DownloadApkData.Instance.installPackageName)
  91. node.getComponent(GuideInstallApkItem).freshItem(1)
  92. }
  93. else if (DownloadApkData.Instance.openPackageName != '') {
  94. let node = this.contentNode.getChildByName(DownloadApkData.Instance.openPackageName)
  95. node.getComponent(GuideInstallApkItem).freshItem(2)
  96. }
  97. }
  98. openRewardPanel(rewardsType) {
  99. this.rewardsType = rewardsType
  100. let videoPrice = GameM.commonData.buyNumCfg[(GameM.commonData.buyTimeTotal + 1).toString()].gold;
  101. if (rewardsType == 1) {
  102. this.rewardsNum = Sciencen_M.instance.accMul(videoPrice, DownloadApkData.Instance.installRatio)
  103. }
  104. else if (rewardsType == 2) {
  105. this.rewardsNum = Sciencen_M.instance.accMul(videoPrice, DownloadApkData.Instance.openRatio)
  106. }
  107. this.listContent.active = false
  108. this.awardContent.active = true
  109. this.labGold.string = Sciencen_M.instance.format(this.rewardsNum)
  110. }
  111. onScroll(sc) {
  112. console.log(sc)
  113. if (this.svContent.x >= -1) {
  114. this.btnLeft.active = false
  115. }
  116. else if (this.svContent.x <= -this.scrollW + 1) {
  117. this.btnRight.active = false
  118. }
  119. else {
  120. this.btnLeft.active = true
  121. this.btnRight.active = true
  122. }
  123. }
  124. clickGetGold() {
  125. GameM.audioM.playEffect(AUDIO_TYPE.button);
  126. if (this.cool) {
  127. return
  128. }
  129. this.cool = true
  130. this.scheduleOnce(() => {
  131. this.cool = false
  132. }, 3)
  133. if (this.rewardsType == 1) {
  134. AdM.onSendEvent('Gourd_Install_reward', '宝葫芦安装领奖', 'Gourd')
  135. }
  136. else if (this.rewardsType == 2) {
  137. AdM.onSendEvent('Gourd_Start_reward', '宝葫芦启动领奖', 'Gourd')
  138. }
  139. DownloadApkData.Instance.updateRewards(this.rewardsType)
  140. }
  141. getGoldBack() {
  142. this.cool = false
  143. GameM.commonData.updateGold(this.rewardsNum)
  144. GameM.audioM.playEffect(AUDIO_TYPE.getGold, false)
  145. EffectNode.instance.PlayCoinAnim(0, 20, cc.v2(0, -300));
  146. this.awardContent.active = false
  147. this.listContent.active = true
  148. if (this.contentNode.childrenCount <= 0) {
  149. UiM.Instance.hallNode.getComponent(Main).setGuideInstallVisible(false)
  150. UiM.Instance.offPanel(PANEL_NAME.GuideInstallApkNode)
  151. }
  152. }
  153. clickLeft() {
  154. GameM.audioM.playEffect(AUDIO_TYPE.button);
  155. let offsetX = Math.abs(this.svContent.x) - this.itemW
  156. let toX = cc.v2(offsetX / this.scrollW, 0)
  157. this.sv.scrollTo(toX, 0.3)
  158. }
  159. clickRight() {
  160. GameM.audioM.playEffect(AUDIO_TYPE.button);
  161. let offsetX = Math.abs(this.svContent.x) + this.itemW
  162. let toX = cc.v2(offsetX / this.scrollW, 0)
  163. this.sv.scrollTo(toX, 0.3)
  164. }
  165. clickClose() {
  166. if (this.cool) {
  167. return
  168. }
  169. GameM.audioM.playEffect(AUDIO_TYPE.button);
  170. UiM.Instance.offPanel(PANEL_NAME.GuideInstallApkNode)
  171. }
  172. onDestroy() {
  173. this.sv.node.off('scrolling', this.onScroll, this)
  174. }
  175. }