miduo_client/Assets/ManagedResources/~Lua/Modules/Message/LoadingPanel.lua

98 lines
3.0 KiB
Lua
Raw Normal View History

2021-04-20 13:58:00 +08:00
require("Base/BasePanel")
2020-05-09 13:31:21 +08:00
LoadingPanel = Inherit(BasePanel)
local this = LoadingPanel
2021-01-25 18:10:14 +08:00
local tipsConfig = ConfigManager.GetConfig(ConfigName.Tips)
2020-05-09 13:31:21 +08:00
--初始化组件(用于子类重写)
function LoadingPanel:InitComponent()
2021-04-21 13:12:04 +08:00
--
2020-05-09 13:31:21 +08:00
this.Slider = Util.GetGameObject(self.gameObject, "Slider"):GetComponent("Slider")
this.Tip = Util.GetGameObject(self.gameObject, "Slider/Image/LoadingText"):GetComponent("Text")
2020-08-22 15:31:14 +08:00
this.SliderText = Util.GetGameObject(self.gameObject, "Slider/Fill Area/Fill/Image/Text"):GetComponent("Text")
this.bg = Util.GetGameObject(self.gameObject, "bg1"):GetComponent("Image")
2020-05-09 13:31:21 +08:00
screenAdapte(Util.GetGameObject(self.gameObject, "bg1"))
screenAdapte(Util.GetGameObject(self.gameObject, "bg2"))
end
function LoadingPanel:OnOpen(sp)
local index = 0
this.bg.sprite = sp
2021-01-25 18:10:14 +08:00
math.randomseed(os.time())
2023-11-29 15:11:22 +08:00
index = math.random(1, 16)
2021-02-23 17:17:35 +08:00
this.Tip.text = GetLanguageStrById(tipsConfig[index].Tips)
end
2021-04-21 13:12:04 +08:00
-- 销毁时回收
function LoadingPanel:OnDestroy()
end
2020-05-09 13:31:21 +08:00
local callList = {}
2020-09-12 11:02:33 +08:00
local curIndex = 0
2020-05-09 13:31:21 +08:00
local lerp = 0
local maxIndex = 0
local function update()
2020-09-25 14:11:05 +08:00
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
2020-05-09 13:31:21 +08:00
end
function LoadingPanel.AddStep(func)
table.insert(callList, func)
maxIndex = maxIndex + 1
end
2020-05-09 13:31:21 +08:00
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)
2020-05-09 13:31:21 +08:00
-- 强制进入下一步
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]
2020-05-09 13:31:21 +08:00
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)
2020-05-09 13:31:21 +08:00
end
function LoadingPanel.End()
UpdateBeat:Remove(update)
this:ClosePanel()
callList = {}
this.spLoader:Destroy()
2020-05-09 13:31:21 +08:00
end
2020-06-23 18:36:24 +08:00
return LoadingPanel