local LoginUI = class("LoginUI", BaseUI) function LoginUI:ctor() self.progress = 0 self.retryTimes = 0 self.connectStartTimes = 0 end function LoginUI:getPrefabPath() return "assets/prefabs/ui/login/login_ui.prefab" end function LoginUI:onClose() end function LoginUI:onLoadRootComplete() local uiMap = self.root:genAllChildren() self.versionTx = uiMap["login_ui.version"] local version = CS.BF.BFMain.Instance.GameLaunchMgr:GetCurrentVersion() self.versionTx:setText(I18N:getGlobalText(I18N.GlobalConst.APP) .. version) uiMap["login_ui.logo"]:setLanguageSprite(GConst.ATLAS_PATH.UI_LOGIN, "login") self.progressTx = uiMap["login_ui.progress_tx"] self.progressTx:setText("") uiMap["login_ui.loading_text"]:setText(I18N:getGlobalText(I18N.GlobalConst.LOADING_DESC)) local distinctId = LocalData:getDistinctId() if distinctId == nil or distinctId == "" then distinctId = CS.ThinkingAnalytics.ThinkingAnalyticsAPI.GetDistinctId() LocalData:setDistinctId(distinctId) BIReport:setIsNewPlayer(true) BIReport:postGameLogin(true) BIReport:postFirstLoginEvent() else BIReport:setIsNewPlayer(false) BIReport:postGameLogin(false) end local data = {} data.open_num = 1 CS.ThinkingAnalytics.ThinkingAnalyticsAPI.UserAdd(data) local copyTx = uiMap["login_ui.copy_account_tx"] copyTx:setText(I18N:getGlobalText(I18N.GlobalConst.CLICK_COPY_ACOUNT_DESC)) copyTx:setVisible(true) copyTx:addClickListener(function() GFunc.copyStr(distinctId) end) CS.BF.BFMain.Instance.LuaMgr:OnGameInitSucc() LocalData:save() self:preloadAndEnterMaincity() end function LoginUI:preloadAndEnterMaincity() local WhiteResManager = require "app/common/white_res_manager" if WhiteResManager:isLoaded() then ModuleManager.LoginManager:loginGame() return end WhiteResManager:gamePreLoad(function(progress) self.progress = math.floor(progress * 100) self:updateProgress() end, function() self.progress = 100 self:updateProgress() end) end function LoginUI:updateProgress() if not self.slideSId then local curSlideValue = 0 self.progressTx:setText("0%") -- 进度条表现处理一下,看起来更平滑一些,最快的话0.5秒跑完 self.dt = 0 self.slideSId = self:scheduleGlobal(function(dt) self.dt = self.dt + dt if curSlideValue < self.progress then curSlideValue = math.floor(self.dt*200) if curSlideValue > self.progress then curSlideValue = self.progress end self.progressTx:setText(curSlideValue .. "%") -- 为了显示好看,加一个范围 local vfxPercent = curSlideValue if vfxPercent < 2 then vfxPercent = 2 elseif vfxPercent > 98 then vfxPercent = 98 end elseif curSlideValue >= 100 then self:unscheduleGlobal(self.slideSId) self.slideSId = nil ModuleManager.LoginManager:loginGame() end end, 0) end end return LoginUI