UINotifyActivityTipsView.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. local UINotifyActivityTipsView = require("UINotifyTips/UINotifyActivityTipsView_Generate")
  2. local NotifyItemCtr = require("Common/NotifyItemCtr")
  3. local TaskJumpCtr = require("Common/TaskJumpCtr")
  4. function UINotifyActivityTipsView:OnAwake(data)
  5. self.controller = require("UINotifyTips/UINotifyActivityTipsCtr"):new()
  6. self.controller:Init(self)
  7. self.controller:SetData(data)
  8. end
  9. function UINotifyActivityTipsView:AddEventListener()
  10. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Open_Activity_Refresh,self,self.OnRefreshActivity);
  11. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Show_Notices,self,self.OnShowNotices);
  12. end
  13. function UINotifyActivityTipsView:FillContent(data, uiBase)
  14. self.uiBase = uiBase
  15. local gameObject = self.uiBase:GetRoot()
  16. if gameObject ~= nil then
  17. self.gameObject = gameObject
  18. self.transform = gameObject.transform
  19. end
  20. self:InitGenerate(self.transform, data)
  21. self:Init()
  22. end
  23. function UINotifyActivityTipsView:Init()
  24. self.notices = {}
  25. self.lastShowNotifyData = nil
  26. self.lastShowItem = nil
  27. self.currentSelectedType = 1
  28. self.toggleActivity.toggle.isOn = true
  29. end
  30. function UINotifyActivityTipsView:OnPageInEnd()
  31. self.super.OnPageInEnd(self)
  32. if not self.timer then
  33. self.timer = Timer.New(function ()
  34. self:ShowActivityItems()
  35. end, 0.1)
  36. self.timer:Start()
  37. end
  38. end
  39. function UINotifyActivityTipsView:RemoveEventListener()
  40. ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
  41. end
  42. function UINotifyActivityTipsView:AddUIEventListener()
  43. ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
  44. self.uiBase:AddButtonEventListener(self.BtnClose.button,self, self.OnBtnCloseClick);
  45. self.uiBase:AddButtonEventListener(self.AnyBtn.button,self, self.OnBtnCloseClick);
  46. self.uiBase:AddToggleEventListener(self.toggleActivity.toggle,self, self.OnPageToggleClick,1)
  47. self.uiBase:AddToggleEventListener(self.toggleNotify.toggle,self, self.OnPageToggleClick,2)
  48. end
  49. function UINotifyActivityTipsView:OnHide()
  50. end
  51. function UINotifyActivityTipsView:OnShow(data)
  52. self.controller:SetData(data)
  53. self:Init()
  54. end
  55. function UINotifyActivityTipsView:OnClose()
  56. self:ClearUpdateActivityTimer()
  57. self.activityScrollList.loopVerticalScrollRect:ClearCells()
  58. if self.timer and self.timer.running then
  59. self.timer:Stop()
  60. end
  61. self.notices = nil
  62. end
  63. function UINotifyActivityTipsView:OnDispose()
  64. end
  65. function UINotifyActivityTipsView:OpenPageByTab(idx)
  66. if idx == 1 then
  67. self:ShowActivityItems()
  68. elseif idx == 2 then
  69. self.notices = {}
  70. self.notifyScrollList.loopVerticalScrollRect:ClearCells()
  71. self:ClearUpdateActivityTimer()
  72. self:ShowNotifyItems()
  73. end
  74. end
  75. function UINotifyActivityTipsView:OnRefreshActivity()
  76. if self.currentSelectedType == 1 then
  77. --LogError("add by raul------currentSelectedType == 1---OnRefreshActivity-------")
  78. self:ShowActivityItems()
  79. end
  80. end
  81. function UINotifyActivityTipsView:ShowActivityItems()
  82. self.notifyScrollList:SetActive(false)
  83. local actItems = ManagerContainer.DataMgr.ActsDataMgr:GetActivityItemsByPageId(Enum.UIPageName.UINotifyActivityTips)
  84. --LogError("add by raul:UINotifyActivityTipsView:ShowActivityItems->#actItems 's number"..#actItems.."---is total actItems Activity Number")
  85. --LogError("add by raul:UINotifyActivityTipsView:ShowActivityItems->actItems".. Inspect(actItems))
  86. if actItems == nil or #actItems == 0 then
  87. self.actEmptyNode:SetActive(true)
  88. self.activityScrollList:SetActive(false)
  89. return
  90. end
  91. self:ClearUpdateActivityTimer()
  92. local existLimitedAct = false
  93. for i = 1, #actItems do
  94. if actItems[i]:IsLimited() then
  95. existLimitedAct = true
  96. --LogError(#actItems.."add by raul---is -total banner Activity Number(---:UINotifyActivityTipsView:ShowActivityItems())")
  97. break
  98. end
  99. end
  100. if existLimitedAct then
  101. self.udpateActTimer = ManagerContainer.LuaTimerMgr:AddTimer(60000, 1,self,self.UpdateActivityTime,nil);
  102. end
  103. self.actEmptyNode:SetActive(false)
  104. self.activityScrollList:SetActive(true)
  105. CommonUtil.LoopGridViewEleCreateNew(self,
  106. self.activityScrollList.loopVerticalScrollRect,
  107. self.activityScrollList.content.verticalLayoutGroup,
  108. actItems,
  109. 0,
  110. self, self.SetActivityItem);
  111. end
  112. function UINotifyActivityTipsView:UpdateActivityTime()
  113. self:ShowActivityItems()
  114. end
  115. function UINotifyActivityTipsView:ClearUpdateActivityTimer()
  116. if self.udpateActTimer~= nil then
  117. ManagerContainer.LuaTimerMgr:RemoveTimer(self.udpateActTimer)
  118. self.udpateActTimer = nil
  119. end
  120. end
  121. function UINotifyActivityTipsView:SetActivityItem(itemLua,idx,itemData)
  122. itemLua.limitedLblNode:SetActive(itemData:IsLimited())
  123. itemLua.limitedNode:SetActive(itemData:IsLimited())
  124. if itemData:IsLimited() then
  125. local day,hour,minute = ConvertTimeForm(itemData:LeftTime())
  126. itemLua.leftDay.text.text = tostring(day)
  127. itemLua.leftHours.text.text = tostring(hour)
  128. itemLua.leftMins.text.text = tostring(minute)
  129. end
  130. if itemData:GetBg() ~= nil then
  131. CommonUtil.LoadIcon(self, itemData:GetBg(), function (sprite)
  132. itemLua.bannerImg.image.sprite = sprite
  133. end, itemLua, 'ActivityBGIdx')
  134. else
  135. itemLua.bannerImg.image.sprite = nil
  136. end
  137. itemLua.redPoint:SetActive(itemData:HasRedPoint())
  138. if itemData.pageId ~= nil then
  139. self.uiBase:AddButtonUniqueEventListener(itemLua.bannerImg.button, self, self.OnClickOpenActivityPage, itemData.pageId,itemData.pageBg, itemData.actId,itemData.type)
  140. end
  141. end
  142. function UINotifyActivityTipsView:OnClickOpenActivityPage(btn,paramList)
  143. local pageId = paramList[0]
  144. local pageBg = paramList[1]
  145. local actId = paramList[2]
  146. local Jumptype = paramList[3]
  147. local data = {pageBg = pageBg, actId = actId}
  148. --type == 0 任务跳转 有解锁条件判断
  149. local bIsJump = false
  150. if Jumptype == 0 then
  151. bIsJump = TaskJumpCtr:JumpBuyCfgId(pageId)
  152. else
  153. bIsJump = true
  154. ManagerContainer.LuaUIMgr:Open(pageId,data,Enum.UIPageName.UINotifyActivityTips)
  155. end
  156. if bIsJump then
  157. self:OnBtnCloseClick()
  158. end
  159. --LogError("add by raul OnClickOpenActivityPage "..Inspect(getmetatable(paramList)))
  160. --LogError("add by raul OnClickOpenActivityPage:actId"..actId)
  161. end
  162. function UINotifyActivityTipsView:ShowNotifyItems()
  163. self.actEmptyNode:SetActive(false)
  164. self.activityScrollList:SetActive(false)
  165. self.notifyScrollList:SetActive(true)
  166. --LogError(tostring(ManagerContainer.LuaGameMgr.serverData.id))
  167. --local url = PlatformPack.NOTIFY_URL .. "?serverid=" .. ManagerContainer.LuaGameMgr.serverData.id
  168. --url = url .. '&timesamp=' .. tostring(os.time())
  169. --local platform = ManagerContainer.LuaGameMgr.platform
  170. --if platform and platform ~= '' then
  171. -- url = url .. '&platform=' .. tostring(platform)
  172. --end
  173. --local subplatform = ManagerContainer.LuaGameMgr.channelName
  174. --if subplatform and subplatform ~= '' then
  175. -- url = url .. '&sub_platform=' .. tostring(subplatform)
  176. --end
  177. local url = PlatformPack.NOTIFY_URL .. "Notice"
  178. --local serverId = ManagerContainer.LuaGameMgr.serverData.id
  179. -- if serverId and serverId > 0 then
  180. -- url = url.. "_"..serverId
  181. -- end
  182. url = url.."_List.json"
  183. --LogError(ManagerContainer.LuaGameMgr.serverData.id)
  184. local OnRequestHttpCb = function(noticeInfo)
  185. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Show_Notices,noticeInfo)
  186. end
  187. ManagerContainer.LuaGameMgr:RequestHttpServer(url,OnRequestHttpCb)
  188. end
  189. function UINotifyActivityTipsView:OnShowNotices(noticeInfo)
  190. if not self.notices then return end
  191. local noticesJson
  192. local ok, errors = RO_XPCALL(function() noticesJson = JSON:decode(noticeInfo) end, debug.traceback)
  193. if ok then
  194. for k,p in pairs(noticesJson) do
  195. self:AddNotices(p)
  196. end
  197. --self:AddNotices(noticesJson)
  198. else
  199. local notice = {}
  200. notice.NoticeTitle = "";
  201. notice.LimitedTimeLabel = "";
  202. notice.NoticeBeginTime = "";
  203. notice.NoticeEndTime = "";
  204. notice.NoticeTxt = string.formatbykey("NoticeAnomaly");
  205. notice._showing = true
  206. self.notices[#self.notices+1] = notice
  207. LogError("[Notice].."..errors)
  208. end
  209. self:SetListData()
  210. end
  211. function UINotifyActivityTipsView:ParseNotice(noticeJson)
  212. if noticeJson == nil then
  213. return nil
  214. end
  215. local notice = {};
  216. notice.NoticeTitle = noticeJson.title;
  217. notice.LimitedTimeLabel = noticeJson.timeLabel;
  218. notice.NoticeBeginTime = noticeJson.beginTime;
  219. notice.NoticeEndTime = noticeJson.endTime;
  220. notice.NoticeTxt = noticeJson.text;
  221. notice.top = noticeJson.top
  222. if noticeJson.top == 1 then
  223. notice._showing = true
  224. end
  225. return notice
  226. end
  227. function UINotifyActivityTipsView:AddNotices(noticesJson)
  228. local notice = self:ParseNotice(noticesJson)
  229. if notice ~= nil then
  230. if notice.top == 1 then
  231. table.insert(self.notices, 1, notice)
  232. else
  233. self.notices[#self.notices + 1] = notice
  234. end
  235. end
  236. end
  237. function UINotifyActivityTipsView:SetListData()
  238. if self.notices ~= nil and #self.notices > 0 then
  239. --self.notices[1]._showing = true
  240. CommonUtil.LoopGridViewEleCreateNew(self,
  241. self.notifyScrollList.loopVerticalScrollRect,
  242. self.notifyScrollList.content.verticalLayoutGroup,
  243. self.notices,
  244. 0,
  245. self, self.SetNoticeItem);
  246. self.notifyScrollList.loopVerticalScrollRect.velocity = Vector2.zero;
  247. local _position = self.notifyScrollList.content.transform.localPosition;
  248. _position.y = 0;
  249. self.notifyScrollList.content.transform.localPosition = _position;
  250. end
  251. end
  252. function UINotifyActivityTipsView:SetNoticeItem(itemLua, idx,itemData)
  253. if itemData._showing then
  254. self.lastShowItem = itemLua
  255. self.lastShowNotifyData = itemData
  256. end
  257. NotifyItemCtr:SetData(self, itemLua, itemData, self.OnOpenNoticeCallback,self.OnHideNoticeCallback);
  258. end
  259. function UINotifyActivityTipsView:OnOpenNoticeCallback(_item,itemData)
  260. local hideTitle = ""
  261. if self.lastShowNotifyData ~= nil then
  262. self.lastShowNotifyData._showing = false;
  263. hideTitle = self.lastShowNotifyData.NoticeTitle
  264. end
  265. self.lastShowNotifyData = itemData
  266. local oldItem = self.lastShowItem
  267. self.lastShowItem = _item
  268. return oldItem,hideTitle;
  269. end
  270. function UINotifyActivityTipsView:OnHideNoticeCallback(itemData)
  271. self.lastShowItem = nil
  272. end
  273. function UINotifyActivityTipsView:OnBtnCloseClick()
  274. self:UIClose()
  275. end
  276. --Toggle事件,_params是1代表的是精彩活动,是2代表的是游戏公告
  277. function UINotifyActivityTipsView:OnPageToggleClick(_toggle, _params)
  278. if _toggle.isOn then
  279. if self.currentSelectedType == _params then
  280. return
  281. end
  282. self.currentSelectedType = _params
  283. self:OpenPageByTab(self.currentSelectedType)
  284. --LogError(self.currentSelectedType.."add by raul---page1--精彩活动---page2--游戏公告")
  285. end
  286. end
  287. return UINotifyActivityTipsView