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

139 lines
5.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 skins = {}
local parent = {}
local curLiveName = ""
local isUnLoadLive = false
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] = this.skinGrid.transform:GetChild(i - 1)
end
return this
end
function RoleSkinPanel:BindEvent()
end
--界面打开时调用
function RoleSkinPanel:OnShow(_sortinglayer,_parent,_curHerodata)
this.gameObject:SetActive(true)
curHeroData = _curHerodata
parent = _parent
local configs = ConfigManager.GetAllConfigsDataByKey(ConfigName.HeroSkin,"HeroId",curHeroData.id)
local skins = {}
for i = 1 ,#configs do
if not skins[configs[i].Type] then
skins[configs[i].Type] = configs[i]
end
end
for k,v in ipairs(skinPres) do
v.gameObject:SetActive(false)
end
local index = 1
for i,v in pairs(skins) do
if not skinPres[index] then
skinPres[index] = newObjToParent(self.skinPre,self.skinGrid)
end
skinPres[index].gameObject:SetActive(true)
self:SetSingleData(skinPres[index],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 = data.ReadingName
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)
Util.GetGameObject(porpertys[go][1],"info"):GetComponent("Text").text = "获取途径"
Util.AddOnceClick(porpertys[go][1].gameObject,function()
end)
lock.gameObject:SetActive(true)
end
if data.Type == curHeroData.skinId or (curHeroData.skinId == 0 and data.IsDefault == 1) then
self.Select.transform:SetParent(Util.GetGameObject(go,"skinState").transform)
self.Select:GetComponent("RectTransform").localPosition = Vector3.zero
elseif HeroSkinManager.IsExist(data.Type) or data.IsDefault == 1 then
local changeSkinId = data.IsDefault == 1 and 0 or data.Type
Util.AddOnceClick(go.gameObject,function()
NetManager.ChangeHeroSkin(curHeroData.dynamicId,changeSkinId,function()
poolManager:UnLoadLive(curHeroData.live, parent.curLiveObj)
HeroManager.ChangeSkinId(curHeroData.dynamicId,changeSkinId)
curHeroData = HeroManager.GetSingleHeroData(curHeroData.dynamicId)
curLiveName = curHeroData.Live
parent.curLiveObj = HeroManager.LoadHerolive(curHeroData,parent.curObj)
PopupTipPanel.ShowTip("已更换皮肤!")
isUnLoadLive = false
this:OnShow(0,parent,curHeroData)
end)
end)
else
Util.AddOnceClick(go.gameObject,function()
poolManager:UnLoadLive(curHeroData.live, parent.curLiveObj)
curLiveName = GetResourcePath(data.Live)
parent.curLiveObj = poolManager:LoadLive(GetResourcePath(data.Live), parent.curObj.transform,
Vector3.one * data.Scale, Vector3.New(data.Position[1], data.Position[2], 0))
PopupTipPanel.ShowTip("未获得此皮肤!")
isUnLoadLive = true
end)
end
end
function RoleSkinPanel:OnHide()
this.gameObject:SetActive(false)
-- if isUnLoadLive then
-- poolManager:UnLoadLive(curLiveName, parent.curLiveObj)
-- parent.curLiveObj = HeroManager.LoadHerolive(curHeroData,parent.curObj)
-- isUnLoadLive = false
-- end
end
function RoleSkinPanel:OnClose()
end
function RoleSkinPanel:OnDestroy()
skinPres = {}
porpertys = {}
curHeroData = {}
end
return RoleSkinPanel