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

219 lines
7.6 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 parent = {}
function RoleSkinPanel:InitComponent(gameObject)
this.gameObject = gameObject
this.skinPre = Util.GetGameObject(gameObject,"skinPre")
this.Select = Util.GetGameObject(gameObject,"selectLight")
this.skinGrid = Util.GetGameObject(gameObject,"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
return this
end
function RoleSkinPanel:BindEvent()
end
--添加事件监听(用于子类重写)
function RoleSkinPanel:AddListener()
end
--移除事件监听(用于子类重写)
function RoleSkinPanel:RemoveListener()
end
this.UpdateShow = this:OnShow(0,parent,curHeroData)
--界面打开时调用
function RoleSkinPanel:OnShow(_sortinglayer,_parent,_curHerodata)
this.gameObject:SetActive(true)
curHeroData = _curHerodata
parent = _parent
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] then
tempskins[configs[i].Type] = configs[i]
end
end
local 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)
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
this:ShowTime()
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 = data.ReadingName
if data.IsDefault == 1 then
skinName.text = "默认"
end
icon.sprite = Util.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 = 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 = "获取途径"
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 == curHeroData.skinId then
return
end
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("已更换皮肤!")
this:OnShow(0,parent,tempdata)
end)
else
parent:ChangeCurentHeroSkinLive(data)
PopupTipPanel.ShowTip("未获得此皮肤!")
end
end
function this: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("%d天",day)
elseif hour > 0 then
return string.format("%2d时",hour)
elseif minute > 0 then
return string.format("%0d分",minute)
else
return string.format("%0d分",1)
end
end
function RoleSkinPanel:OnHide()
this.gameObject:SetActive(false)
end
function RoleSkinPanel:OnClose()
end
function RoleSkinPanel:OnDestroy()
skinPres = {}
porpertys = {}
curHeroData = {}
if this.timer then
this.timer:Stop()
this.timer = nil
end
end
return RoleSkinPanel