MoreGamePicItem.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import MoreGameData from "../datas/MoreGameData";
  2. import AdM from "../manager/AdM";
  3. import UiM from "../manager/UiM";
  4. import MoreGameNode from "../ui/MoreGameNode";
  5. import LogUtil from "../utils/LogUtil";
  6. import { Utils } from "../utils/Utils";
  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. start() {
  23. }
  24. init(data) {
  25. this.data = data
  26. cc.loader.load(data.banner2, (err, res) => {
  27. if (err) {
  28. console.log('err:', err);
  29. return;
  30. }
  31. if (this.banner) {
  32. let tex: cc.Texture2D = res as cc.Texture2D;
  33. this.banner.spriteFrame = new cc.SpriteFrame(tex);
  34. }
  35. })
  36. this.spPro.node.active = false
  37. this.btnStart.active = false
  38. this.labPro.string = ''
  39. //打开
  40. if (AdM.canStartGame(data.packageName, false)) {
  41. this.spRed.active = false
  42. this.btnStart.active = true
  43. } else {
  44. if (Utils.checkHasApk(data.nebulaAppId + ".apk") != "") {
  45. //安装
  46. this.spRed.active = false
  47. this.btnStart.active = true
  48. } else {
  49. //下载
  50. this.spRed.active = true
  51. }
  52. }
  53. }
  54. creatorDownLoadTask() {
  55. UiM.Instance.moreGameNode.getComponent(MoreGameNode).hasClick = true
  56. if (this.cool) {
  57. return
  58. }
  59. this.cool = true
  60. this.scheduleOnce(() => {
  61. this.cool = false
  62. }, 3)
  63. let result = MoreGameData.Instance.createNewTask(this.data)
  64. if (result != null) {
  65. this.schedule(() => {
  66. this.showDownloadProgress()
  67. }, 0.5)
  68. }
  69. }
  70. showDownloadProgress() {
  71. let info = MoreGameData.Instance.getTaskInfo(this.data.nebulaAppId)
  72. if (info != null) {
  73. if (info.progress >= 0) {
  74. LogUtil.logV("showDownloadProgress", "three")
  75. this.spPro.node.active = true
  76. let proNum = info.progress / info.totalBytesReceives
  77. let pro = (proNum * 100).toFixed(1)
  78. this.spPro.fillRange = 1 - proNum
  79. this.labPro.string = `${pro}%`
  80. } else {
  81. this.init(this.data)
  82. }
  83. } else {
  84. this.init(this.data)
  85. }
  86. }
  87. }