141 lines
5.4 KiB
Lua
141 lines
5.4 KiB
Lua
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()
|
||
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
|
||
self.Select.transform:SetParent(Util.GetGameObject(go,"skinState").transform)
|
||
self.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()
|
||
poolManager:UnLoadLive(curHeroData.live, parent.curLiveObj)
|
||
HeroManager.ChangeSkinId(curHeroData.dynamicId,skinId)
|
||
local tempdata = HeroManager.GetSingleHeroData(curHeroData.dynamicId)
|
||
curLiveName = tempdata.Live
|
||
parent.curLiveObj = HeroManager.LoadHerolive(tempdata,parent.curObj)
|
||
PopupTipPanel.ShowTip("已更换皮肤!")
|
||
this:OnShow(0,parent,tempdata)
|
||
end)
|
||
else
|
||
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("未获得此皮肤!")
|
||
end
|
||
|
||
end
|
||
|
||
function RoleSkinPanel:OnHide()
|
||
this.gameObject:SetActive(false)
|
||
end
|
||
function RoleSkinPanel:OnClose()
|
||
|
||
end
|
||
function RoleSkinPanel:OnDestroy()
|
||
skinPres = {}
|
||
porpertys = {}
|
||
curHeroData = {}
|
||
end
|
||
return RoleSkinPanel |