Invest.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /** 投资界面 */
  2. import GameM, { AUDIO_TYPE } from "../manager/GameM";
  3. import InvestItem from "../prefabs/InvestItem";
  4. import AdM from "../manager/AdM";
  5. import UiM, { PANEL_NAME } from "../manager/UiM";
  6. import InvestData from "../datas/InvestData";
  7. import GuideMng from "../manager/GuideMng";
  8. import { Utils } from "../utils/Utils";
  9. const { ccclass, property } = cc._decorator;
  10. @ccclass
  11. export default class Invest extends cc.Component {
  12. @property(cc.Node)
  13. content: cc.Node = null
  14. @property(cc.Label)
  15. labTimes: cc.Label = null
  16. @property(cc.Label)
  17. labCard: cc.Label = null
  18. @property(cc.Node)
  19. qipaoNode: cc.Node = null
  20. @property(cc.Node)
  21. guideRect: cc.Node = null;
  22. investData = null
  23. itemP = null
  24. //分帧加载
  25. addNum = 0
  26. addMax = 0
  27. addTotal = 0
  28. _n = 0
  29. _dis = 2
  30. onLoad() {
  31. }
  32. onEnable() {
  33. AdM.showBanner()
  34. this.guideRect.active = false
  35. // = GuideMng.Ins.CurGuideId == 5;
  36. }
  37. /** 刷新是否看视频 */
  38. freshInvestItem() {
  39. let item
  40. let s
  41. for (var i = 0; i < this.content.children.length; i++) {
  42. item = this.content.getChildByName((i + 1).toString())
  43. s = item.getComponent(InvestItem)
  44. s.freshVideoState()
  45. }
  46. }
  47. /** 刷新显示加速卡还是视频 */
  48. freshInvestSpeedType() {
  49. let item
  50. let s
  51. for (var i = 0; i < this.content.children.length; i++) {
  52. item = this.content.getChildByName((i + 1).toString())
  53. s = item.getComponent(InvestItem)
  54. s.freshSpeedType()
  55. }
  56. }
  57. onDisable() {
  58. AdM.destroyNative()
  59. AdM.destroyBanner()
  60. }
  61. start() {
  62. InvestData.Instance.getInvestInfo()
  63. }
  64. async init(first = true) {
  65. this.investData = InvestData.Instance.investData
  66. let item: cc.Node
  67. let s: InvestItem
  68. if (first) {
  69. this.content.removeAllChildren()
  70. this.itemP = await Utils.loadResPromise('prefabs/InvestItem')
  71. this.addNum = 0
  72. this.addTotal = this.investData.length
  73. //探索 投资引导
  74. this.scheduleOnce(() => {
  75. GuideMng.Ins.CheckInvestGuide5();
  76. }, 0.7)
  77. }
  78. else {
  79. for (var i = 0; i < this.content.childrenCount; i++) {
  80. item = this.content.getChildByName((i + 1).toString())
  81. s = item.getComponent(InvestItem)
  82. let index = s.data.index
  83. s.init(this.getDataByIndex(this.investData, index))
  84. }
  85. }
  86. this.updateTimes()
  87. }
  88. update() {
  89. if (this.addNum < this.addTotal) {
  90. if (this._n <= this._dis) {
  91. this._n++
  92. }
  93. else {
  94. this._n = 0
  95. let item: cc.Node = cc.instantiate(this.itemP)
  96. let s = item.getComponent(InvestItem)
  97. item.name = this.investData[this.addNum].index.toString()
  98. s.init(this.investData[this.addNum])
  99. this.content.addChild(item)
  100. this.addNum++
  101. }
  102. }
  103. }
  104. getDataByIndex(data, index) {
  105. for (let entry of data) {
  106. if (index == entry.index) {
  107. return entry
  108. }
  109. }
  110. }
  111. onGetGold(index) {
  112. let item = this.content.getChildByName(index.toString())
  113. let s = item.getComponent(InvestItem)
  114. s.getGold()
  115. }
  116. updateTimes() {
  117. let leftCount = InvestData.Instance.SurplusTimes
  118. if (leftCount < 0) {
  119. leftCount = 0
  120. }
  121. this.labTimes.string = leftCount + ""
  122. this.labCard.string = GameM.commonData.roleData.speedCard + ""
  123. }
  124. clickClose() {
  125. GameM.audioM.playEffect(AUDIO_TYPE.button)
  126. UiM.Instance.offPanel(PANEL_NAME.InvestNode, false, () => {
  127. AdM.createInter(5)
  128. })
  129. }
  130. clickIconShowTip() {
  131. this.qipaoNode.active = true
  132. this.scheduleOnce(() => {
  133. if (cc.isValid(this.qipaoNode)) {
  134. this.qipaoNode.active = false
  135. }
  136. }, 2)
  137. }
  138. Click_GuideRectBtn() {
  139. this.guideRect.active = false;
  140. }
  141. }