281 lines
14 KiB
Lua
281 lines
14 KiB
Lua
require("Base/BasePanel")
|
||
RoleGodSoulLayout = Inherit(BasePanel)
|
||
local heroConfig = ConfigManager.GetConfig(ConfigName.HeroConfig)
|
||
|
||
--初始化组件(用于子类重写)
|
||
function RoleGodSoulLayout:InitComponent()
|
||
self.spLoader = SpriteLoader.New()
|
||
self.closeBtn = Util.GetGameObject(self.gameObject,"mask")
|
||
|
||
self.help = Util.GetGameObject(self.gameObject,"bgdi/topLayout/help")
|
||
self.helpPosition = self.help:GetComponent("RectTransform").localPosition
|
||
self.curHeroName = Util.GetGameObject(self.gameObject,"bgdi/topLayout/name"):GetComponent("Text")
|
||
self.curHeroGo = Util.GetGameObject(self.gameObject,"bgdi/topLayout/itemPre/HeroPre")
|
||
|
||
self.godPre = Util.GetGameObject(self.gameObject,"bgdi/godPre")
|
||
self.costPre = Util.GetGameObject(self.gameObject,"bgdi/costPre")
|
||
self.heroPre = Util.GetGameObject(self.gameObject,"bgdi/HeroPre")
|
||
self.singlePre = Util.GetGameObject(self.gameObject,"bgdi/singlePre")
|
||
self.grid = Util.GetGameObject(self.gameObject,"bgdi/scroll/grid")
|
||
self.gridPos = self.grid:GetComponent("RectTransform").anchoredPosition
|
||
self.gridList = {}
|
||
end
|
||
|
||
function RoleGodSoulLayout:OnSortingOrderChange()
|
||
end
|
||
|
||
--绑定事件(用于子类重写)
|
||
function RoleGodSoulLayout:BindEvent()
|
||
Util.AddClick(self.help, function()
|
||
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.shenhun,self.helpPosition.x,self.helpPosition.y - 500)
|
||
end)
|
||
Util.AddClick(self.closeBtn, function()
|
||
self:ClosePanel()
|
||
end)
|
||
end
|
||
|
||
--添加事件监听(用于子类重写)
|
||
function RoleGodSoulLayout:AddListener()
|
||
Game.GlobalEvent:AddEvent(GameEvent.Role.UpdateSodSoulLayout, self.SetData,self)
|
||
end
|
||
--移除事件监听(用于子类重写)
|
||
function RoleGodSoulLayout:RemoveListener()
|
||
Game.GlobalEvent:RemoveEvent(GameEvent.Role.UpdateSodSoulLayout, self.SetData,self)
|
||
end
|
||
|
||
--界面打开时调用(用于子类重写)
|
||
function RoleGodSoulLayout:OnOpen(_curHerodata)
|
||
self.curHeroData = _curHerodata
|
||
if self.curHeroData.dynamicId then
|
||
self.lv = GodSoulManager.GetGodSoulLv(self.curHeroData.dynamicId)
|
||
self.addShow = true
|
||
self.heroConfig = self.curHeroData.heroConfig
|
||
else
|
||
self.lv = 0
|
||
self.addShow = false
|
||
self.heroConfig = self.curHeroData
|
||
end
|
||
end
|
||
|
||
function RoleGodSoulLayout:OnShow()
|
||
self.gameObject:SetActive(true)
|
||
self:SetData()
|
||
end
|
||
|
||
function RoleGodSoulLayout:SetData()
|
||
self:UpdateGodList()
|
||
self:SetHeroData(self.curHeroGo,self.curHeroData,true)
|
||
self.curHeroName.text = self.heroConfig.ReadingName
|
||
local pos = Vector3.New(self.gridPos.x,self.gridPos.y,self.gridPos.z)
|
||
for i = 1,self.lv - 1 do
|
||
pos.y = pos.y + GetPreferredHeight(self.gridList[i].go.transform)
|
||
end
|
||
local pos1 = self.grid:GetComponent("RectTransform").anchoredPosition
|
||
if pos1.y ~= pos.y then
|
||
self.grid:GetComponent("RectTransform").anchoredPosition = pos
|
||
end
|
||
end
|
||
|
||
function RoleGodSoulLayout:SetHeroData(heroGo,heroData,isCur)
|
||
local frame = Util.GetGameObject(heroGo,"frame"):GetComponent("Image")
|
||
local icon = Util.GetGameObject(heroGo,"icon"):GetComponent("Image")
|
||
local proIcon = Util.GetGameObject(heroGo,"proIcon"):GetComponent("Image")
|
||
local starGrid = Util.GetGameObject(heroGo,"star")
|
||
if self.addShow then
|
||
if isCur then
|
||
local lv = Util.GetGameObject(heroGo,"lv/Text"):GetComponent("Text")
|
||
lv.text = heroData.lv
|
||
end
|
||
frame.sprite = self.spLoader:LoadSprite(GetHeroQuantityImageByquality(heroData.heroConfig.Quality,heroData.star))
|
||
proIcon.sprite = self.spLoader:LoadSprite(GetProStrImageByProNum(heroData.heroConfig.PropertyName))
|
||
SetHeroIcon(self.spLoader,heroData,icon,heroData.heroConfig)
|
||
local star,starType = heroData.GetStar(1)
|
||
local starSize = Vector2.New(30,30)
|
||
local starScale = -8
|
||
if starType == 3 then
|
||
starSize = Vector2.New(33.43,83.61)
|
||
starScale = -13.77
|
||
end
|
||
SetHeroStars(self.spLoader, starGrid, star,starType,starSize,starScale)
|
||
else
|
||
local lv = Util.GetGameObject(heroGo,"lv/Text"):GetComponent("Text")
|
||
lv.text = heroData.Level
|
||
frame.sprite = self.spLoader:LoadSprite(GetHeroQuantityImageByquality(heroData.Quality,heroData.star))
|
||
proIcon.sprite = self.spLoader:LoadSprite(GetProStrImageByProNum(heroData.PropertyName))
|
||
SetHeroIcon(self.spLoader,heroData,icon,heroData)
|
||
SetHeroStars(self.spLoader, starGrid, heroData.Star,1)
|
||
end
|
||
end
|
||
|
||
function RoleGodSoulLayout:UpdateGodList()
|
||
|
||
|
||
self.godDatas = GodSoulManager.GetGodSoulDataByLv(self.heroConfig.Id,0)
|
||
if not self.gridList then
|
||
self.gridList = {}
|
||
end
|
||
for i = 1,math.max(#self.gridList,#self.godDatas) do
|
||
if not self.godDatas[i] then
|
||
self.gridList[i].go.gameObject:SetActive(false)
|
||
else
|
||
if not self.gridList[i] then
|
||
self.gridList[i] = {}
|
||
self.gridList[i].go = newObjToParent(self.singlePre,self.grid)
|
||
self.gridList[i].tip = Util.GetGameObject(self.gridList[i].go,"middle/Text"):GetComponent("Text")
|
||
self.gridList[i].godGrid = Util.GetGameObject(self.gridList[i].go,"middle/godGrid")
|
||
self.gridList[i].godLvList = {}
|
||
self.gridList[i].costGrid = Util.GetGameObject(self.gridList[i].go,"middle/costGrid")
|
||
self.gridList[i].costList = {}
|
||
self.gridList[i].add = Util.GetGameObject(self.gridList[i].go,"add")
|
||
self.gridList[i].red = Util.GetGameObject(self.gridList[i].add,"red")
|
||
self.gridList[i].red.gameObject:SetActive(false)
|
||
self.gridList[i].des = Util.GetGameObject(self.gridList[i].go,"bottom/des"):GetComponent("Text")
|
||
self.gridList[i].upHero = Util.GetGameObject(self.gridList[i].go,"upHero")
|
||
self.gridList[i].upHeroList = {}
|
||
end
|
||
if self.addShow then
|
||
self.gridList[i].upHeroDataList = GodSoulManager.GetBindHeroDatasByLevel(self.curHeroData.dynamicId,i)
|
||
else
|
||
self.gridList[i].upHeroDataList = {}
|
||
end
|
||
self.gridList[i].go.gameObject:SetActive(true)
|
||
self:UpdataSingleGod(i)
|
||
end
|
||
end
|
||
end
|
||
|
||
--index 等级
|
||
function RoleGodSoulLayout:UpdataSingleGod(index)
|
||
for i = 1,math.max(#self.gridList[index].godLvList,index) do
|
||
if index < i then
|
||
self.gridList[index].godLvList[i].gameObject:SetActive(false)
|
||
else
|
||
if not self.gridList[index].godLvList[i] then
|
||
self.gridList[index].godLvList[i] = newObjToParent(self.godPre,self.gridList[index].godGrid)
|
||
end
|
||
self.gridList[index].godLvList[i].gameObject:SetActive(true)
|
||
end
|
||
end
|
||
--绿色
|
||
self.gridList[index].tip.text = string.format("<color=#B5AA95>需要:</color>")
|
||
local godDatasByLv = GodSoulManager.MergeGodSoulDataByLv(self.heroConfig.Id,index)
|
||
for i = 1,math.max(#self.gridList[index].costList,#godDatasByLv) do
|
||
if not godDatasByLv[i] then
|
||
self.gridList[index].costList[i].go.gameObject:SetActive(false)
|
||
else
|
||
if not self.gridList[index].costList[i] then
|
||
self.gridList[index].costList[i] = {}
|
||
self.gridList[index].costList[i].go = newObjToParent(self.costPre,self.gridList[index].costGrid)
|
||
self.gridList[index].costList[i].frame = Util.GetGameObject(self.gridList[index].costList[i].go,"frame"):GetComponent("Image")
|
||
self.gridList[index].costList[i].icon = Util.GetGameObject(self.gridList[index].costList[i].frame.transform,"icon"):GetComponent("Image")
|
||
self.gridList[index].costList[i].num = Util.GetGameObject(self.gridList[index].costList[i].go,"num"):GetComponent("Text")
|
||
end
|
||
self.gridList[index].costList[i].go.gameObject:SetActive(true)
|
||
|
||
if godDatasByLv[i].id > 0 then
|
||
if godDatasByLv[i].star > 10 then
|
||
self.gridList[index].costList[i].frame.sprite = self.spLoader:LoadSprite("s_shenhunxitong_zuanshitouxiangkuang")
|
||
else
|
||
self.gridList[index].costList[i].frame.sprite = self.spLoader:LoadSprite("s_shenhunxitong_hong")
|
||
end
|
||
self.gridList[index].costList[i].icon.gameObject:SetActive(true)
|
||
self.gridList[index].costList[i].icon.sprite = self.spLoader:LoadSprite(GetResourcePath(heroConfig[godDatasByLv[i].id].Icon))
|
||
elseif godDatasByLv[i].property > 0 then
|
||
self.gridList[index].costList[i].icon.gameObject:SetActive(false)
|
||
self.gridList[index].costList[i].frame.sprite = self.spLoader:LoadSprite(PropertySmallIcon[godDatasByLv[i].star][godDatasByLv[i].property])
|
||
elseif godDatasByLv[i].profession > 0 then
|
||
self.gridList[index].costList[i].icon.gameObject:SetActive(false)
|
||
self.gridList[index].costList[i].frame.sprite = self.spLoader:LoadSprite(GodSoulProfession[godDatasByLv[i].star][godDatasByLv[i].profession])
|
||
else
|
||
self.gridList[index].costList[i].icon.gameObject:SetActive(false)
|
||
self.gridList[index].costList[i].frame.sprite = self.spLoader:LoadSprite(StarImage[godDatasByLv[i].star])
|
||
end
|
||
if not self.addShow then
|
||
self.gridList[index].costList[i].num.text = string.format("<color=#B5AA95>×%s</color>",godDatasByLv[i].num)
|
||
Util.SetGray(self.gridList[index].costList[i].frame.gameObject,false)
|
||
elseif index >= self.lv + 1 then --未激活时红色,图标置灰
|
||
self.gridList[index].costList[i].num.text = string.format("<color=#FF0000>×%s</color>",godDatasByLv[i].num)
|
||
Util.SetGray(self.gridList[index].costList[i].frame.gameObject,true)
|
||
else --激活时绿色,图标不置灰
|
||
self.gridList[index].costList[i].num.text = string.format("<color=#00FF00>×%s</color>",godDatasByLv[i].num)
|
||
Util.SetGray(self.gridList[index].costList[i].frame.gameObject,false)
|
||
end
|
||
end
|
||
end
|
||
|
||
if self.addShow then
|
||
if #self.gridList[index].upHeroDataList < 1 then
|
||
self.gridList[index].upHero.gameObject:SetActive(false)
|
||
else
|
||
self.gridList[index].upHero.gameObject:SetActive(true)
|
||
for i = 1,math.max(#self.gridList[index].upHeroList,#self.gridList[index].upHeroDataList) do
|
||
if not self.gridList[index].upHeroDataList[i] then
|
||
self.gridList[index].upHeroList[i].gameObject:SetActive(false)
|
||
else
|
||
if not self.gridList[index].upHeroList[i] then
|
||
self.gridList[index].upHeroList[i] = newObjToParent(self.heroPre,self.gridList[index].upHero)
|
||
end
|
||
self.gridList[index].upHeroList[i].gameObject:SetActive(true)
|
||
local tempHeroData = HeroManager.GetSingleHeroData(self.gridList[index].upHeroDataList[i])
|
||
self:SetHeroData(self.gridList[index].upHeroList[i],tempHeroData,false)
|
||
Util.AddOnceClick(self.gridList[index].upHeroList[i],function()
|
||
UIManager.OpenPanel(UIName.GeneralBigPopup,GENERAL_POPUP_TYPE.ShenHun,self.godDatas[index],self.curHeroData,index,i)
|
||
end)
|
||
end
|
||
end
|
||
end
|
||
else
|
||
self.gridList[index].upHero.gameObject:SetActive(false)
|
||
end
|
||
|
||
self.gridList[index].red.gameObject:SetActive(false)
|
||
if not self.addShow then
|
||
self.gridList[index].add.gameObject:SetActive(false)
|
||
Util.SetGray(self.gridList[index].godGrid,false)
|
||
--Util.SetGray(self.gridList[index].des.gameObject,false)
|
||
self.gridList[index].des.text = string.format("<color=#B5AA95>%s</color>",self.godDatas[index].skill) --神魂效果 绿色 未激活时置灰
|
||
elseif index <= self.lv + 1 then
|
||
self.gridList[index].add.gameObject:SetActive(true)
|
||
if index == self.lv + 1 then
|
||
Util.SetGray(self.gridList[index].godGrid,true) --勾魂图标 未激活时置灰
|
||
--Util.SetGray(self.gridList[index].des.gameObject,true)
|
||
self.gridList[index].des.text = string.format("<color=#B5AA95>%s</color>",self.godDatas[index].skill) --神魂效果 绿色 未激活时置灰
|
||
local isShow = GodSoulManager.CheckRedPointGodSoul(self.curHeroData) or false
|
||
self.gridList[index].red.gameObject:SetActive(isShow)
|
||
else
|
||
Util.SetGray(self.gridList[index].godGrid,false)
|
||
--Util.SetGray(self.gridList[index].des.gameObject,false)
|
||
self.gridList[index].des.text = string.format("<color=#00FF00>%s</color>",self.godDatas[index].skill) --神魂效果 绿色 未激活时置灰
|
||
end
|
||
Util.SetGray(self.gridList[index].add,false)
|
||
else
|
||
self.gridList[index].add.gameObject:SetActive(true)
|
||
--红色
|
||
Util.SetGray(self.gridList[index].godGrid,true)
|
||
--Util.SetGray(self.gridList[index].des.gameObject,true)
|
||
self.gridList[index].des.text = string.format("<color=#B5AA95>%s</color>",self.godDatas[index].skill) --神魂效果 绿色 未激活时置灰
|
||
Util.SetGray(self.gridList[index].add,true)
|
||
end
|
||
|
||
Util.AddOnceClick(self.gridList[index].add,function()
|
||
if index <= self.lv + 1 then
|
||
UIManager.OpenPanel(UIName.GeneralBigPopup,GENERAL_POPUP_TYPE.ShenHun,self.godDatas[index],self.curHeroData,index)
|
||
else
|
||
PopupTipPanel.ShowTip("需要激活上一个神魂才可解锁!")
|
||
end
|
||
end)
|
||
end
|
||
|
||
function RoleGodSoulLayout:OnHide()
|
||
self.gameObject:SetActive(false)
|
||
end
|
||
|
||
function RoleGodSoulLayout:OnDestroy()
|
||
self.gridList = {}
|
||
end
|
||
|
||
function RoleGodSoulLayout:OnClose()
|
||
self.gameObject:SetActive(false)
|
||
end
|
||
|
||
return RoleGodSoulLayout |