UIVipLvUpView.lua 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. local UIVipLvUpView = require("UIVip/UIVipLvUpView_Generate")
  2. function UIVipLvUpView:OnAwake(data)
  3. self.controller = require("UIVip/UIVipLvUpCtr"):new()
  4. self.controller:Init(self)
  5. self.controller:SetData(data)
  6. end
  7. function UIVipLvUpView:AddEventListener()
  8. end
  9. function UIVipLvUpView:FillContent(data, uiBase)
  10. self.uiBase = uiBase
  11. local gameObject = self.uiBase:GetRoot()
  12. if gameObject ~= nil then
  13. self.gameObject = gameObject
  14. self.transform = gameObject.transform
  15. end
  16. self:InitGenerate(self.transform, data)
  17. self:Init()
  18. end
  19. function UIVipLvUpView:Init()
  20. self.gainList.loopListView:InitListView(0, function(loopListView, itemIndex)
  21. return self:GetItemByIndex(loopListView, itemIndex)
  22. end)
  23. self:InitView()
  24. end
  25. function UIVipLvUpView:RemoveEventListener()
  26. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  27. end
  28. function UIVipLvUpView:AddUIEventListener()
  29. self.uiBase:AddButtonUniqueEventListener(self.AnyBtn.button, self, self.OnClickCloseBtn)
  30. end
  31. function UIVipLvUpView:OnHide()
  32. end
  33. function UIVipLvUpView:OnShow(data)
  34. self.controller:SetData(data)
  35. end
  36. function UIVipLvUpView:OnClose()
  37. end
  38. function UIVipLvUpView:OnDispose()
  39. self.canClose = nil
  40. if self.animTimer then
  41. self.animTimer:Stop()
  42. self.animTimer = nil
  43. end
  44. if self.closeTimer then
  45. self.closeTimer:Stop()
  46. self.closeTimer = nil
  47. end
  48. self.gainList.loopListView:Dispose()
  49. self.reward.loopHorizontalScrollRect:ClearCells()
  50. self.controller:OnDispose()
  51. end
  52. function UIVipLvUpView:OnPageInEnd()
  53. self.super.OnPageInEnd(self)
  54. self:StartVipAnim()
  55. end
  56. function UIVipLvUpView:OnClickCloseBtn()
  57. if not self.canClose then return end
  58. local isNext = self.controller:RefreshNextChange()
  59. if not isNext then
  60. self:UIClose()
  61. return
  62. end
  63. self:InitView()
  64. self:StartVipAnim()
  65. end
  66. function UIVipLvUpView:InitView()
  67. self.canClose = false
  68. local lastLv, curLv = self.controller:GetInfo()
  69. local lastVipCfg = ManagerContainer.CfgMgr:GetVipCfgById(lastLv)
  70. local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(curLv)
  71. self:RefreshView(lastVipCfg)
  72. if self.animTimer then
  73. self.animTimer:Stop()
  74. self.animTimer = nil
  75. end
  76. self.animTimer = Timer.New(function()
  77. self:RefreshView(vipCfg)
  78. end, 1)
  79. if self.closeTimer then
  80. self.closeTimer:Stop()
  81. self.closeTimer = nil
  82. end
  83. local duration = GlobalConfig.Instance:GetConfigFloatValue(250)
  84. if duration <= 0 then
  85. duration = 4
  86. end
  87. self.closeTimer = Timer.New(function()
  88. self:StopVipAnim()
  89. end, duration)
  90. self.godSeal.animator:Play('VipKeep', -1, 0)
  91. self.godSeal.animator:Update(0)
  92. self.gainList.loopListView:SetListItemCount(0)
  93. CommonUtil.LoopGridViewEleCreateNew(self, self.reward.loopHorizontalScrollRect, nil, {}, 0, self, self.UpdateRewardItem)
  94. end
  95. function UIVipLvUpView:StartVipAnim()
  96. self.godSeal.animator:Play('VipLevelUp', -1, 0)
  97. self.godSeal.animator:Update(0)
  98. if self.animTimer then
  99. self.animTimer:Start()
  100. end
  101. if self.closeTimer then
  102. self.closeTimer:Start()
  103. end
  104. end
  105. function UIVipLvUpView:StopVipAnim()
  106. self.canClose = true
  107. local _, curLv = self.controller:GetInfo()
  108. local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(curLv)
  109. if not vipCfg then
  110. self.gainList.loopListView:SetListItemCount(0)
  111. CommonUtil.LoopGridViewEleCreateNew(self, self.reward.loopHorizontalScrollRect, nil, {}, 0, self, self.UpdateRewardItem)
  112. return
  113. end
  114. self.gainList.loopListView:SetListItemCount(0)
  115. self.gainList.loopListView:SetListItemCount(vipCfg.UnlockDes and #vipCfg.UnlockDes or 0)
  116. self.gainList.loopListView:RefreshAllShownItem()
  117. CommonUtil.LoopGridViewEleCreateNew(self, self.reward.loopHorizontalScrollRect, nil, vipCfg.Reward and vipCfg.Reward or {}, 0, self, self.UpdateRewardItem)
  118. end
  119. function UIVipLvUpView:RefreshView(vipCfg)
  120. self.vipIcon.image.sprite = nil
  121. self.vipIcon.image.enabled = false
  122. self.vipFrame.image.sprite = nil
  123. self.vipFrame.image.enabled = false
  124. if vipCfg then
  125. self.curVipNameTxt.text.text = string.formatbykey(vipCfg.Name)
  126. CommonUtil.LoadIcon(self, vipCfg.BigIcon, function(sprite)
  127. if sprite then
  128. self.vipIcon.image.sprite = sprite
  129. self.vipIcon.image.enabled = true
  130. end
  131. end)
  132. CommonUtil.LoadIcon(self, vipCfg.BigFrame, function(sprite)
  133. if sprite then
  134. self.vipFrame.image.sprite = sprite
  135. self.vipFrame.image.enabled = true
  136. end
  137. end)
  138. else
  139. self.curVipNameTxt.text.text = ''
  140. end
  141. end
  142. function UIVipLvUpView:GetItemByIndex(loopListView, itemIndex)
  143. local _, vipLv = self.controller:GetInfo()
  144. local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(vipLv)
  145. if not vipCfg then return nil end
  146. if not vipCfg.UnlockDes then return nil end
  147. local unlockDes = vipCfg.UnlockDes[itemIndex + 1]
  148. if not unlockDes then return nil end
  149. local item = loopListView:NewListViewItem('VipUnlockDesItem')
  150. local isNew = unlockDes[1] or 0
  151. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'VipUnlockDesItem', item.gameObject)
  152. if itemLua then
  153. itemLua.exist:SetActive(isNew ~= 1)
  154. itemLua.new:SetActive(isNew == 1)
  155. local params = {}
  156. local langKey = unlockDes[2]
  157. for i = 3, #unlockDes do
  158. params[#params + 1] = tostring(unlockDes[i])
  159. end
  160. itemLua.desTxt.text.text = string.formatbykey(langKey, unpack(params))
  161. end
  162. ManagerContainer.LuaUIMgr:ForceRebuildLayoutImmediate(item.CachedRectTransform)
  163. return item
  164. end
  165. function UIVipLvUpView:RefreshBottomView()
  166. local _, vipLv = self.controller:GetInfo()
  167. local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(vipLv)
  168. if not vipCfg then
  169. self.vipNameTxt.text.text = ''
  170. self.gainList.loopListView:SetListItemCount(0)
  171. CommonUtil.LoopGridViewEleCreateNew(self, self.reward.loopHorizontalScrollRect, nil, {}, 0, self, self.UpdateRewardItem)
  172. return
  173. end
  174. self.vipNameTxt.text.text = string.formatbykey(vipCfg.Name)
  175. self.gainList.loopListView:SetListItemCount(vipCfg.UnlockDes and #vipCfg.UnlockDes or 0)
  176. self.gainList.loopListView:RefreshAllShownItem()
  177. CommonUtil.LoopGridViewEleCreateNew(self, self.reward.loopHorizontalScrollRect, nil, vipCfg.Reward and vipCfg.Reward or {}, 0, self, self.UpdateRewardItem)
  178. end
  179. function UIVipLvUpView:UpdateRewardItem(itemLua, itemIdx, itemData)
  180. if not itemLua or not itemData then return end
  181. CommonUtil.UpdateItemPrefab(self, itemLua.iconItem, {cfgId = itemData[1], num = itemData[2]}, Enum.ItemIEnterType.Bag, self, self.ShowItemTips)
  182. itemLua.check:SetActive(false)
  183. end
  184. function UIVipLvUpView:ShowItemTips(button, params)
  185. ManagerContainer.LuaUIMgr:OpenTips(params[0])
  186. end
  187. return UIVipLvUpView