MoreNormalGameItem.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  7. import MoreGameData from "../datas/MoreGameData";
  8. import AdM from "../manager/AdM";
  9. import GameM, { AUDIO_TYPE } from "../manager/GameM";
  10. import UiM from "../manager/UiM";
  11. import MoreGameNode from "../ui/MoreGameNode";
  12. import LogUtil from "../utils/LogUtil";
  13. import { Utils } from "../utils/Utils";
  14. const { ccclass, property } = cc._decorator;
  15. @ccclass
  16. export default class MoreNormalGameItem extends cc.Component {
  17. @property(cc.Sprite)
  18. iconNode: cc.Sprite = null;
  19. @property(cc.Label)
  20. progressLabel: cc.Label = null;
  21. @property(cc.Node)
  22. btnDown: cc.Node = null;
  23. @property(cc.Node)
  24. btnOpen: cc.Node = null;
  25. @property(cc.Label)
  26. labName: cc.Label = null;
  27. @property(cc.Label)
  28. labDes: cc.Label = null;
  29. @property(cc.Node)
  30. spRed: cc.Node = null;
  31. // LIFE-CYCLE CALLBACKS:
  32. // onLoad () {}
  33. private data = null
  34. start() {
  35. }
  36. setInfo(data) {
  37. this.data = data
  38. if (cc.sys.os == cc.sys.OS_ANDROID) {
  39. cc.loader.load(data.icon, (err, res) => {
  40. if (err) {
  41. console.log('err:', err);
  42. return;
  43. }
  44. if (cc.isValid(this.iconNode)) {
  45. let tex: cc.Texture2D = res as cc.Texture2D;
  46. this.iconNode.spriteFrame = new cc.SpriteFrame(tex);
  47. }
  48. })
  49. }
  50. this.labName.string = data.title
  51. this.labDes.string = data.introduction
  52. this.spRed.active = false
  53. if (AdM.canStartGame(data.packageName, false)) {
  54. this.btnDown.active = false
  55. this.btnOpen.active = true
  56. } else {
  57. if (Utils.checkHasApk(data.nebulaAppId + ".apk") != "") {
  58. this.btnDown.active = false
  59. this.btnOpen.active = true
  60. } else {
  61. this.btnDown.active = true
  62. this.btnOpen.active = false
  63. // this.spRed.active = true
  64. let info = MoreGameData.Instance.getTaskInfo(data.nebulaAppId)
  65. if (info != null) {
  66. this.schedule(() => {
  67. this.showDownloadProgress()
  68. }, 0.5)
  69. } else {
  70. this.progressLabel.string = "下载"
  71. }
  72. }
  73. }
  74. }
  75. // clickPic() {
  76. // GameM.audioM.playEffect(AUDIO_TYPE.button)
  77. // let index = parseInt(this.node.name)
  78. // if (UiM.Instance.moreGameNode) {
  79. // UiM.Instance.moreGameNode.getComponent(MoreGameNode).onOpenBigPicNode(index)
  80. // }
  81. // }
  82. cool = false
  83. creatorDownLoadTask() {
  84. GameM.audioM.playEffect(AUDIO_TYPE.button)
  85. if (this.cool) {
  86. return
  87. }
  88. this.cool = true
  89. this.scheduleOnce(() => {
  90. this.cool = false
  91. }, 3)
  92. let result = MoreGameData.Instance.createNewTask(this.data)
  93. if (result != null) {
  94. this.schedule(() => {
  95. this.showDownloadProgress()
  96. }, 0.5)
  97. } else {
  98. this.progressLabel.string = ""
  99. }
  100. }
  101. showDownloadProgress() {
  102. let info = MoreGameData.Instance.getTaskInfo(this.data.nebulaAppId)
  103. if (info != null) {
  104. if (info.progress >= 0) {
  105. LogUtil.logV("showDownloadProgress", "three")
  106. this.progressLabel.string = ((info.progress / info.totalBytesReceives) * 100).toFixed(1) + "%"
  107. } else {
  108. this.setInfo(this.data)
  109. }
  110. } else {
  111. this.setInfo(this.data)
  112. }
  113. }
  114. update(dt) { }
  115. }