local UIPreDownloadJP = UIViewClass() local EventSystem = require('Event/EventSystem') -------------------- function UIPreDownloadJP:OnCreated() self.preDownloadRewardID = DataSheetManager.ConstData:GetDataByID("PreDownloadRewardID").IntValue end function UIPreDownloadJP:OnOpened(context) CTL.PreDownloadJP.SetInUIPreDownloadJPPanel(true) self:RegistSystemEvent(EventID.UI_Loading_UpdateDownloadProgress, self.RefreshDownLoadProgress) self:RegistSystemEvent(EventID.PreDownloadJP_ShowRedPoint, self.RefreshBtnState) self:InitPanel() self:RemoveRedPoint() end function UIPreDownloadJP:OnClosed() CTL.PreDownloadJP.SetInUIPreDownloadJPPanel(false) end function UIPreDownloadJP:OnButtonClicked(comp) if comp == self.btn_PreHotfix then if CTL.HotFix.Get_IsNetReachable() then CTL.Tips.AddTipsMsg(Const_IDS.IDS_PreDownload_Error) return end CTL.HotFix.TryStartPreHotfix() end end function UIPreDownloadJP:OnValueChanged(comp, value) if comp == self.toggle_Skip then PersistentData.DeviceData:Set(CTL.PreDownloadJP.NoWifiCanHotFix, value, true) if LoginProxy.Get_IsPauseDownload() and not value then CTL.HotFix.ResumeDownload() end end end function UIPreDownloadJP:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_QuestionReward then UTL.Item.SetItemCell(cellTable.item, data.ItemID, data.ItemNum) end end function UIPreDownloadJP:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_QuestionReward then if target == cellTable.item.event_Click then UTL.ItemTips.ShowCommonTipsById(data.ItemID) end end end -------------------- function UIPreDownloadJP:InitPanel() -- 显示公告内容 local content = MDL.PreDownloadJP.GetJapanUpdateContent() if content then UIUtils.SetLabel(self.labLocal_TaskDescribe, content) end -- 显示奖励 local rewardData = DataSheetManager.PreDownloadReward:GetDataByID(self.preDownloadRewardID) self.loop_QuestionReward:ReloadAll(rewardData.Item_Table) -- 设置非WIFI环境下载Toggle self.toggle_Skip.isOn = PersistentData.DeviceData:Get(CTL.PreDownloadJP.NoWifiCanHotFix, true) self:RefreshBtnState() end function UIPreDownloadJP:RefreshBtnRedPoint() self.btn_PreHotfix:SetRedPoint(MDL.PreDownloadJP.IsShowRp()) end function UIPreDownloadJP:RefreshBtnState() -- 判断本地下载状态 && 预下载版本号 local preHotfixCode = PersistentData.DeviceData:Get(CTL.PreDownloadJP.PreHotfixCode, "0") if preHotfixCode == CTL.HotFix.GetPreHotfixCode() then -- 如果本地保存的下载热更版本号跟公告相同 则表示下载中 self.state_DownloadInfo:SetState(2) self:RefreshDownLoadProgress(CTL.HotFix.GetLastDownloadSize(), MDL.HotFix.GetMaxDownloadSize(), 0) -- 设置一次下载状态 else if preHotfixCode == "0" and CTL.PreDownloadJP.IsPreHotfixFinish() and CTL.HotFix.GetPreHotfixCode() == MDL.PreDownloadJP.GetServePreHotfixCode() and MDL.PreDownloadJP.GetPreHotfixState() == MDL.PreDownloadJP.VersionGiftState.Send then self.state_DownloadInfo:SetState(1) else self.state_DownloadInfo:SetState(0) end self:RefreshBtnRedPoint() end end function UIPreDownloadJP:RefreshDownLoadProgress(curSize, maxSize, speed) if curSize == maxSize then if MDL.PreDownloadJP.GetPreHotfixState() == MDL.PreDownloadJP.VersionGiftState.Send then self.state_DownloadInfo:SetState(1) end else self.state_DownloadInfo:SetState(2) local curStr = UTL.String.TransferKiloBytesSize(curSize) local maxStr = UTL.String.TransferKiloBytesSize(maxSize) UIUtils.SetLabel(self.txt_DownloadResources, string.FormatByIdsId(Const_IDS.IDS_DownloadResources, curStr, maxStr)) UIUtils.SetLabel(self.txt_DownloadSpeed, string.FormatByIdsId(Const_IDS.IDS_DownloadSpeed, UTL.String.TransferKiloBytesSize(speed) .. "/S")) end end function UIPreDownloadJP:RemoveRedPoint() PersistentData.PlayerData:Set(CTL.PreDownloadJP.LastPreHotfixCode, CTL.HotFix.GetPreHotfixCode(), true) EventSystem.Dispatch(EventID.PreDownloadJP_ShowRedPoint) end return UIPreDownloadJP