MoreGamePicItem.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * @description 互推banner 单个item
  3. * @author kaka
  4. */
  5. import JsbSystem from "../../../mk/system/JsbSystem";
  6. const { ccclass, property } = cc._decorator;
  7. @ccclass
  8. export default class MoreGamePicItem extends cc.Component {
  9. @property(cc.Sprite)
  10. banner: cc.Sprite = null;
  11. @property(cc.Node)
  12. spRed: cc.Node = null;
  13. @property(cc.Sprite)
  14. spPro: cc.Sprite = null;
  15. @property(cc.Label)
  16. labPro: cc.Label = null;
  17. @property(cc.Node)
  18. btnStart: cc.Node = null;
  19. data = null
  20. cool = false
  21. init(data) {
  22. if (!CC_JSB) {
  23. return;
  24. }
  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 (data.appType == 1) {
  41. if (JsbSystem.ifCanStartGame(data.packageName, false)) {
  42. this.spRed.active = false
  43. this.btnStart.active = true
  44. } else {
  45. if (JsbSystem.isFileExist(data.nebulaAppId)) {
  46. //安装
  47. this.spRed.active = false
  48. this.btnStart.active = true
  49. } else {
  50. //下载
  51. this.spRed.active = true
  52. }
  53. }
  54. }
  55. else if (data.appType == 2) {
  56. this.spRed.active = false
  57. this.btnStart.active = true
  58. }
  59. }
  60. creatorDownLoadTask() {
  61. if (!CC_JSB) {
  62. return;
  63. }
  64. if (this.cool) {
  65. return
  66. }
  67. this.cool = true
  68. this.scheduleOnce(() => {
  69. this.cool = false
  70. }, 3)
  71. if (this.data.appType == 1) {
  72. let result = gData.moreGame.createNewTask(this.data)
  73. if (result != null) {
  74. this.schedule(() => {
  75. this.showDownloadProgress()
  76. }, 0.5)
  77. }
  78. }
  79. else if (this.data.appType == 2) {
  80. cc.sys.openURL(this.data.recommendLink);
  81. }
  82. }
  83. showDownloadProgress() {
  84. let info = gData.moreGame.getTaskInfo(this.data.nebulaAppId)
  85. if (info != null) {
  86. if (info.progress >= 0) {
  87. // LogUtil.logV("showDownloadProgress", "three")
  88. this.spPro.node.active = true
  89. let proNum = info.progress / info.totalBytesReceives
  90. let pro = (proNum * 100).toFixed(1)
  91. this.spPro.fillRange = 1 - proNum
  92. this.labPro.string = `${pro}%`
  93. } else {
  94. this.init(this.data)
  95. }
  96. } else {
  97. this.init(this.data)
  98. }
  99. }
  100. }