UIActivityChipRewardComView.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. local UIActivityChipRewardComView = require("UIActivity/UIActivityChipRewardComView_Generate")
  2. local IconItemCtr = require("Common/IconItemCtr")
  3. function UIActivityChipRewardComView:OnAwake(data)
  4. self.controller = require("UIActivity/UIActivityChipRewardComCtr"):new()
  5. self.controller:Init(self)
  6. self.controller:SetData(data)
  7. end
  8. function UIActivityChipRewardComView: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.ACTIVITY_GLOBAL_REFRESH,self,self.Refresh)
  12. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.CHIPREWARD_ISNOTICE_CHANHE,self,self.IsNoticeRefresh)
  13. end
  14. function UIActivityChipRewardComView:FillContent(data, uiBase)
  15. self.uiBase = uiBase
  16. local gameObject = self.uiBase:GetRoot()
  17. if gameObject ~= nil then
  18. self.gameObject = gameObject
  19. self.transform = gameObject.transform
  20. end
  21. self:InitGenerate(self.transform, data)
  22. self:Init()
  23. end
  24. function UIActivityChipRewardComView:Init()
  25. self.controller:RefreshChipDatas()
  26. local activeItem = self.controller.activityData
  27. CommonUtil.LoadIcon(self, activeItem.pageBg, function (sprite)
  28. self.banner.image.sprite = sprite
  29. end)
  30. self.isCanSendRedNoticeReq = false
  31. self:InitGrid()
  32. self:Refresh()--true
  33. if not self.timer then
  34. self.timer = FrameTimer.New(slot(self.DelayInitTop, self), 1)
  35. end
  36. if not self.timer.running then
  37. self.timer:Start()
  38. end
  39. end
  40. function UIActivityChipRewardComView:DelayInitTop()
  41. self:InitTop()
  42. end
  43. function UIActivityChipRewardComView:InitTop()
  44. if not self.updateTimer then
  45. self.updateTimer = Timer.New(slot(self.UpdateMinute, self), 60, -1)
  46. end
  47. if not self.updateTimer.running then
  48. self.updateTimer:Start()
  49. end
  50. local canOpen = self:RefreshRemainTime()
  51. if canOpen then
  52. local activeItem = self.controller.activityData
  53. ManagerContainer.DataMgr.ActsDataMgr:SendGetGlobalCollectionServerData(activeItem.actId)
  54. end
  55. end
  56. function UIActivityChipRewardComView:RefreshRemainTime()
  57. local leftTime = self.controller:GetRemainTime()
  58. if leftTime <= 0 then
  59. self.time.text.text = "0"
  60. ManagerContainer.DataMgr.ActsDataMgr:RefreshRedPointState(Enum.ActivityType.ACTIVITY_TYPE_FESTIVAL_REWARD)
  61. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.ACTIVITY_PAGECLOSE)
  62. self:OnClickCloseBtn()
  63. return false
  64. end
  65. local day,hour,minute,second = ConvertTimeForm(leftTime)
  66. local timeStr = ""
  67. if day > 0 then
  68. timeStr = day .. Enum.TimeString.d..hour .. Enum.TimeString.h .. minute .. Enum.TimeString.m
  69. else
  70. if hour > 0 then
  71. timeStr = hour .. Enum.TimeString.h .. minute .. Enum.TimeString.m
  72. else
  73. if minute == 0 then
  74. minute = 1
  75. end
  76. timeStr = minute .. Enum.TimeString.m
  77. end
  78. end
  79. self.time.text.text = timeStr
  80. return true
  81. end
  82. function UIActivityChipRewardComView:UpdateMinute()
  83. self:RefreshRemainTime()
  84. end
  85. function UIActivityChipRewardComView:InitGrid()
  86. self.boxExchange.loopListView:InitListView(0, function(gridView, itemIndex, row, column)
  87. return self:GetItemByRowColumn(gridView, itemIndex, row, column)
  88. end, nil)
  89. end
  90. function UIActivityChipRewardComView:Refresh()
  91. local loopListView = self.boxExchange.loopListView
  92. local length = self.controller:GetChipDataLength()
  93. loopListView:SetListItemCount(length)
  94. loopListView:RefreshAllShownItem()
  95. end
  96. function UIActivityChipRewardComView:ActivityRefresh(actid)
  97. if self.controller:GetActId() == actid then
  98. self:Refresh()
  99. end
  100. end
  101. function UIActivityChipRewardComView:GetItemByRowColumn(gridView, itemIndex, row, column)
  102. local length = self.controller:GetChipDataLength()
  103. if (itemIndex < 0 or itemIndex >= length) then
  104. return nil
  105. end
  106. local showData = self.controller:GetChipShowDataByIdx(itemIndex)
  107. local cfgData = ManagerContainer.CfgMgr:GetActivitiesCollectionCfgById(showData.cfgId)
  108. local item = gridView:NewListViewItem("ExchangeItem")
  109. local itemlua = CommonUtil.BindGridViewItem2Lua(self, "ExchangeItem", item.gameObject)
  110. for i = 1, 4 do
  111. itemlua["coastItem"..(i-1)]:SetActive(false)
  112. end
  113. itemlua.checkmark:SetActive(not showData.isNotice)
  114. itemlua.reward.iconSmallItem2:SetActive(false)
  115. itemlua.serverLimit:SetActive(cfgData.ServersReward > 0)
  116. itemlua.coast.scrollRect.enabled = #cfgData.ExchangeCondition > 4
  117. local globalCount = self.controller:GetGlobalCount(showData.cfgId)
  118. if cfgData.ServersReward > 0 then
  119. local remain = cfgData.ServersReward - globalCount
  120. itemlua.green:SetActive(remain > 0)
  121. itemlua.red:SetActive(remain == 0)
  122. itemlua.number.text.text = remain.."/"..cfgData.ServersReward
  123. end
  124. local globalLack = (globalCount >= cfgData.ServersReward and cfgData.ServersReward > 0)
  125. itemlua.mask:SetActive(showData.rewardNum >= cfgData.Number)
  126. local enough = true
  127. local maxExchangeCount = Mathf.Infinity
  128. for i = 1, #cfgData.ExchangeCondition do
  129. local reward = cfgData.ExchangeCondition[i]
  130. local curNum = CommonUtil.GetOwnResCountByItemId(reward[1])
  131. if curNum < reward[2] then
  132. enough = false
  133. else
  134. local count = math.floor(curNum / reward[2])
  135. if count < maxExchangeCount then
  136. maxExchangeCount = count
  137. end
  138. end
  139. local condata = {cfgId = reward[1], num = reward[2]}
  140. local itemGo = itemlua["coastItem"..(i-1)]
  141. itemGo:SetActive(true)
  142. IconItemCtr:SetData(self,itemGo.iconSmallItem1,condata, Enum.ItemIEnterType.Bag, self, self.OnItemClick)
  143. itemGo.iconSmallItem1.num:SetActive(false)
  144. local curNumStr = curNum < reward[2] and string.format(Constant.RedColorText, curNum) or string.format(Constant.GreenColorText, curNum)
  145. itemlua["text"..i].text.text = curNumStr.."/"..reward[2]
  146. end
  147. local remainTimes = cfgData.Number - showData.rewardNum
  148. if maxExchangeCount > remainTimes then
  149. maxExchangeCount = remainTimes
  150. end
  151. local rewarddata = nil
  152. rewarddata = { cfgId = cfgData.Reward[1][1], num = cfgData.Reward[1][2]}
  153. itemlua.reward.iconSmallItem2:SetActive(true)
  154. itemlua.numberReward.text.text = remainTimes
  155. if rewarddata~= nil then
  156. IconItemCtr:SetData(self, itemlua.reward.iconSmallItem2, rewarddata, Enum.ItemIEnterType.Bag, self, self.OnItemClick)
  157. end
  158. itemlua.uIRedPointRP:SetActive(not showData.isNotice and enough and cfgData.Number > showData.rewardNum and ((globalCount < cfgData.ServersReward and cfgData.ServersReward > 0) or cfgData.ServersReward == 0))
  159. self.uiBase:AddButtonUniqueEventListener(itemlua.button.button, self, self.OnChipClick, itemIndex, enough, globalLack, maxExchangeCount)
  160. self.uiBase:AddButtonUniqueEventListener(itemlua.dscReminder.button, self, self.OnNoticeButtonClick, itemIndex)
  161. return item
  162. end
  163. function UIActivityChipRewardComView:OnNoticeButtonClick(button,param)
  164. local idx = param[0]
  165. if self.isCanSendRedNoticeReq then
  166. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("FrequentOperation")
  167. return
  168. end
  169. local showData = self.controller:GetChipShowDataByIdx(idx)
  170. if showData then
  171. self.isCanSendRedNoticeReq = true
  172. local activity_id = self.controller:GetActId()
  173. local data = {activity_id = activity_id, collect_id = showData.cfgId, no_notice = not showData.isNotice}
  174. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_ACTIVITIES_WORD_NOTICE_SET_REQ,data)
  175. if not self.ReqLimitTimer then
  176. self.ReqLimitTimer = Timer.New(slot(self.ReqLimitUpdate, self), 0.5, -1)
  177. end
  178. if not self.ReqLimitTimer.running then
  179. self.ReqLimitTimer:Start()
  180. end
  181. end
  182. end
  183. function UIActivityChipRewardComView:ReqLimitUpdate()
  184. self.isCanSendRedNoticeReq = false
  185. if self.ReqLimitTimer then
  186. self.ReqLimitTimer:Stop()
  187. end
  188. end
  189. function UIActivityChipRewardComView:IsNoticeRefresh(cfgId)
  190. local showData,idx = self.controller:GetChipShowDataByCfgId(cfgId)
  191. if showData then
  192. local itemLua = self:GetShowItemByIdx(idx - 1)
  193. if itemLua then
  194. local cfgData = ManagerContainer.CfgMgr:GetActivitiesCollectionCfgById(showData.cfgId)
  195. local globalCount = self.controller:GetGlobalCount(showData.cfgId)
  196. local enough = true
  197. for i = 1, #cfgData.ExchangeCondition do
  198. local reward = cfgData.ExchangeCondition[i]
  199. local curNum = CommonUtil.GetOwnResCountByItemId(reward[1])
  200. if curNum < reward[2] then
  201. enough = false
  202. end
  203. end
  204. itemLua.checkmark:SetActive(not showData.isNotice)
  205. itemLua.uIRedPointRP:SetActive(not showData.isNotice and enough and cfgData.Number > showData.rewardNum and ((globalCount < cfgData.ServersReward and cfgData.ServersReward > 0) or cfgData.ServersReward == 0))
  206. end
  207. end
  208. end
  209. function UIActivityChipRewardComView:GetShowItemByIdx(idx)
  210. local item = self.boxExchange.loopListView:GetShownItemByItemIndex(idx)
  211. if item then
  212. local itemlua = CommonUtil.GetBindGridViewItem2Lua(self, "ExchangeItem", item.gameObject)
  213. return itemlua
  214. end
  215. end
  216. function UIActivityChipRewardComView:RemoveEventListener()
  217. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  218. end
  219. function UIActivityChipRewardComView:AddUIEventListener()
  220. self.uiBase:AddButtonEventListener(self.AnyBtn.button,self, self.OnClickCloseBtn)
  221. self.uiBase:AddButtonEventListener(self.backBtn.button,self, self.OnClickCloseBtn)
  222. self.uiBase:AddButtonEventListener(self.btnInfo.button, self, self.OnClickPlayRuleBtn)
  223. end
  224. function UIActivityChipRewardComView:OnClickPlayRuleBtn()
  225. local str = self.controller:GetRuleKey()
  226. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPlayRule, {'PlayExplainTitle', str})
  227. end
  228. function UIActivityChipRewardComView:OnClickCloseBtn()
  229. ManagerContainer.LuaUIMgr:ClosePage(self.uiBase.PageId)
  230. if self.uiBase.MSourceUIID > 0 then
  231. ManagerContainer.LuaUIMgr:Open(self.uiBase.MSourceUIID)
  232. end
  233. end
  234. function UIActivityChipRewardComView:OnChipClick(button, params)
  235. local idx = params[0]
  236. local enough = params[1]
  237. local globalEnough = params[2]
  238. local maxExchangeCount = params[3]
  239. if globalEnough then
  240. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("SetsWordActivity05")
  241. return
  242. end
  243. if not enough then
  244. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("SetsWordActivity01")
  245. return
  246. end
  247. local showData = self.controller:GetChipShowDataByIdx(idx)
  248. local cfgData = ManagerContainer.CfgMgr:GetActivitiesCollectionCfgById(showData.cfgId)
  249. if not cfgData then return end
  250. local data = {cfgId = cfgData.Reward[1][1], count = cfgData.Reward[1][2], maxExchangeCount = maxExchangeCount, idx = idx, owner = self, ownerCB = self.ItemClick1Sure,EnterType = Enum.UIPageName.UIActivityChipRewardCom}
  251. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UITipsExchange, data)
  252. --local data = {"ActivityCollectTip",nil,idx,self,self.ItemClick1Sure}
  253. --ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINoticeTips, data)
  254. end
  255. function UIActivityChipRewardComView:ItemClick1Sure(idx, num)
  256. self.controller:SendGetActivityRewardReq(idx, num)
  257. end
  258. function UIActivityChipRewardComView:OnItemClick(button,params)
  259. local data = params[0]
  260. local data1 = clone(data)
  261. --玉如意单独提示预览时间语言包 暂写死
  262. if data.cfgId == 15024 then
  263. data1.isPreview = true
  264. end
  265. ManagerContainer.LuaUIMgr:OpenTips(data1)
  266. end
  267. function UIActivityChipRewardComView:OnHide()
  268. end
  269. function UIActivityChipRewardComView:OnShow(data)
  270. self.controller:SetData(data)
  271. end
  272. function UIActivityChipRewardComView:OnClose()
  273. ManagerContainer.LuaUIMgr:ClosePage(Enum.UIPageName.UINoticeTips)
  274. if self.timer then
  275. self.timer:Stop()
  276. self.timer = nil
  277. end
  278. if self.updateTimer then
  279. self.updateTimer:Stop()
  280. self.updateTimer = nil
  281. end
  282. if self.ReqLimitTimer then
  283. self.ReqLimitTimer:Stop()
  284. self.ReqLimitTimer = nil
  285. end
  286. end
  287. function UIActivityChipRewardComView:OnDispose()
  288. self.boxExchange.loopListView:Dispose()
  289. self.controller:OnDispose()
  290. end
  291. return UIActivityChipRewardComView