MoreGamePicItem.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**
  2. * @description 互推banner 单个item
  3. * @author kaka
  4. */
  5. import JsbSystem from "../../../mk/system/JsbSystem";
  6. import { DataEventId } from "../../data/GameData";
  7. const { ccclass, property } = cc._decorator;
  8. @ccclass
  9. export default class MoreGamePicItem extends cc.Component {
  10. @property(cc.Sprite)
  11. banner: cc.Sprite = null;
  12. @property(cc.Node)
  13. spRed: cc.Node = null;
  14. @property(cc.Sprite)
  15. spPro: cc.Sprite = null;
  16. @property(cc.Label)
  17. labPro: cc.Label = null;
  18. @property(cc.Node)
  19. btnStart: cc.Node = null;
  20. data = null
  21. cool = false
  22. init(data) {
  23. if (!CC_JSB) {
  24. return;
  25. }
  26. this.data = data
  27. cc.loader.load(data.banner2, (err, res) => {
  28. if (err) {
  29. console.log('err:', err);
  30. return;
  31. }
  32. if (this.banner) {
  33. let tex: cc.Texture2D = res as cc.Texture2D;
  34. this.banner.spriteFrame = new cc.SpriteFrame(tex);
  35. }
  36. })
  37. this.spPro.node.active = false
  38. this.btnStart.active = false
  39. this.labPro.string = ''
  40. //打开
  41. if (data.appType == 1) {
  42. if (JsbSystem.ifCanStartGame(data.packageName, false)) {
  43. this.spRed.active = false
  44. this.btnStart.active = true
  45. } else {
  46. if (JsbSystem.isFileExist(data.nebulaAppId)) {
  47. //安装
  48. this.spRed.active = false
  49. this.btnStart.active = true
  50. } else {
  51. //下载
  52. this.spRed.active = true
  53. }
  54. }
  55. }
  56. else if (data.appType == 2) {
  57. this.spRed.active = false
  58. this.btnStart.active = true
  59. }
  60. }
  61. creatorDownLoadTask() {
  62. if (!CC_JSB) {
  63. return;
  64. }
  65. if (this.cool) {
  66. return
  67. }
  68. mk.data.sendDataEvent(DataEventId.hutuiFunction, "互推推荐位banner下载");
  69. this.cool = true
  70. this.scheduleOnce(() => {
  71. this.cool = false
  72. }, 3)
  73. if (this.data.appType == 1) {
  74. let result = gData.moreGame.createNewTask(this.data, 3)
  75. if (result != null) {
  76. this.schedule(() => {
  77. this.showDownloadProgress()
  78. }, 0.5)
  79. }
  80. }
  81. else if (this.data.appType == 2) {
  82. cc.sys.openURL(this.data.recommendLink);
  83. }
  84. }
  85. showDownloadProgress() {
  86. let info = gData.moreGame.getTaskInfo(this.data.nebulaAppId)
  87. if (info != null) {
  88. if (info.progress >= 0) {
  89. // LogUtil.logV("showDownloadProgress", "three")
  90. this.spPro.node.active = true
  91. let proNum = info.progress / info.totalBytesReceives
  92. let pro = (proNum * 100).toFixed(1)
  93. this.spPro.fillRange = 1 - proNum
  94. this.labPro.string = `${pro}%`
  95. } else {
  96. this.init(this.data)
  97. }
  98. } else {
  99. this.init(this.data)
  100. }
  101. }
  102. }