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

137 lines
4.6 KiB
Lua

require("Base/BasePanel")
LoadingPanel = Inherit(BasePanel)
local this = LoadingPanel
local tipsConfig = ConfigManager.GetConfig(ConfigName.Tips)
local loadingConfig = ConfigManager.GetConfig(ConfigName.Loading)
--初始化组件(用于子类重写)
local spineName = nil
local spineObj = nil
local configLen = 0
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")
this.heroPos = Util.GetGameObject(self.gameObject, "heroPos")
screenAdapte(Util.GetGameObject(self.gameObject, "bg1"))
screenAdapte(Util.GetGameObject(self.gameObject, "bg2"))
end
function LoadingPanel:OnOpen()
local index = 0
local spLoader = SpriteLoader.New()
this.bg.sprite = spLoader:LoadSprite("LoadingBG2")
math.randomseed(os.time())
index = math.random(1, 16)
this.Tip.text = GetLanguageStrById(tipsConfig[index].Tips)
this.Tip.text = GetLanguageStrById("加载中不需要消耗流量...")
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
local heroConfig
for k, v in ConfigPairs(loadingConfig) do
configLen = configLen + 1
end
local spineLive = math.random(1, configLen)
local curLoad = ConfigManager.TryGetConfigData(ConfigName.Loading, spineLive)
if curLoad then
if spineObj ~= nil and spineName ~= nil then
poolManager:UnLoadLive(spineName, spineObj, PoolManager.AssetType.GameObject)
end
heroConfig = ConfigManager.TryGetConfigData(ConfigName.HeroConfig, curLoad.Hero)
spName = curLoad.LoadingBG
end
UIManager.OpenPanel(UIName.LoadingPanel)
--LogError("heroconfig i================="..heroConfig[10001].Id.." len==="..#heroConfig)
if heroConfig then
spineName = GetResourcePath(heroConfig.Live)
spineObj = poolManager:LoadLive(spineName, this.heroPos.transform, Vector3.one * heroConfig.Scale,
Vector3.New(heroConfig.Position[1], heroConfig.Position[2], 0))
spineObj.transform:SetParent(this.heroPos.transform)
-- spineObj.transform.localPosition = Vector2.New(0, -20)
-- spineObj.transform.localScale=Vector3.one
end
UpdateBeat:Add(update)
lerp = 0
curIndex = 0
this.Slider.maxValue = #callList - 1
this.Slider.value = curIndex
--"你知道嘛:充值会让你变得更强!" --"白驹工作室倾情奉献"
LoadingPanel.OnStep()
--end
--end)
end
function LoadingPanel.End()
UpdateBeat:Remove(update)
this:ClosePanel()
callList = {}
if spineObj ~= nil and spineName ~= nil then
poolManager:UnLoadLive(spineName, spineObj, PoolManager.AssetType.GameObject)
end
spineName = nil
spineObj = nil
this.spLoader:Destroy()
end
return LoadingPanel