c1_lua/lua/app/module/login/login_ui.lua
2023-04-11 21:58:05 +08:00

125 lines
3.6 KiB
Lua

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))
uiMap["login_ui.copy_account_tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.CLICK_COPY_ACOUNT_DESC))
self:initListener()
ModuleManager.LoginManager:addServerListCallback(function(serverList)
if EDITOR_MODE then
Logger.logHighlight("------------serverList------------")
Logger.printTable(serverList)
end
self:refreshServerList(serverList)
ModuleManager.LoginManager:saveAuthArgs()
ModuleManager.LoginManager:initSocket()
end)
-- first 可以卸载了, 此项目只会启动时检查一次热更,之后不会再次检查
CS.BF.BFMain.Instance.LuaMgr:OnGameInitSucc()
LocalData:save()
local accountId = LocalData:getAccountInfo().id or GConst.EMPTY_STRING
local copyTx = uiMap["login_ui.copy_account_tx"]
copyTx:setVisible(accountId ~= GConst.EMPTY_STRING)
copyTx:addClickListener(function()
GFunc.copyStr(accountId)
end)
end
function LoginUI:initListener()
self:addEventListener(EventManager.CUSTOM_EVENT.LOGIN_REQ_SUCCESS, function()
self:preloadAndEnterMaincity()
end)
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
function LoginUI:refreshServerList(serverList)
self.serverList = serverList or {}
if not ModuleManager.LoginManager.selectIndex or ModuleManager.LoginManager.selectIndex <= 0 then
ModuleManager.LoginManager.selectIndex = 1
else
ModuleManager.LoginManager.selectIndex = ModuleManager.LoginManager.selectIndex + 1
end
if ModuleManager.LoginManager.selectIndex > #self.serverList then
ModuleManager.LoginManager.selectIndex = 1
end
local defaultUrl = self.serverList[ModuleManager.LoginManager.selectIndex].url
Logger.logHighlight(defaultUrl)
LocalData:setString(LocalData.KEYS.GATE, defaultUrl)
end
return LoginUI