RewardUI.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /** @format */
  2. import {UI} from '../enums/UI'
  3. import {BaseUI} from './BaseUI'
  4. import {Data, Mgr} from '../GameControl'
  5. import {ccUtils} from '../utils/ccUtils'
  6. import {observer, render, node, label, editBox, list} from '../mobx/observer'
  7. import List from '../uiutils/List'
  8. import {idNum} from '../proto/typedef'
  9. import {EVENT} from '../enums/Enum'
  10. import {GoodsConfig} from '../config/GoodsConfig'
  11. import {CenterGridCell} from '../cell/CenterGridCell'
  12. import {IReward, IRewardNty, ItemUICfg} from '../interface/UIInterface'
  13. import {SOUND} from '../enums/Sound'
  14. const {ccclass, property} = cc._decorator
  15. @ccclass
  16. @observer
  17. export class RewardUI extends BaseUI {
  18. @list('goodsList')
  19. goodsList: List
  20. @node('centerGird')
  21. centerGirdNode: cc.Node
  22. @node('bottom_obtain')
  23. bgFrame: cc.Node
  24. @node('streamer_title')
  25. title: cc.Node
  26. @node('quickShow')
  27. quickShow: cc.Node
  28. goods: idNum[] = []
  29. itemUICfgArr: ItemUICfg[]
  30. centerNodes: cc.Node[]
  31. curShowNodes: cc.Node[] //当前界面显示的物品
  32. defaultIntervalTime: number = 0.15 //每个物品显示的间隔时间
  33. curIntervalTime: number = this.defaultIntervalTime //当前每个物品显示的间隔时间
  34. async onShow(args: IReward, fromUI: number) {
  35. this.curIntervalTime = this.defaultIntervalTime
  36. this.quickShow.active = true
  37. Mgr.audio.playSFX(SOUND.reward)
  38. this.goods = args.idNumArr
  39. this.itemUICfgArr = args.itemUICfgArr
  40. let centerGird: CenterGridCell = this.centerGirdNode.getComponent(CenterGridCell)
  41. let showList = this.goods.length > centerGird.getMaxNum()
  42. this.goodsList.node.active = showList
  43. this.centerGirdNode.active = !showList
  44. let nodes: cc.Node[]
  45. this.centerNodes = []
  46. if (showList) {
  47. this.goodsList.numItems = this.goods.length
  48. nodes = this.goodsList.getInsideItem()
  49. } else {
  50. nodes = centerGird.init(this.goods.length)
  51. nodes.forEach((v, index) => {
  52. v['goodsID'] = this.goods[index].id
  53. let itemUICfg: ItemUICfg =
  54. this.itemUICfgArr && this.itemUICfgArr[index] ? this.itemUICfgArr[index] : {showDetails: true}
  55. Mgr.goods.initOneGoods(this.goods[index], cc.find('goods', v), this, itemUICfg)
  56. Mgr.goods.showRectAni(v, v['goodsID'], this)
  57. })
  58. this.centerNodes = nodes
  59. }
  60. this.curShowNodes = nodes
  61. if (nodes[0] && nodes[0].active) {
  62. for (let i = 0; i < nodes.length; i++) {
  63. cc.find('goods', nodes[i]).active = false
  64. cc.find('light_effect_2', nodes[i]).active = false
  65. cc.find('rectAni', nodes[i]).opacity = 0
  66. }
  67. }
  68. let t = cc.tween
  69. this.bgFrame.stopAllActions()
  70. this.bgFrame.scaleY = 0.7
  71. this.title.stopAllActions()
  72. this.title.scale = 1
  73. t(this.bgFrame)
  74. .then(t().to(0.1, {scaleY: 1}))
  75. .start()
  76. t(this.title)
  77. .then(t().to(0.1, {scale: 1.2}).to(0.1, {scale: 1}).union())
  78. .start()
  79. t(this.bgFrame)
  80. for (let i = 0; i < nodes.length; i++) {
  81. let aniNode = cc.find('goods', nodes[i])
  82. let rectAni = cc.find('rectAni', nodes[i])
  83. let lightNode = cc.find('light_effect_2', nodes[i])
  84. aniNode.active = true
  85. lightNode.active = true
  86. aniNode.stopAllActions()
  87. lightNode.stopAllActions()
  88. aniNode.scale = 0
  89. lightNode.width = 0
  90. lightNode.height = 0
  91. lightNode.opacity = 255
  92. await new Promise(resolve => {
  93. setTimeout(resolve, this.curIntervalTime * 1000)
  94. })
  95. t(aniNode)
  96. .then(t().to(0.25, {opacity: 255, scale: 0.9}))
  97. .call(() => {
  98. rectAni.opacity = 255
  99. })
  100. .start()
  101. t(lightNode)
  102. .then(t().to(0.25, {width: 190, height: 190}).to(0.2, {opacity: 0}).union())
  103. .start()
  104. if (i >= nodes.length - 1) {
  105. this.quickShow.active = false
  106. }
  107. }
  108. }
  109. initGoodsItem(node: cc.Node, index: number) {
  110. node['goodsID'] = this.goods[index].id
  111. let itemUICfg: ItemUICfg =
  112. this.itemUICfgArr && this.itemUICfgArr[index] ? this.itemUICfgArr[index] : {showDetails: true}
  113. Mgr.goods.initOneGoods(this.goods[index], cc.find('goods', node), this, itemUICfg)
  114. Mgr.goods.showRectAni(node, node['goodsID'], this)
  115. }
  116. onHide() {
  117. //防止RewardUI被重复打开两次,会执行onHide再执行onShow
  118. if (!this.curShowNodes || !this.goods) return
  119. for (let i = 0; i < this.curShowNodes.length; i++) {
  120. cc.find('goods', this.curShowNodes[i]).active = false
  121. cc.find('light_effect_2', this.curShowNodes[i]).active = false
  122. }
  123. this.goods.forEach(idNum => {
  124. let nodes = this.centerNodes.length > 0 ? this.centerNodes : this.goodsList.content.children
  125. let node = nodes.find(v => v['goodsID'] == idNum.id)
  126. if (!node) return
  127. let starPos = ccUtils.convertToWorldSpaceCanvasAR(node)
  128. let minY = this.goodsList.node.y - this.goodsList.node.height / 2
  129. if (starPos.y < minY) starPos.y = minY
  130. Mgr.goods.flyGoods(idNum.id, starPos, () => {
  131. Mgr.event.trigger(EVENT.goodsChangeSync, idNum.id, idNum.num)
  132. })
  133. })
  134. this.goods.length = 0
  135. if (!Mgr.global.tryOpenNextReadyBox()) Mgr.event.trigger(EVENT.mainPopAnyUI)
  136. }
  137. //第一次快速显示、然后再次点击触发quickClose
  138. quickShowItem(event) {
  139. this.curIntervalTime = 0
  140. this.quickShow.active = false
  141. }
  142. }