98 lines
3.0 KiB
Lua
98 lines
3.0 KiB
Lua
require("Base/BasePanel")
|
|
LoadingPanel = Inherit(BasePanel)
|
|
local this = LoadingPanel
|
|
local tipsConfig = ConfigManager.GetConfig(ConfigName.Tips)
|
|
--初始化组件(用于子类重写)
|
|
function LoadingPanel:InitComponent()
|
|
--
|
|
this.Slider = Util.GetGameObject(self.gameObject, "Slider"):GetComponent("Slider")
|
|
this.Tip = Util.GetGameObject(self.gameObject, "Slider/Image/LoadingText"):GetComponent("Text")
|
|
this.SliderText = Util.GetGameObject(self.gameObject, "Slider/Fill Area/Fill/Image/Text"):GetComponent("Text")
|
|
this.bg = Util.GetGameObject(self.gameObject, "bg1"):GetComponent("Image")
|
|
screenAdapte(Util.GetGameObject(self.gameObject, "bg1"))
|
|
screenAdapte(Util.GetGameObject(self.gameObject, "bg2"))
|
|
end
|
|
|
|
function LoadingPanel:OnOpen(sp)
|
|
local index = 0
|
|
this.bg.sprite = sp
|
|
math.randomseed(os.time())
|
|
index = math.random(1, 16)
|
|
this.Tip.text = GetLanguageStrById(tipsConfig[index].Tips)
|
|
end
|
|
-- 销毁时回收
|
|
function LoadingPanel:OnDestroy()
|
|
end
|
|
local callList = {}
|
|
local curIndex = 0
|
|
local lerp = 0
|
|
local maxIndex = 0
|
|
local function update()
|
|
if this.Slider and this.SliderText then
|
|
lerp = math.clamp(lerp + Time.fixedDeltaTime * 15,0,1)
|
|
local curValue = this.Slider.value * (1-lerp) + curIndex * lerp
|
|
this.Slider.value = curValue
|
|
local curTextValue = math.ceil((curValue/this.Slider.maxValue)*100)
|
|
curTextValue = curTextValue > 100 and 100 or curTextValue
|
|
this.SliderText.text = curTextValue .."%"
|
|
end
|
|
end
|
|
|
|
function LoadingPanel.AddStep(func)
|
|
table.insert(callList, func)
|
|
maxIndex = maxIndex + 1
|
|
end
|
|
|
|
function LoadingPanel.OnStep()
|
|
lerp = 0
|
|
curIndex = curIndex + 1
|
|
if callList[curIndex] then
|
|
callList[curIndex]()
|
|
end
|
|
end
|
|
|
|
-- 登录时有接口报错时执行,防止登录报错卡死导致进不去游戏的问题
|
|
function LoadingPanel.ErrorStep(msg)
|
|
--
|
|
if curIndex >= maxIndex then return end
|
|
LogError("登录接口"..curIndex..", 报错:"..msg.errCode .. "|"..msg.errMsg)
|
|
-- 强制进入下一步
|
|
LoadingPanel.OnStep()
|
|
end
|
|
|
|
|
|
function LoadingPanel.Start()
|
|
-- 创建sprite加载器
|
|
this.spLoader = SpriteLoader.New()
|
|
|
|
local spName = "loading1"
|
|
local sprites = PackageManager.GetLoadingList()
|
|
if sprites then
|
|
math.randomseed(os.time())
|
|
local index = math.random(1, #sprites)
|
|
spName = sprites[index]
|
|
end
|
|
LoadStreamingTexture(this.spLoader, spName, function(sp)
|
|
if #callList <= 1 then
|
|
return
|
|
end
|
|
UIManager.OpenPanel(UIName.LoadingPanel, sp)
|
|
UpdateBeat:Add(update)
|
|
lerp = 0
|
|
curIndex = 0
|
|
this.Slider.maxValue = #callList - 1
|
|
this.Slider.value = curIndex
|
|
--"你知道嘛:充值会让你变得更强!" --"白驹工作室倾情奉献"
|
|
LoadingPanel.OnStep()
|
|
end)
|
|
end
|
|
|
|
function LoadingPanel.End()
|
|
UpdateBeat:Remove(update)
|
|
this:ClosePanel()
|
|
callList = {}
|
|
|
|
this.spLoader:Destroy()
|
|
end
|
|
|
|
return LoadingPanel |