local UILoginAnnouncement = UIViewClass() local JSON = require("cjson") local EventSystem = require('Event/EventSystem') local INTERVAL_GET_SPEED = 1.5 local INTERVAL_SYNC_ANNOUNCEMENT_TIME = 60 --保底刷新拉取公告时间 local Tab_Title_MaxLength = 23 --tab文本最长字节长度(单字节语言) local Tab_Title_MaxLength_Tailand = 125 --tab文本最长字节长度(泰语) function UILoginAnnouncement:OnCreated() self.contentLen = 0 self.curIndex = 0 end function UILoginAnnouncement:OnOpened() UIUtils.SetLabelText(self.UICommonPopUpTab.txt_Title,Const_IDS.IDS_LOGIN_SERVER_TYPE_NOTICE) self:RegistSystemEvent(EventID.UI_Login_SyncAnnouncementInfo, self.SyncAnnouncementList) UIUtils.SetActive(self.group_DownloadInfo, false) self.announcementKind = CTL.Login.AnnouncementKind.SystemNoticeKind_Public self:SyncAnnouncementList() UIUtils.SetActive(self.panel_WhiteList, false) --检测设备性能过低问题 self:CheckNeedQuitGame() self.updateAnnounceTextTimer = nil if DEF.USE_BATCH_MODE then self:CloseView() end self:RegistSystemEvent(EventID.UI_OnWhiteListEntered, self.OnWhiteListEntered) end function UILoginAnnouncement:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUpTab.btn_Close) end function UILoginAnnouncement:SyncAnnouncementList() local announcementList = MDL.Login.GetAnnouncementList() self:InitData(announcementList) end function UILoginAnnouncement:InitData(announcementList) self.UICommonPopUpTab.loop_Tab:ClearCells() if announcementList ~= nil and #announcementList > 0 then --c#拿的list 索引从0开始 --如果有强更公告或是维护公告,只显示维护公告,否则显示所有公告 local forceUpdateKey local maintainceKey local obstructKey --一年的秒数作为最大值 local freshTime = 31536000 for i, v in ipairs(announcementList) do local beginTime = v.Begin local endTime = v.End --先判断公告是否过期 if CTL.Login.IsAnnouncementInTime(beginTime, endTime) then local remainTime = endTime - MDL.Login.AnnounceServerTime freshTime = remainTime < freshTime and remainTime or freshTime if v.Kind == CTL.Login.AnnouncementKind.SystemNoticeKind_Obstruct then --阻挡公告优先级最高 obstructKey = i break elseif v.Kind == CTL.Login.AnnouncementKind.SystemNoticeKind_Forceupdate then forceUpdateKey = i elseif v.Kind == CTL.Login.AnnouncementKind.SystemNoticeKind_Maintaince then maintainceKey = i end end end --如果公告刷新时间比保底刷新时间近,那就走公告剩余时间 if freshTime > 0 and freshTime < INTERVAL_SYNC_ANNOUNCEMENT_TIME then self:StopRepeatFunc(self.OnUpdateFun) self:StartRepeatFunc(self.OnUpdateFun,freshTime) else --否则就走保底刷新 self:StopRepeatFunc(self.OnUpdateFun) self:StartRepeatFunc(self.OnUpdateFun,INTERVAL_SYNC_ANNOUNCEMENT_TIME) end if obstructKey ~= nil then self.hasStartShowSpeed = false self.downloadSpeedShow = 0 self.announcementKind = CTL.Login.AnnouncementKind.SystemNoticeKind_Obstruct local find = announcementList[obstructKey] self.UICommonPopUpTab.loop_Tab:AddData(find, 0) --预下载 if DEF.OPEN_STAGE_DOWNLOAD then self.progressMat = self.img_DownloadFrame.material self.progressMat:SetFloat("_Percent", 0) self.downloadMaxNum = CTL.HotFix.GetMaxGroupStage() self:RegistSystemEvent(EventID.UI_Loading_UpdateDownloadProgress, self.UpdateDownloadProgress) self:RegistSystemEvent(EventID.UI_StagePackage_AllDownload, self.UpdateDownloadState) self:RegistSystemEvent(EventID.Pause_Download, self.UpdateDownloadState) self:RegistSystemEvent(EventID.Resume_Download, self.UpdateDownloadState) self:RegistSystemEvent(EventID.UpdateDownloadState, self.UpdateDownloadState) self:RegistSystemEvent(EventID.OnPerPackFinish, self.OnPerPackFinish) self:UpdateDownloadState() end elseif forceUpdateKey ~= nil then self.announcementKind = CTL.Login.AnnouncementKind.SystemNoticeKind_Forceupdate local find = announcementList[forceUpdateKey] self.UICommonPopUpTab.loop_Tab:AddData(find, 0) elseif maintainceKey ~= nil then self.announcementKind = CTL.Login.AnnouncementKind.SystemNoticeKind_Maintaince local find = announcementList[maintainceKey] self.UICommonPopUpTab.loop_Tab:AddData(find, 0) else self.announcementKind = CTL.Login.AnnouncementKind.SystemNoticeKind_Public for i, v in ipairs(announcementList) do self.UICommonPopUpTab.loop_Tab:AddData(v, 0) end end self.UICommonPopUpTab.loop_Tab:SelectIndex(0) else self.Txt_Announce.text = nil end end function UILoginAnnouncement:OnPerPackFinish(stage) self.hasStartShowSpeed = false self:StopRepeatFunc(self.ShowDownloadSpeed) end --底层获取的速度:每秒速度相加总和/相加总次数,当下载开始1s后才开始计算 --每一个pack的开始,都会重置上一次速度的计算,下一个pack就需要等待1s --因此这里错开时间去取速度 function UILoginAnnouncement:ShowDownloadSpeed() self.downloadSpeedShow = UTL.String.TransferKiloBytesSize(LoginProxy.GetDownloadSpeed()) end function UILoginAnnouncement:OnUpdateFun(deltaTime, timeSinceUpdate) if deltaTime < INTERVAL_SYNC_ANNOUNCEMENT_TIME then self:StopRepeatFunc(self.OnUpdateFun) CTL.Login.IsClickNotice = true CTL.Login.StartGetGamePackageCfg() else self:StopRepeatFunc(self.OnUpdateFun) --模拟点击公告按钮来获取最新公告 EventSystem.Dispatch(EventID.UI_Login_RefreshAnnouncementInfo) end end function UILoginAnnouncement:OnCellInit(scrollRect, index, item, data) if scrollRect == self.UICommonPopUpTab.loop_Tab and data then UIUtils.SetActive(item.img_RedDot, false) UIUtils.SetActive(item.img_Arrow, false) UIUtils.SetActive(item.img_ArrowS, false) local title = self:HandleTabStr(data.Title) item.txt_Name_Selected.text = title item.txt_Name_Nomal.text = title local txtState = data.Type; -- 角标文字类型 local cornorImageState = data.CornerMark - 1; -- 角标图片类型 if cornorImageState < 0 then cornorImageState = 0 end if txtState == 0 then UIUtils.SetActive(item.group_SignState, false) UIUtils.SetActive(item.group_SignStateS, false) else UIUtils.SetActive(item.group_SignState, true) UIUtils.SetActive(item.group_SignStateS, true) -- 0、绿色 1、红色 2、灰色 if cornorImageState == 0 then item.UIState:SetState(2) item.UIStateS:SetState(2) elseif cornorImageState == 1 then item.UIState:SetState(1) item.UIStateS:SetState(1) elseif cornorImageState == 1 then item.UIState:SetState(0) item.UIStateS:SetState(0) end UIUtils.SetLabelText(item.txt_Fire, self:GetTabHintStr(txtState)) UIUtils.SetLabelText(item.txt_FireS, self:GetTabHintStr(txtState)) end end end function UILoginAnnouncement:HandleTabStr(title) --中文不做特殊处理 if Localization.IsAllChinese() then return title end local count, maxCharCount --泰语(一个泰文占3个字符) if Localization.IsThailand() then count = UTL.String.GetStrCharCount(title, 3) maxCharCount = Tab_Title_MaxLength_Tailand else count = UTL.String.GetStrCharCount(title, 1) maxCharCount = Tab_Title_MaxLength end if count <= maxCharCount then return title end --根据空格划分开,不能从单词中间切割 for i = maxCharCount + 1, 1, -1 do if title:byte(i) == 32 then -- 32 空格字符的ASCII码 return string.sub(title, 1, i - 1) .. "..." end end return string.sub(title, 1, maxCharCount) .. "..." end -- 1、版本 2、活动 3、公告 4、最新 5、更新 function UILoginAnnouncement:GetTabHintStr(index) local txtIDS = "" if index == 1 then txtIDS = "IDS_LOGIN_SERVER_TYPE_VER" elseif index == 2 then txtIDS = "IDS_LOGIN_NOTICE_TYPE_NOTICE" elseif index == 3 then txtIDS = "IDS_Login_Announcement" elseif index == 4 then txtIDS = "IDS_LOGIN_NOTICE_TYPE_NEW" elseif index == 5 then txtIDS = "IDS_LOGIN_SERVER_TYPE_UPDATE" end return Const_IDS[txtIDS] end --解决字体花屏的问题,定时加载一定数量的字符 function UILoginAnnouncement:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.UICommonPopUpTab.loop_Tab and data then self.lua_value = JSON.decode(data.Body) self.Txt_Announce.text = self.lua_value.Content UIUtils.ResetScrollRect(self.group_Scroll) UIUtils.SetLabel(self.lab_Title, data.Title) end end function UILoginAnnouncement:OnButtonClicked(obj) if obj == self.UICommonPopUpTab.btn_Close then self:ClickClose() elseif obj == self.btn_WhiteList then self:AfterInputWhiteListPwd() elseif obj == self.btn_ShowWhiteList then self:OpenWhiteList() elseif obj == self.btn_rect then if LoginProxy.Get_IsDownloading() then CTL.HotFix.PauseDownload() else CTL.HotFix.ContinueDownloadStage() end end end --打开白名单 local _firstClickOpenWhiteTime = 0 local _clickOpenWhiteCount = 0 local WhiteListClickTime = 3 local WhiteListClickNum = 7 function UILoginAnnouncement:OpenWhiteList() if _firstClickOpenWhiteTime == 0 then _firstClickOpenWhiteTime = os.time() _clickOpenWhiteCount = 1 else if os.time() - _firstClickOpenWhiteTime < WhiteListClickTime then _clickOpenWhiteCount = _clickOpenWhiteCount + 1 else _firstClickOpenWhiteTime = 0 _clickOpenWhiteCount = 0 end end --3秒内连点7次,打开白名单 if _clickOpenWhiteCount > WhiteListClickNum then self.panel_WhiteList.gameObject:SetActive(true) _firstClickOpenWhiteTime = 0 _clickOpenWhiteCount = 0 end end --输入完白名单 function UILoginAnnouncement:AfterInputWhiteListPwd() self.panel_WhiteList.gameObject:SetActive(false) local inputWhiteListPwd = self.input_WhiteList.text if not string.isNilOrEmpty(inputWhiteListPwd) then if CTL.Login.SetInputWhiteList(inputWhiteListPwd) then self:CloseView() CTL.Login.SetGameLoginType() SDKUtil.AutoLogin() end end end function UILoginAnnouncement:OnWhiteListEntered(whitelistStr) self.input_WhiteList.text = whitelistStr self:AfterInputWhiteListPwd() end function UILoginAnnouncement:ClickClose() if CTL.Login.OnClickCloseAnnoucement() then --0不处理 1维护警告 2关闭界面 self:CloseView() end end --检测低端安卓手机是否需要退出游戏,小于配置的分的就弹出退出游戏 function UILoginAnnouncement:CheckNeedQuitGame() local isNeedQuit = false local needQuitGPURankNumber = 51 --GPU 小于51分的就弹出退出游戏 --新增模拟器跳过检测 if UNITY_ANDROID and not UNITY_EDITOR and not TAI_DEVELOPMENT_BUILD and not DEF.USE_UWA_TOOLS and not IsEmulator then local rankNumber = UIUtils.GetGPURankNumber() --rankNumber为0 表示检测不到GPU型号,需要跳过低设备弹窗 if rankNumber ~= 0 then isNeedQuit = rankNumber < needQuitGPURankNumber end end if isNeedQuit then --UTL.MessageBox.ShowOnlyOkBox("", Const_IDS.IDS_ERROR_Lowend_Device, self.OnQuitConfirm) UTL.MessageBox.ShowOnlyOkBox("", Const_IDS.IDS_ERROR_Lowend_Device_Allowin, nil) --先不退出游戏,只弹提示 end end function UILoginAnnouncement:OnQuitConfirm(buttonID) UIUtils.QuitGame() end function UILoginAnnouncement:UpdateDownloadProgress(curSize, maxSize, speed) curSize = self.hasDownloadSize + curSize local curShow = UTL.String.TransferKiloBytesSize(curSize) local maxShow = UTL.String.TransferKiloBytesSize(self.maxDownloadSize) local content = string.format(UIUtils.GetLocalizedTxt(Const_IDS.IDS_StagePackage_DownloadProgress) .. "%s/S(%s/%s)", CTL.HotFix.GetCurGroupStage(), self.downloadMaxNum, self.downloadSpeedShow, curShow, maxShow) self.txt_DownloadProgress.text = content self.progressMat:SetFloat("_Percent", curSize / self.maxDownloadSize) if self.hasStartShowSpeed == false then self.hasStartShowSpeed = true self:StartRepeatFunc(self.ShowDownloadSpeed, INTERVAL_GET_SPEED, 0) end end function UILoginAnnouncement:UpdateDownloadState() local curStage = LoginProxy.GetCurStage() local nextStageGroup = CTL.HotFix.GetStageNum(CTL.HotFix.GetNextStage()) local curStageGroup = CTL.HotFix.GetStageNum(curStage) self.maxDownloadSize = CTL.HotFix.GetStageGroupSize(nextStageGroup) if curStageGroup == nextStageGroup then self.hasDownloadSize = CTL.HotFix.GetSeriesStageSize(CTL.HotFix.GetGroupMinStage(curStageGroup), curStage) else self.hasDownloadSize = 0 end if CTL.HotFix.Get_IfAllDownload() == true then UIUtils.SetActive(self.group_DownloadInfo, false) else UIUtils.SetActive(self.group_DownloadInfo, true) if LoginProxy.Get_IsDownloading() then self.group_DownloadState:SetState(1) else self.group_DownloadState:SetState(0) --暂停状态下载速度置为0 self:UpdateDownloadProgress(CTL.HotFix.GetLastDownloadSize(), self.maxDownloadSize, 0) end end end function UILoginAnnouncement:OnClosed() self.progressMat = nil end return UILoginAnnouncement