UIBattleBossBoxView.lua 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. local UIBattleBossBoxView = require("UIBattle/UIBattleBossBoxView_Generate")
  2. local DOTween = DG.Tweening.DOTween
  3. local BoxState = {
  4. NotOpen = 1,
  5. Opening = 2,
  6. Opened = 3,
  7. }
  8. function UIBattleBossBoxView:OnAwake(data)
  9. self.controller = require("UIBattle/UIBattleBossBoxCtr"):new()
  10. self.controller:Init(self)
  11. self.controller:SetData(data)
  12. end
  13. function UIBattleBossBoxView:AddEventListener()
  14. end
  15. function UIBattleBossBoxView:FillContent(data, uiBase)
  16. self.uiBase = uiBase
  17. local gameObject = self.uiBase:GetRoot()
  18. if gameObject ~= nil then
  19. self.gameObject = gameObject
  20. self.transform = gameObject.transform
  21. end
  22. self:InitGenerate(self.transform, data)
  23. self:Init()
  24. end
  25. function UIBattleBossBoxView:Init()
  26. self.boxState = BoxState.NotOpen
  27. self.boxAnim.animator:Play('BossBoxIn')
  28. local rewardItemList = nil
  29. if not rewardItemList then
  30. rewardItemList = ManagerContainer.LuaBattleMgr.rewardItemList
  31. end
  32. if rewardItemList == nil then
  33. LogError('[Wboy] not find rewards, config is error !!!')
  34. end
  35. local idx = 1
  36. local max = Mathf.Min(#rewardItemList, 10)
  37. for i = 1, max do
  38. local keyValue = rewardItemList[i]
  39. local pot = self['pot' .. idx]
  40. if pot then
  41. pot:SetActive(true)
  42. pot.fly:SetActive(false)
  43. CommonUtil.SetRewardItemData(self, keyValue.key, pot.fly.iconItem, keyValue.value, self.OnClickItem)
  44. end
  45. idx = idx + 1
  46. end
  47. self.vaildIdx = idx - 1
  48. local pot = self['pot' .. idx]
  49. while pot do
  50. pot:SetActive(false)
  51. idx = idx + 1
  52. pot = self['pot' .. idx]
  53. end
  54. end
  55. function UIBattleBossBoxView:RemoveEventListener()
  56. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  57. end
  58. function UIBattleBossBoxView:AddUIEventListener()
  59. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  60. self.uiBase:AddButtonUniqueEventListener(self.AnyBtn.button, self, self.OnClickBtnAlpha)
  61. end
  62. function UIBattleBossBoxView:OnHide()
  63. end
  64. function UIBattleBossBoxView:OnShow(data)
  65. self.controller:SetData(data)
  66. end
  67. function UIBattleBossBoxView:OnClose()
  68. -- 提前移除特效,缩放的时候,特效并未缩放
  69. if self.fxGoes ~= nil then
  70. for i =1, #self.fxGoes do
  71. ManagerContainer.ResMgr:RecycleGO(Constants.EffectPath,self.fxGoes[i].name,self.fxGoes[i].go)
  72. end
  73. end
  74. self.fxGoes = nil
  75. end
  76. function UIBattleBossBoxView:OnDispose()
  77. local seq = self.doTweenSequence
  78. if seq then
  79. seq:Kill()
  80. seq = nil
  81. end
  82. self.controller:OnDispose()
  83. end
  84. function UIBattleBossBoxView:OnPageOutEnd()
  85. LogError("==========OnPageOutEnd========")
  86. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.BIGMAP_ENTER_NEXTMAP_START)
  87. self.super.OnPageOutEnd(self)
  88. end
  89. function UIBattleBossBoxView:OnClickItem(btn,params)
  90. local logicData = params[0]
  91. local item = {cfgId = logicData.cfgId};
  92. --ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIItemTips, item)
  93. ManagerContainer.LuaUIMgr:OpenTips(item)
  94. end
  95. function UIBattleBossBoxView:OnClickBtnAlpha()
  96. if self.boxState == BoxState.Opened then
  97. self:UIClose(self)
  98. elseif self.boxState == BoxState.NotOpen then
  99. self.boxState = BoxState.Opening
  100. self:OpenBox()
  101. end
  102. end
  103. function UIBattleBossBoxView:OpenBox()
  104. self.boxAnim.animator:Play('BossBoxOpen')
  105. local seq = self.doTweenSequence
  106. if seq then
  107. seq:Kill()
  108. seq = nil
  109. end
  110. seq = DOTween.Sequence()
  111. self.doTweenSequence = seq
  112. local startPos = self.boxAnim.transform.position
  113. local flyAnim = 0.1
  114. local delay = 1
  115. local idx = 1
  116. local pot = self['pot' .. idx]
  117. while pot do
  118. if idx > self.vaildIdx then
  119. break
  120. end
  121. seq:AppendInterval(delay)
  122. local fly = pot.fly
  123. seq:AppendCallback(function()
  124. fly:SetActive(true)
  125. fly.transform.position = startPos
  126. fly.animation:Play('ItemIcon')
  127. end)
  128. seq:Append(fly.transform:DOLocalMove(Vector3.zero, flyAnim))
  129. delay = flyAnim
  130. idx = idx + 1
  131. pot = self['pot' .. idx]
  132. end
  133. seq:AppendCallback(function()
  134. self.boxState = BoxState.Opened
  135. end)
  136. seq:AppendInterval(3)
  137. seq:AppendCallback(function()
  138. self:UIClose()
  139. end)
  140. end
  141. return UIBattleBossBoxView