MoreGameNormalItem.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /**
  2. * @description 互推界面常规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 MoreGameNormalItem extends cc.Component {
  10. @property(cc.Sprite)
  11. iconNode: cc.Sprite = null;
  12. @property(cc.Label)
  13. progressLabel: cc.Label = null;
  14. @property(cc.Node)
  15. btnDown: cc.Node = null;
  16. @property(cc.Node)
  17. btnOpen: cc.Node = null;
  18. @property(cc.Label)
  19. labName: cc.Label = null;
  20. @property(cc.Label)
  21. labDes: cc.Label = null;
  22. @property(cc.Node)
  23. spRed: cc.Node = null;
  24. private data = null
  25. /**
  26. * list_data
  27. * @param data item数据
  28. */
  29. public async setItemData(bData) {
  30. if (!CC_JSB) {
  31. return;
  32. }
  33. this.setInfo(bData.item_data)
  34. }
  35. setInfo(data) {
  36. this.data = data;
  37. cc.loader.load(this.data.icon, (err, res) => {
  38. if (err) {
  39. console.log('err:', err);
  40. return;
  41. }
  42. if (cc.isValid(this.iconNode)) {
  43. let tex: cc.Texture2D = res as cc.Texture2D;
  44. this.iconNode.spriteFrame = new cc.SpriteFrame(tex);
  45. }
  46. })
  47. this.labName.string = this.data.title
  48. this.labDes.string = this.data.introduction
  49. this.spRed.active = false
  50. if (this.data.appType == 1) {
  51. if (JsbSystem.ifCanStartGame(this.data.packageName, false)) {
  52. this.btnDown.active = false
  53. this.btnOpen.active = true
  54. } else {
  55. if (JsbSystem.isFileExist(this.data.nebulaAppId)) {
  56. this.btnDown.active = false
  57. this.btnOpen.active = true
  58. } else {
  59. this.btnDown.active = true
  60. this.btnOpen.active = false
  61. // this.spRed.active = true
  62. let info = gData.moreGame.getTaskInfo(this.data.nebulaAppId)
  63. if (info != null) {
  64. this.schedule(() => {
  65. this.showDownloadProgress()
  66. }, 0.5)
  67. } else {
  68. this.progressLabel.string = "下载"
  69. }
  70. }
  71. }
  72. }
  73. else if (this.data.appType == 2) {
  74. this.btnDown.active = false
  75. this.btnOpen.active = true
  76. }
  77. }
  78. cool = false
  79. creatorDownLoadTask() {
  80. mk.audio.playEffect('button');
  81. if (!CC_JSB) {
  82. return;
  83. }
  84. if (this.cool) {
  85. return
  86. }
  87. mk.data.sendDataEvent(DataEventId.hutuiFunction,"互推格子位下载");
  88. this.cool = true
  89. this.scheduleOnce(() => {
  90. this.cool = false
  91. }, 3)
  92. if (this.data.appType == 1) {
  93. let result = gData.moreGame.createNewTask(this.data)
  94. if (result != null) {
  95. this.schedule(() => {
  96. this.showDownloadProgress()
  97. }, 0.5)
  98. } else {
  99. this.progressLabel.string = ""
  100. }
  101. }
  102. else if (this.data.appType == 2) {
  103. cc.sys.openURL(this.data.recommendLink);
  104. // JsbSystem.sendEvent('hutuiEventLaunch_' + this.data.nebulaAppId, "互推启动" + this.data.title, 'hutuiEventLaunch')
  105. }
  106. }
  107. showDownloadProgress() {
  108. let info = gData.moreGame.getTaskInfo(this.data.nebulaAppId)
  109. if (info != null) {
  110. if (info.progress >= 0) {
  111. // LogUtil.logV("showDownloadProgress", "three")
  112. this.progressLabel.string = ((info.progress / info.totalBytesReceives) * 100).toFixed(1) + "%"
  113. } else {
  114. this.setInfo(this.data)
  115. }
  116. } else {
  117. this.setInfo(this.data)
  118. }
  119. }
  120. }