UIActivityDailyRechargeBTView.lua 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. local UIActivityDailyRechargeBTView = require("UIActivity/UIActivityDailyRechargeBTView_Generate")
  2. local IconItemCtr = require("Common/IconItemCtr")
  3. function UIActivityDailyRechargeBTView:OnAwake(data)
  4. self.controller = require("UIActivity/UIActivityDailyRechargeBTCtr"):new()
  5. self.controller:Init(self)
  6. self.controller:SetData(data)
  7. end
  8. function UIActivityDailyRechargeBTView:AddEventListener()
  9. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Activity_Data_Change,self,self.ActivityRefresh)
  10. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Activity_Day_Change,self,self.ActivityRefresh)
  11. end
  12. function UIActivityDailyRechargeBTView:FillContent(data, uiBase)
  13. self.uiBase = uiBase
  14. local gameObject = self.uiBase:GetRoot()
  15. if gameObject ~= nil then
  16. self.gameObject = gameObject
  17. self.transform = gameObject.transform
  18. end
  19. self:InitGenerate(self.transform, data)
  20. self:Init()
  21. end
  22. function UIActivityDailyRechargeBTView:Init()
  23. local data = self.controller:GetData()
  24. CommonUtil.LoadIcon(self, data.pageBg, function (sprite)
  25. self.bg.image.sprite = sprite
  26. end)
  27. self.controller:InitData()
  28. self.taskListScroll.loopListView:InitListView(0, function(gridView, itemIndex, row, column)
  29. return self:GetItemByRowColumn(gridView, itemIndex, row, column)
  30. end, nil)
  31. self:RefreshRemainTime()
  32. end
  33. function UIActivityDailyRechargeBTView:RemoveEventListener()
  34. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  35. end
  36. function UIActivityDailyRechargeBTView:AddUIEventListener()
  37. self.uiBase:AddButtonEventListener(self.AnyBtn.button,self, self.OnClickCloseBtn)
  38. self.uiBase:AddButtonEventListener(self.backBtn.button,self, self.OnClickCloseBtn)
  39. end
  40. function UIActivityDailyRechargeBTView:OnHide()
  41. end
  42. function UIActivityDailyRechargeBTView:OnShow(data)
  43. self.controller:SetData(data)
  44. end
  45. function UIActivityDailyRechargeBTView:OnClose()
  46. end
  47. function UIActivityDailyRechargeBTView:OnDispose()
  48. self.taskListScroll.loopListView:Dispose()
  49. self:StopRemainTime()
  50. self.controller:OnDispose()
  51. end
  52. function UIActivityDailyRechargeBTView:OnPageInEnd()
  53. self:RefreshShow()
  54. end
  55. function UIActivityDailyRechargeBTView:OnClickCloseBtn()
  56. ManagerContainer.LuaUIMgr:ClosePage(self.uiBase.PageId)
  57. if self.uiBase.MSourceUIID > 0 then
  58. ManagerContainer.LuaUIMgr:Open(self.uiBase.MSourceUIID)
  59. end
  60. end
  61. function UIActivityDailyRechargeBTView:OnClickTaskGoto(btn,param)
  62. local taskData = param[0]
  63. local parentPageId = 0
  64. if ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UIMainCity1) then
  65. parentPageId = Enum.UIPageName.UIMainCity1
  66. elseif ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UIBattle) then
  67. parentPageId = Enum.UIPageName.UIBattle
  68. end
  69. if taskData:CanJump() then
  70. if taskData.gotoPageId > 0 then
  71. if taskData.gotoPageId == Enum.UIPageName.UIDojo2D then
  72. ManagerContainer.DataMgr.ArenaData:SendArenaDataReq(Enum.UIPageName.UIDojo2D, parentPageId)
  73. else
  74. ManagerContainer.LuaUIMgr:Open(taskData.gotoPageId,nil,parentPageId)
  75. end
  76. local uiData = ManagerContainer.CfgMgr:GetUIData(taskData.gotoPageId)
  77. if uiData.type == 0 then
  78. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UIMAINVIEW_CHANGE_NOTICE, uiData.mainViewType)
  79. end
  80. self:UIClose()
  81. end
  82. else
  83. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("DailyTaskText")
  84. end
  85. end
  86. function UIActivityDailyRechargeBTView:OnClickTaskGet(btn,param)
  87. local taskId = param[0]
  88. ManagerContainer.DataMgr.ActsDataMgr:SendGetActivityRewardReq(self.controller:GetActivityActId(),taskId)
  89. end
  90. function UIActivityDailyRechargeBTView:ActivityRefresh(actid)
  91. if self.controller:GetActivityActId() == actid then
  92. self:RefreshShow()
  93. end
  94. end
  95. function UIActivityDailyRechargeBTView:RefreshShow()
  96. local dayTaskList = self.controller:GetDayTaskList()
  97. local length = dayTaskList ~= nil and #dayTaskList or 0
  98. self.taskListScroll.loopListView:SetListItemCount(length, true)
  99. self.taskListScroll.loopListView:RefreshAllShownItem()
  100. self:RefreshRemainTime()
  101. end
  102. function UIActivityDailyRechargeBTView:RefreshRemainTime()
  103. if not self.controller then
  104. self:StopRemainTime()
  105. return
  106. end
  107. local remainTime = self.controller:GetDayRemainTime()
  108. if not self.updateTimer then
  109. self.updateTimer = Timer.New(slot(self.RefreshRemainTime, self), 60, -1)
  110. self.updateTimer.time = remainTime % 60
  111. end
  112. if not self.updateTimer.running then
  113. self.updateTimer:Start()
  114. end
  115. self.leftTimeNode.leftTimeTxt.text.text = DateTimeUtil.convertSeconds2TimeStr1(remainTime, true, false, false)
  116. end
  117. function UIActivityDailyRechargeBTView:StopRemainTime()
  118. if self.updateTimer then
  119. self.updateTimer:Stop()
  120. self.updateTimer = nil
  121. end
  122. end
  123. function UIActivityDailyRechargeBTView:GetItemByRowColumn(gridView, itemIndex, row, column)
  124. local taskData = self.controller:GetDayTaskListDataByIdx(itemIndex + 1)
  125. if not taskData then
  126. return nil
  127. end
  128. local item = gridView:NewListViewItem('TaskItemActivity')
  129. local taskLua = CommonUtil.BindGridViewItem2Lua(self, 'TaskItemActivity', item.gameObject)
  130. taskLua.taskName.text.text = I18N.T(taskData.name)
  131. taskLua.progress.scrollbar.size = taskData.progress and taskData.progress or (taskData.doNum / taskData.finishedNum)
  132. taskLua.doNumTxt.text.text = taskData.doNum .. "/" .. taskData.finishedNum
  133. self:ShowTaskReward(taskLua,taskData:ShowRewards())
  134. self.uiBase:AddButtonUniqueEventListener(taskLua.gotoBtn.button,self, self.OnClickTaskGoto, taskData)
  135. self.uiBase:AddButtonUniqueEventListener(taskLua.getBtn.button,self, self.OnClickTaskGet, taskData.taskId)
  136. if taskData:IsOutofDate() then
  137. if not taskData:IsFinished() then
  138. taskLua.gotoBtn:SetActive(false)
  139. taskLua.getBtn:SetActive(false)
  140. taskLua.sealBtn:SetActive(false)
  141. taskLua.endBtn:SetActive(true)
  142. elseif not taskData:IsGotReward() then
  143. taskLua.gotoBtn:SetActive(false)
  144. taskLua.getBtn:SetActive(true)
  145. taskLua.sealBtn:SetActive(false)
  146. taskLua.endBtn:SetActive(false)
  147. else
  148. taskLua.gotoBtn:SetActive(false)
  149. taskLua.getBtn:SetActive(false)
  150. taskLua.sealBtn:SetActive(true)
  151. taskLua.endBtn:SetActive(false)
  152. end
  153. else
  154. if not taskData:IsFinished() then
  155. taskLua.gotoBtn:SetActive(true)
  156. taskLua.getBtn:SetActive(false)
  157. taskLua.sealBtn:SetActive(false)
  158. taskLua.endBtn:SetActive(false)
  159. elseif not taskData:IsGotReward() then
  160. taskLua.gotoBtn:SetActive(false)
  161. taskLua.getBtn:SetActive(true)
  162. taskLua.sealBtn:SetActive(false)
  163. taskLua.endBtn:SetActive(false)
  164. else
  165. taskLua.gotoBtn:SetActive(false)
  166. taskLua.getBtn:SetActive(false)
  167. taskLua.sealBtn:SetActive(true)
  168. taskLua.endBtn:SetActive(false)
  169. end
  170. end
  171. return item
  172. end
  173. function UIActivityDailyRechargeBTView:ShowTaskReward(taskLua,rewards)
  174. if taskLua.itemList == nil then
  175. taskLua.itemList = {}
  176. taskLua.itemList[#taskLua.itemList+1] = taskLua.iconSmallItem
  177. end
  178. for i = 1, #taskLua.itemList do
  179. taskLua.itemList[i]:SetActive(false)
  180. end
  181. if rewards == nil then
  182. return
  183. end
  184. for i = 1, #rewards do
  185. local itemLua = taskLua.itemList[i]
  186. if itemLua == nil then
  187. local itemGo = UnityEngine.GameObject.Instantiate(taskLua.iconSmallItem.gameObject)
  188. itemLua = CommonUtil.BindGridViewItem2Lua(self, "IconItem", itemGo)
  189. itemLua.prefabName = "IconItem"
  190. itemGo.name = "IconItem"
  191. itemLua.transform:SetParent(taskLua.rewardsNode.transform)
  192. itemLua.transform.localScale = Vector3(1,1,1)
  193. itemLua.rectTransform.anchoredPosition3D = Vector3(0,0,0)
  194. taskLua.itemList[#taskLua.itemList+1] = itemLua
  195. end
  196. local rewardData = {cfgId = rewards[i][1], num = rewards[i][2] }
  197. IconItemCtr:SetData(self, itemLua, rewardData, nil, self, self.OnClickItem)
  198. itemLua:SetActive(true)
  199. end
  200. end
  201. function UIActivityDailyRechargeBTView:OnClickItem(btn,params)
  202. local logicData = params[0]
  203. ManagerContainer.LuaUIMgr:OpenTips(logicData)
  204. end
  205. return UIActivityDailyRechargeBTView