UIActivityDailyRechargeView.lua 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. local UIActivityDailyRechargeView = require("UIActivity/UIActivityDailyRechargeView_Generate")
  2. local IconItemCtr = require("Common/IconItemCtr")
  3. function UIActivityDailyRechargeView:OnAwake(data)
  4. self.controller = require("UIActivity/UIActivityDailyRechargeCtr"):new()
  5. self.controller:Init(self)
  6. self.controller:SetData(data)
  7. end
  8. function UIActivityDailyRechargeView:AddEventListener()
  9. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  10. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Activity_Data_Change,self,self.ActivityRefresh);
  11. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Activity_Daily_Comulative_Refresh, self, self.Refresh)
  12. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.PAY_DAY_RECHARGE_CHANGED, self, self.Refresh)
  13. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.UI_CLOSE_COMPELETED, self, self.OnUICloseCompleted)
  14. end
  15. function UIActivityDailyRechargeView: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 UIActivityDailyRechargeView:InitGrid()
  26. self.rewards.loopListView:InitListView(0, function(gridView, itemIndex, row, column)
  27. return self:GetRankItemByRowColumn(gridView, itemIndex, row, column)
  28. end, nil)
  29. end
  30. function UIActivityDailyRechargeView:Init()
  31. self:InitGrid()
  32. self:Refresh()
  33. self.lastBtn:SetActive(false)
  34. self.nextBtn:SetActive(false)
  35. end
  36. function UIActivityDailyRechargeView:OnPageInEnd()
  37. self.super.OnPageInEnd(self)
  38. if self.rewardList then
  39. local length = #self.rewardList + 1
  40. self.rewards.scrollRect.enabled = length > 5
  41. end
  42. end
  43. function UIActivityDailyRechargeView:ActivityRefresh(actid)
  44. if self.controller:GetActId() == actid then
  45. self:Refresh()
  46. end
  47. end
  48. function UIActivityDailyRechargeView:Refresh()
  49. local rewardState, curDay = self.controller:GetDailyRewardState()
  50. local displayCfgData = ManagerContainer.CfgMgr:GetNextActivitiesTiredChargeCfgById_New(rewardState, curDay)
  51. local realCfgData = self.controller:GetNextTiredChargeCfgData()
  52. self.rewards:SetActive(displayCfgData ~= nil)
  53. local dailyTiredCount = self.controller:GetDailyTiredChargeCount()
  54. self.text1:SetActive(displayCfgData and rewardState < displayCfgData.Id and dailyTiredCount < displayCfgData.RechargeAmount)
  55. self.text2:SetActive(displayCfgData == nil)
  56. self.text3:SetActive(displayCfgData and rewardState < displayCfgData.Id and dailyTiredCount >= displayCfgData.RechargeAmount)
  57. self.text2.text.text = dailyTiredCount
  58. self.text3.text.text = dailyTiredCount
  59. if displayCfgData then
  60. self.controller.curShowID = displayCfgData.Index
  61. local needChargeCount = self.controller:GetNeedChargeCount()
  62. local count = dailyTiredCount >= displayCfgData.RechargeAmount and displayCfgData.RechargeAmount or needChargeCount
  63. self.text1.text.text = count
  64. if dailyTiredCount >= displayCfgData.RechargeAmount then
  65. self.bottomDsc.uILocalizeScript:SetContentAndValues("DscRecharge01", {dailyTiredCount,displayCfgData.RechargeAmount})
  66. else
  67. self.bottomDsc.uILocalizeScript:SetContentAndValues("DscRecharge02", {dailyTiredCount, count,displayCfgData.RechargeAmount})
  68. end
  69. self:RefreshReward(displayCfgData)
  70. else
  71. self.bottomDsc.uILocalizeScript:SetContentAndValues("DscRecharge01", {dailyTiredCount,displayCfgData.RechargeAmount})
  72. end
  73. self.btnConfirm:SetActive(displayCfgData == nil)
  74. self.btnReceive:SetActive(displayCfgData and rewardState < displayCfgData.Id and dailyTiredCount >= displayCfgData.RechargeAmount)
  75. self.btnRecharge:SetActive(displayCfgData and rewardState < displayCfgData.Id and dailyTiredCount < displayCfgData.RechargeAmount)
  76. self.btnReceive.uIRedPointRP:SetActive(self.controller:GetDailyRPState())
  77. end
  78. function UIActivityDailyRechargeView:RefreshReward(cfgData)
  79. self.rewardList = clone(cfgData.Reward)
  80. --LogError("==================="..Inspect(cfgData))
  81. for i = #self.rewardList, 1, -1 do
  82. local cfgId = self.rewardList[i][1]
  83. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(cfgId)
  84. if itemCfgData.ItemTime > 0 and itemCfgData.ItemTime ~= 5 then
  85. table.remove(self.rewardList, i)
  86. elseif itemCfgData.ItemTime == 5 then
  87. local isIn = self.controller:IsInActivityDrops(cfgId)
  88. if not isIn then
  89. table.remove(self.rewardList, i)
  90. end
  91. end
  92. end
  93. local length = #self.rewardList + 1
  94. self.rewards.loopListView:SetListItemCount(length, true)
  95. self.rewards.loopListView:RefreshAllShownItem()
  96. end
  97. function UIActivityDailyRechargeView:GetRankItemByRowColumn(gridView, itemIndex, row, column)
  98. local item
  99. if itemIndex == 0 then
  100. item = gridView:NewListViewItem('Empty')
  101. else
  102. local reward = self.rewardList[itemIndex]
  103. local cfgId = reward[1]
  104. item = gridView:NewListViewItem('IconItem')
  105. local itemLua = CommonUtil.BindGridViewItem2Lua(self, 'IconItem', item.gameObject)
  106. local data = {cfgId = cfgId, num = reward[2]}
  107. IconItemCtr:SetData(self, itemLua, data, Enum.ItemIEnterType.Bag, self, self.ShowItemClick)
  108. end
  109. item.gameObject.name = itemIndex
  110. return item
  111. end
  112. function UIActivityDailyRechargeView:RemoveEventListener()
  113. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  114. end
  115. function UIActivityDailyRechargeView:AddUIEventListener()
  116. self.uiBase:AddButtonEventListener(self.AnyBtn.button, self, self.OnCloseClick)
  117. self.uiBase:AddButtonEventListener(self.backBtn.button, self, self.OnCloseClick)
  118. self.uiBase:AddButtonEventListener(self.btnConfirm.button, self, self.OnCloseClick)
  119. self.uiBase:AddButtonEventListener(self.btnReceive.button, self, self.OnRewardReceive)
  120. self.uiBase:AddButtonEventListener(self.btnRecharge.button, self, self.OnGotoPay)
  121. self.uiBase:AddButtonEventListener(self.nextBtn.button,self,self.OnNextBtnClick)
  122. self.uiBase:AddButtonEventListener(self.lastBtn.button,self,self.OnLastBtnClick)
  123. end
  124. function UIActivityDailyRechargeView:ShowItemClick(button, params)
  125. local data = params[0]
  126. ManagerContainer.LuaUIMgr:OpenTips(data)
  127. end
  128. function UIActivityDailyRechargeView:OnCloseClick()
  129. ManagerContainer.LuaUIMgr:OpenSourceUI(self)
  130. end
  131. function UIActivityDailyRechargeView:OnRewardReceive()
  132. self.controller:SendRewardReq(self.uiData.id)
  133. end
  134. function UIActivityDailyRechargeView:OnUICloseCompleted(owner)
  135. if owner.uiData.id ~= Enum.UIPageName.UIRuneShopBT then return end
  136. if ManagerContainer.LuaUIMgr:PageInHideStack(self.uiBase) then
  137. ManagerContainer.LuaUIMgr:Show(Enum.UIPageName.UIActivityDailyRecharge)
  138. end
  139. end
  140. function UIActivityDailyRechargeView:OnGotoPay()
  141. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBT, {Enum.RuneShopType.Gifts, Enum.RuneShopSubType.Gold})
  142. ManagerContainer.LuaUIMgr:Hide(Enum.UIPageName.UIActivityDailyRecharge)
  143. end
  144. function UIActivityDailyRechargeView:OnHide()
  145. end
  146. function UIActivityDailyRechargeView:OnShow(data)
  147. self.controller:SetData(data)
  148. end
  149. function UIActivityDailyRechargeView:OnClose()
  150. self.rewards.loopListView:Dispose()
  151. end
  152. function UIActivityDailyRechargeView:OnDispose()
  153. self.controller:OnDispose()
  154. end
  155. function UIActivityDailyRechargeView:OnNextBtnClick()
  156. self:ShowRewards(self.controller:NextShowID())
  157. end
  158. function UIActivityDailyRechargeView:OnLastBtnClick()
  159. self:ShowRewards(self.controller:LastShowID())
  160. end
  161. function UIActivityDailyRechargeView:ShowRewards(id)
  162. local rewardState, curDay = self.controller:GetDailyRewardState()
  163. local displayCfgData = ManagerContainer.CfgMgr:GetActivitiesTiredChargeCfgById_New(id, curDay)
  164. local dailyTiredCount = self.controller:GetDailyTiredChargeCount()
  165. self.text1:SetActive(displayCfgData and rewardState < displayCfgData.Id and dailyTiredCount < displayCfgData.RechargeAmount)
  166. self.text2:SetActive(displayCfgData == nil)
  167. self.text3:SetActive(displayCfgData and rewardState < displayCfgData.Id and dailyTiredCount >= displayCfgData.RechargeAmount)
  168. self.text2.text.text = dailyTiredCount
  169. self.text3.text.text = dailyTiredCount
  170. if displayCfgData then
  171. self.controller.curShowID = displayCfgData.Index
  172. local needChargeCount = displayCfgData.RechargeAmount - dailyTiredCount
  173. local count = dailyTiredCount >= displayCfgData.RechargeAmount and displayCfgData.RechargeAmount or needChargeCount
  174. self.text1.text.text = count
  175. if dailyTiredCount >= displayCfgData.RechargeAmount then
  176. self.bottomDsc.uILocalizeScript:SetContentAndValues("DscRecharge01", {dailyTiredCount,displayCfgData.RechargeAmount})
  177. else
  178. self.bottomDsc.uILocalizeScript:SetContentAndValues("DscRecharge02", {dailyTiredCount, count,displayCfgData.RechargeAmount})
  179. end
  180. self:RefreshReward(displayCfgData)
  181. else
  182. self.bottomDsc.uILocalizeScript:SetContentAndValues("DscRecharge01", {dailyTiredCount,displayCfgData.RechargeAmount})
  183. end
  184. self.btnConfirm:SetActive(displayCfgData == nil)
  185. self.btnReceive:SetActive(displayCfgData and rewardState <= displayCfgData.Index and dailyTiredCount >= displayCfgData.RechargeAmount)
  186. self.btnRecharge:SetActive(displayCfgData and rewardState <= displayCfgData.Index and dailyTiredCount < displayCfgData.RechargeAmount)
  187. self.sealBtn:SetActive(displayCfgData and rewardState > displayCfgData.Index )
  188. end
  189. return UIActivityDailyRechargeView