| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345 |
- local UINotifyActivityTipsView = require("UINotifyTips/UINotifyActivityTipsView_Generate")
- local NotifyItemCtr = require("Common/NotifyItemCtr")
- local TaskJumpCtr = require("Common/TaskJumpCtr")
- function UINotifyActivityTipsView:OnAwake(data)
- self.controller = require("UINotifyTips/UINotifyActivityTipsCtr"):new()
- self.controller:Init(self)
- self.controller:SetData(data)
- end
- function UINotifyActivityTipsView:AddEventListener()
- ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Open_Activity_Refresh,self,self.OnRefreshActivity);
- ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name, UIEventNames.EID_Show_Notices,self,self.OnShowNotices);
- end
- function UINotifyActivityTipsView:FillContent(data, uiBase)
- self.uiBase = uiBase
- local gameObject = self.uiBase:GetRoot()
- if gameObject ~= nil then
- self.gameObject = gameObject
- self.transform = gameObject.transform
- end
- self:InitGenerate(self.transform, data)
- self:Init()
- end
- function UINotifyActivityTipsView:Init()
- self.notices = {}
- self.lastShowNotifyData = nil
- self.lastShowItem = nil
- self.currentSelectedType = 1
- self.toggleActivity.toggle.isOn = true
- end
- function UINotifyActivityTipsView:OnPageInEnd()
- self.super.OnPageInEnd(self)
- if not self.timer then
- self.timer = Timer.New(function ()
- self:ShowActivityItems()
- end, 0.1)
- self.timer:Start()
- end
- end
- function UINotifyActivityTipsView:RemoveEventListener()
- ManagerContainer.LuaEventMgr:Unregister(self.uiData.name)
- end
- function UINotifyActivityTipsView:AddUIEventListener()
- ManagerContainer.LuaEventMgr:RegisterUIEvent(self.uiData.name)
- self.uiBase:AddButtonEventListener(self.BtnClose.button,self, self.OnBtnCloseClick);
- self.uiBase:AddButtonEventListener(self.AnyBtn.button,self, self.OnBtnCloseClick);
- self.uiBase:AddToggleEventListener(self.toggleActivity.toggle,self, self.OnPageToggleClick,1)
- self.uiBase:AddToggleEventListener(self.toggleNotify.toggle,self, self.OnPageToggleClick,2)
- end
- function UINotifyActivityTipsView:OnHide()
- end
- function UINotifyActivityTipsView:OnShow(data)
- self.controller:SetData(data)
- self:Init()
- end
- function UINotifyActivityTipsView:OnClose()
- self:ClearUpdateActivityTimer()
- self.activityScrollList.loopVerticalScrollRect:ClearCells()
- if self.timer and self.timer.running then
- self.timer:Stop()
- end
- self.notices = nil
- end
- function UINotifyActivityTipsView:OnDispose()
- end
- function UINotifyActivityTipsView:OpenPageByTab(idx)
- if idx == 1 then
- self:ShowActivityItems()
- elseif idx == 2 then
- self.notices = {}
- self.notifyScrollList.loopVerticalScrollRect:ClearCells()
- self:ClearUpdateActivityTimer()
- self:ShowNotifyItems()
- end
- end
- function UINotifyActivityTipsView:OnRefreshActivity()
- if self.currentSelectedType == 1 then
- --LogError("add by raul------currentSelectedType == 1---OnRefreshActivity-------")
- self:ShowActivityItems()
- end
- end
- function UINotifyActivityTipsView:ShowActivityItems()
- self.notifyScrollList:SetActive(false)
-
- local actItems = ManagerContainer.DataMgr.ActsDataMgr:GetActivityItemsByPageId(Enum.UIPageName.UINotifyActivityTips)
- --LogError("add by raul:UINotifyActivityTipsView:ShowActivityItems->#actItems 's number"..#actItems.."---is total actItems Activity Number")
- --LogError("add by raul:UINotifyActivityTipsView:ShowActivityItems->actItems".. Inspect(actItems))
- if actItems == nil or #actItems == 0 then
- self.actEmptyNode:SetActive(true)
- self.activityScrollList:SetActive(false)
- return
- end
- self:ClearUpdateActivityTimer()
- local existLimitedAct = false
- for i = 1, #actItems do
- if actItems[i]:IsLimited() then
- existLimitedAct = true
- --LogError(#actItems.."add by raul---is -total banner Activity Number(---:UINotifyActivityTipsView:ShowActivityItems())")
- break
- end
- end
- if existLimitedAct then
- self.udpateActTimer = ManagerContainer.LuaTimerMgr:AddTimer(60000, 1,self,self.UpdateActivityTime,nil);
- end
- self.actEmptyNode:SetActive(false)
- self.activityScrollList:SetActive(true)
- CommonUtil.LoopGridViewEleCreateNew(self,
- self.activityScrollList.loopVerticalScrollRect,
- self.activityScrollList.content.verticalLayoutGroup,
- actItems,
- 0,
- self, self.SetActivityItem);
- end
- function UINotifyActivityTipsView:UpdateActivityTime()
- self:ShowActivityItems()
- end
- function UINotifyActivityTipsView:ClearUpdateActivityTimer()
- if self.udpateActTimer~= nil then
- ManagerContainer.LuaTimerMgr:RemoveTimer(self.udpateActTimer)
- self.udpateActTimer = nil
- end
- end
- function UINotifyActivityTipsView:SetActivityItem(itemLua,idx,itemData)
- itemLua.limitedLblNode:SetActive(itemData:IsLimited())
- itemLua.limitedNode:SetActive(itemData:IsLimited())
- if itemData:IsLimited() then
- local day,hour,minute = ConvertTimeForm(itemData:LeftTime())
- itemLua.leftDay.text.text = tostring(day)
- itemLua.leftHours.text.text = tostring(hour)
- itemLua.leftMins.text.text = tostring(minute)
- end
- if itemData:GetBg() ~= nil then
- CommonUtil.LoadIcon(self, itemData:GetBg(), function (sprite)
- itemLua.bannerImg.image.sprite = sprite
- end, itemLua, 'ActivityBGIdx')
- else
- itemLua.bannerImg.image.sprite = nil
- end
- itemLua.redPoint:SetActive(itemData:HasRedPoint())
- if itemData.pageId ~= nil then
- self.uiBase:AddButtonUniqueEventListener(itemLua.bannerImg.button, self, self.OnClickOpenActivityPage, itemData.pageId,itemData.pageBg, itemData.actId,itemData.type)
- end
- end
- function UINotifyActivityTipsView:OnClickOpenActivityPage(btn,paramList)
- local pageId = paramList[0]
- local pageBg = paramList[1]
- local actId = paramList[2]
- local Jumptype = paramList[3]
- local data = {pageBg = pageBg, actId = actId}
- --type == 0 任务跳转 有解锁条件判断
- local bIsJump = false
- if Jumptype == 0 then
- bIsJump = TaskJumpCtr:JumpBuyCfgId(pageId)
- else
- bIsJump = true
- ManagerContainer.LuaUIMgr:Open(pageId,data,Enum.UIPageName.UINotifyActivityTips)
- end
-
- if bIsJump then
- self:OnBtnCloseClick()
- end
- --LogError("add by raul OnClickOpenActivityPage "..Inspect(getmetatable(paramList)))
- --LogError("add by raul OnClickOpenActivityPage:actId"..actId)
- end
- function UINotifyActivityTipsView:ShowNotifyItems()
- self.actEmptyNode:SetActive(false)
- self.activityScrollList:SetActive(false)
- self.notifyScrollList:SetActive(true)
- --LogError(tostring(ManagerContainer.LuaGameMgr.serverData.id))
- --local url = PlatformPack.NOTIFY_URL .. "?serverid=" .. ManagerContainer.LuaGameMgr.serverData.id
- --url = url .. '×amp=' .. tostring(os.time())
- --local platform = ManagerContainer.LuaGameMgr.platform
- --if platform and platform ~= '' then
- -- url = url .. '&platform=' .. tostring(platform)
- --end
- --local subplatform = ManagerContainer.LuaGameMgr.channelName
- --if subplatform and subplatform ~= '' then
- -- url = url .. '&sub_platform=' .. tostring(subplatform)
- --end
- local url = PlatformPack.NOTIFY_URL .. "Notice"
- --local serverId = ManagerContainer.LuaGameMgr.serverData.id
- -- if serverId and serverId > 0 then
- -- url = url.. "_"..serverId
- -- end
- url = url.."_List.json"
- --LogError(ManagerContainer.LuaGameMgr.serverData.id)
- local OnRequestHttpCb = function(noticeInfo)
- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Show_Notices,noticeInfo)
- end
- ManagerContainer.LuaGameMgr:RequestHttpServer(url,OnRequestHttpCb)
-
-
- end
- function UINotifyActivityTipsView:OnShowNotices(noticeInfo)
- if not self.notices then return end
- local noticesJson
- local ok, errors = RO_XPCALL(function() noticesJson = JSON:decode(noticeInfo) end, debug.traceback)
- if ok then
-
- for k,p in pairs(noticesJson) do
- self:AddNotices(p)
- end
- --self:AddNotices(noticesJson)
- else
- local notice = {}
- notice.NoticeTitle = "";
- notice.LimitedTimeLabel = "";
- notice.NoticeBeginTime = "";
- notice.NoticeEndTime = "";
- notice.NoticeTxt = string.formatbykey("NoticeAnomaly");
- notice._showing = true
- self.notices[#self.notices+1] = notice
- LogError("[Notice].."..errors)
- end
- self:SetListData()
- end
- function UINotifyActivityTipsView:ParseNotice(noticeJson)
- if noticeJson == nil then
- return nil
- end
- local notice = {};
-
- notice.NoticeTitle = noticeJson.title;
- notice.LimitedTimeLabel = noticeJson.timeLabel;
- notice.NoticeBeginTime = noticeJson.beginTime;
- notice.NoticeEndTime = noticeJson.endTime;
- notice.NoticeTxt = noticeJson.text;
- notice.top = noticeJson.top
- if noticeJson.top == 1 then
- notice._showing = true
- end
-
- return notice
- end
- function UINotifyActivityTipsView:AddNotices(noticesJson)
- local notice = self:ParseNotice(noticesJson)
- if notice ~= nil then
- if notice.top == 1 then
- table.insert(self.notices, 1, notice)
- else
- self.notices[#self.notices + 1] = notice
- end
- end
- end
- function UINotifyActivityTipsView:SetListData()
- if self.notices ~= nil and #self.notices > 0 then
- --self.notices[1]._showing = true
- CommonUtil.LoopGridViewEleCreateNew(self,
- self.notifyScrollList.loopVerticalScrollRect,
- self.notifyScrollList.content.verticalLayoutGroup,
- self.notices,
- 0,
- self, self.SetNoticeItem);
- self.notifyScrollList.loopVerticalScrollRect.velocity = Vector2.zero;
- local _position = self.notifyScrollList.content.transform.localPosition;
- _position.y = 0;
- self.notifyScrollList.content.transform.localPosition = _position;
- end
- end
- function UINotifyActivityTipsView:SetNoticeItem(itemLua, idx,itemData)
- if itemData._showing then
- self.lastShowItem = itemLua
- self.lastShowNotifyData = itemData
- end
- NotifyItemCtr:SetData(self, itemLua, itemData, self.OnOpenNoticeCallback,self.OnHideNoticeCallback);
- end
- function UINotifyActivityTipsView:OnOpenNoticeCallback(_item,itemData)
- local hideTitle = ""
- if self.lastShowNotifyData ~= nil then
- self.lastShowNotifyData._showing = false;
- hideTitle = self.lastShowNotifyData.NoticeTitle
- end
- self.lastShowNotifyData = itemData
-
- local oldItem = self.lastShowItem
- self.lastShowItem = _item
- return oldItem,hideTitle;
- end
- function UINotifyActivityTipsView:OnHideNoticeCallback(itemData)
- self.lastShowItem = nil
- end
- function UINotifyActivityTipsView:OnBtnCloseClick()
- self:UIClose()
- end
- --Toggle事件,_params是1代表的是精彩活动,是2代表的是游戏公告
- function UINotifyActivityTipsView:OnPageToggleClick(_toggle, _params)
- if _toggle.isOn then
- if self.currentSelectedType == _params then
- return
- end
- self.currentSelectedType = _params
- self:OpenPageByTab(self.currentSelectedType)
- --LogError(self.currentSelectedType.."add by raul---page1--精彩活动---page2--游戏公告")
- end
- end
- return UINotifyActivityTipsView
|