144 lines
4.1 KiB
Lua
144 lines
4.1 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()
|
|
ModuleManager.LoginManager:removeAllLoginData()
|
|
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))
|
|
|
|
self:initListener()
|
|
|
|
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)
|
|
|
|
ModuleManager.LoginManager:resetServerListStartTime()
|
|
ModuleManager.LoginManager:addServerListCallback(function(serverList)
|
|
if EDITOR_MODE then
|
|
Logger.logHighlight("------------serverList------------")
|
|
Logger.printTable(serverList)
|
|
end
|
|
|
|
self:refreshServerList(serverList)
|
|
ModuleManager.LoginManager:saveAuthArgs(false)
|
|
ModuleManager.LoginManager:initSocket()
|
|
|
|
local info = LocalData:getLastLoginInfo()
|
|
BIReport:postAccountLoginClick(info.type)
|
|
end)
|
|
ModuleManager.LoginManager:getServerList()
|
|
|
|
CS.BF.BFMain.Instance.LuaMgr:OnGameInitSucc()
|
|
LocalData:save()
|
|
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
|
|
LocalData:setString(LocalData.KEYS.GATE, defaultUrl)
|
|
end
|
|
|
|
return LoginUI |