miduo_client/Assets/ManagedResources/~Lua/Modules/RoleInfo/RoleSkinPanel.lua

244 lines
8.2 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

require("Base/BasePanel")
RoleSkinPanel = Inherit(BasePanel)
local this = RoleSkinPanel
local porpertyConfigs = ConfigManager.GetConfig(ConfigName.PropertyConfig)
local artResConfig = ConfigManager.GetConfig(ConfigName.ArtResourcesConfig)
local skinPres = {}
local porpertys = {}
local curHeroData = {}
local curSkinId = 0
local parent = {}
local skins = {}
function RoleSkinPanel:New(gameObject)
local b = {}
b.gameObject = gameObject
b.transform = gameObject.transform
setmetatable(b, { __index = RoleSkinPanel })
return b
end
function RoleSkinPanel:InitComponent()
this.spLoader = SpriteLoader.New()
this.skinPre = Util.GetGameObject(self.gameObject,"skinPre")
this.Select = Util.GetGameObject(self.gameObject,"selectLight")
this.skinGrid = Util.GetGameObject(self.gameObject,"scroll/skinGrid")
for i = 1, this.skinGrid.transform.childCount do
skinPres[i] = {}
skinPres[i].obj = this.skinGrid.transform:GetChild(i - 1)
skinPres[i].data = nil
end
end
function RoleSkinPanel:BindEvent()
end
--添加事件监听(用于子类重写)
function RoleSkinPanel:AddListener()
end
--移除事件监听(用于子类重写)
function RoleSkinPanel:RemoveListener()
end
this.UpdateShow = this:OnShow()
function RoleSkinPanel:OnShow()
self.gameObject:SetActive(true)
end
function RoleSkinPanel:SetData(_sortinglayer,_parent,_curHerodata,_isUpZhen,_heroDatas)
curHeroData = _curHerodata
parent = _parent
curSkinId = curHeroData.skinId
local configs = ConfigManager.GetAllConfigsDataByKey(ConfigName.HeroSkin,"HeroId",curHeroData.id)
local tempskins = {}
for i = 1 ,#configs do
--LogGreen("configs[i].Type:"..configs[i].Type)
if not tempskins[configs[i].Type] and configs[i].Show == 1 then
tempskins[configs[i].Type] = configs[i]
end
end
skins = {}
for i,v in pairs(tempskins) do
table.insert(skins,v)
end
table.sort(skins,function(a,b)
if a.Type == b.Type then
return a.Id < b.Id
else
return a.Type < b.Type
end
end)
this:UpdateView()
this:ShowTime()
end
function RoleSkinPanel:UpdateView()
for k,v in pairs(skinPres) do
v.obj.gameObject:SetActive(false)
v.data = nil
end
local index = 1
for i,v in ipairs(skins) do
if not skinPres[index] then
skinPres[index] = {}
end
if not skinPres[index].obj then
skinPres[index].obj = newObjToParent(this.skinPre,this.skinGrid)
end
skinPres[index].data = v
--LogGreen("v.Type:"..v.Type)
skinPres[index].obj.gameObject:SetActive(true)
self:SetSingleData(skinPres[index].obj,v)
index = index + 1
end
end
function RoleSkinPanel:SetSingleData(go,data)
--LogGreen("皮肤Id"..data.Type)
local icon = Util.GetGameObject(go,"skinIcon"):GetComponent("Image")
local lock = Util.GetGameObject(go,"skinState/Off")
local infoPre = Util.GetGameObject(go,"skinInfo/infoPre")
local infoGrid = Util.GetGameObject(go,"skinInfo/grid")
local skinName = Util.GetGameObject(go,"skinName/name"):GetComponent("Text")
skinName.text = GetLanguageStrById(data.ReadingName)
if data.IsDefault == 1 then
skinName.text = Language[11828]
end
--icon.sprite = this.spLoader:LoadSprite(artResConfig[data.Painting].Name)
if not porpertys then
porpertys = {}
end
if not porpertys[go] then
porpertys[go] = {}
end
for i = 1, infoGrid.transform.childCount do
porpertys[go][i] = infoGrid.transform:GetChild(i - 1)
porpertys[go][i].gameObject:SetActive(false)
end
if HeroSkinManager.IsExist(data.Type) or data.IsDefault == 1 then
if data.MonomerProperty and #data.MonomerProperty > 0 then
for i = 1, #data.MonomerProperty do
if not porpertys[go][i] then
porpertys[go][i] = newObjToParent(infoPre,infoGrid)
end
porpertys[go][i].gameObject:SetActive(true)
local tempProData = porpertyConfigs[data.MonomerProperty[i][1]]
Util.GetGameObject(porpertys[go][i],"info"):GetComponent("Text").text = GetLanguageStrById(tempProData.Info) .. "+" ..GetPropertyFormatStr(tempProData.Style,data.MonomerProperty[i][2])
porpertys[go][i]:GetComponent("Button").enabled = false
end
end
lock.gameObject:SetActive(false)
else
if not porpertys[go][1] then
porpertys[go][1] = newObjToParent(infoPre,infoGrid)
end
porpertys[go][1].gameObject:SetActive(true)
porpertys[go][1]:GetComponent("Button").enabled = true
Util.GetGameObject(porpertys[go][1],"info"):GetComponent("Text").text = Language[11829]
Util.AddOnceClick(porpertys[go][1].gameObject,function()
UIManager.OpenPanel(UIName.RewardItemSingleShowPopup, data.Id,function() end)
end)
lock.gameObject:SetActive(true)
end
if data.Type == curHeroData.skinId or (curHeroData.skinId == 0 and data.IsDefault == 1) then
this.Select.transform:SetParent(Util.GetGameObject(go,"skinState").transform)
this.Select:GetComponent("RectTransform").localPosition = Vector3.zero
end
Util.AddOnceClick(go.gameObject,function()
local skinId = data.IsDefault == 1 and 0 or data.Type
this:BtnAction(skinId,data)
end)
end
function RoleSkinPanel:BtnAction(skinId,data)
if skinId == curSkinId then
return
end
curSkinId = skinId
if HeroSkinManager.IsExist(skinId) or skinId == 0 then
NetManager.ChangeHeroSkin(curHeroData.dynamicId,skinId,function()
HeroManager.ChangeSkinId(curHeroData.dynamicId,skinId)
local tempdata = HeroManager.GetSingleHeroData(curHeroData.dynamicId)
parent:ChangeCurentHeroSkinLive()
PopupTipPanel.ShowTip(Language[11830])
this:UpdateView()
end)
else
parent:ChangeCurentHeroSkinLive(data)
PopupTipPanel.ShowTip(Language[11831])
end
end
function RoleSkinPanel:ShowTime()
if this.timer then
this.timer:Stop()
this.timer = nil
end
this.timer = Timer.New(function()
for k,v in pairs(skinPres) do
if v.data then
Util.GetGameObject(v.obj,"skinTime"):SetActive(true)
local skindata = HeroSkinManager.GetSkins(v.data.Type)
if v.data.IsDefault == 1 or not skindata then
Util.GetGameObject(v.obj,"skinTime"):SetActive(false)
elseif skindata.overTime < 0 then
Util.GetGameObject(v.obj,"skinTime"):SetActive(false)
else
local time = skindata.overTime
if time < 0 then
Util.GetGameObject(v.obj,"skinTime"):SetActive(false)
else
time = this:TimeToFormat(time)
Util.GetGameObject(v.obj,"skinTime/time"):GetComponent("Text").text = time
end
end
end
end
end,1,-1,true)
this.timer:Start()
end
function RoleSkinPanel:TimeToFormat(time)
local day = math.floor(time / (24 * 3600))
local minute = math.floor(time / 60) % 60
local sec = time % 60
local hour = math.floor(math.floor(time - day * 24 * 3600 - sec - minute * 60) / 3600)
if day > 0 then
return string.format(Language[11832],day)
elseif hour > 0 then
return string.format(Language[11833],hour)
elseif minute > 0 then
return string.format(Language[11834],minute)
else
return string.format(Language[11834],1)
end
end
function RoleSkinPanel:OnHide()
self.gameObject:SetActive(false)
end
function RoleSkinPanel:OnClose()
skinPres = {}
porpertys = {}
curHeroData = {}
if this.timer then
this.timer:Stop()
this.timer = nil
end
end
function RoleSkinPanel:OnDestroy()
this.spLoader:Destroy()
skinPres = {}
porpertys = {}
curHeroData = {}
if this.timer then
this.timer:Stop()
this.timer = nil
end
end
return RoleSkinPanel