MoreGamePicItem.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. this.data = data
  23. //pc不加载,加载会报错
  24. if (cc.sys.os != cc.sys.OS_WINDOWS) {
  25. cc.loader.load(data.banner2, (err, res) => {
  26. if (err) {
  27. console.log('err:', err);
  28. return;
  29. }
  30. if (this.banner) {
  31. let tex: cc.Texture2D = res as cc.Texture2D;
  32. this.banner.spriteFrame = new cc.SpriteFrame(tex);
  33. }
  34. })
  35. }
  36. this.spPro.node.active = false
  37. this.btnStart.active = false
  38. this.labPro.string = ''
  39. //打开
  40. if (JsbSystem.ifCanStartGame(data.packageName, false)) {
  41. this.spRed.active = false
  42. this.btnStart.active = true
  43. } else {
  44. if (JsbSystem.isFileExist(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 = gData.moreGame.createNewTask(this.data)
  64. if (result != null) {
  65. this.schedule(() => {
  66. this.showDownloadProgress()
  67. }, 0.5)
  68. }
  69. }
  70. showDownloadProgress() {
  71. let info = gData.moreGame.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. }