364 lines
14 KiB
Lua
364 lines
14 KiB
Lua
require("Base/BasePanel")
|
|
HandBookHeroAndEquipListPanel = Inherit(BasePanel)
|
|
|
|
local OpenType = 0 --1 英雄 2装备 3 法宝
|
|
|
|
local proId=0--0 全部 1 火 2风 3 水 4 地 5 光 6 暗
|
|
local tabs = {}
|
|
local orginLayer = 0
|
|
local orginLayer2 = 0
|
|
|
|
local gridListData = {}
|
|
local heroNumList = {}
|
|
--初始化组件(用于子类重写)
|
|
function HandBookHeroAndEquipListPanel:InitComponent()
|
|
|
|
self.btnBack = Util.GetGameObject(self.transform, "btnBack")
|
|
|
|
--英雄
|
|
self.heroScroll = Util.GetGameObject(self.transform, "heroScroll")
|
|
self.heroScrollbar = Util.GetGameObject(self.transform, "heroScrollbar")
|
|
self.heroScrollbar.gameObject:SetActive(false)
|
|
self.card = poolManager:LoadAsset("card", PoolManager.AssetType.GameObject)
|
|
self.card.transform:SetParent(self.transform)
|
|
self.card:GetComponent("RectTransform").localScale = Vector3.New(1,1,1)
|
|
Util.GetGameObject(self.card, "choosed").gameObject:SetActive(false)
|
|
Util.GetGameObject(self.card, "redAndLock").gameObject:SetActive(false)
|
|
|
|
self.starNum = Util.GetGameObject(self.transform, "starNum")
|
|
self.heroprefab = Util.GetGameObject(self.transform, "heroprefab")
|
|
self.scrollRoot = Util.GetGameObject(self.transform, "heroScroll")
|
|
local rootHight = self.scrollRoot.transform.rect.height
|
|
local sv = SubUIManager.Open(SubUIConfig.ScrollFitterView, self.scrollRoot.transform,
|
|
self.heroprefab, Vector2.New(1080, rootHight - 10), 1, 0)
|
|
sv.gameObject:GetComponent("RectTransform").anchoredPosition = Vector2.New(0, -5)
|
|
-- 保存
|
|
sv.moveTween.Strength = 5
|
|
self.SystemScrollView = sv
|
|
|
|
--self.BtView = SubUIManager.Open(SubUIConfig.BtView, self.gameObject.transform)
|
|
--self.BtView2 = SubUIManager.Open(SubUIConfig.BtView2, self.gameObject.transform)
|
|
self.UpView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform)
|
|
|
|
self.selectBtn = Util.GetGameObject(self.gameObject, "Tabs/selectBtn")
|
|
Util.GetGameObject(self.transform, "Tabs/grid/Btn" .. 0):SetActive(false)
|
|
for i = 1, 6 do
|
|
tabs[i] = Util.GetGameObject(self.transform, "Tabs/grid/Btn" .. i)
|
|
end
|
|
self.Tabs = Util.GetGameObject(self.gameObject, "Tabs")
|
|
end
|
|
|
|
--绑定事件(用于子类重写)·
|
|
function HandBookHeroAndEquipListPanel:BindEvent()
|
|
|
|
Util.AddClick(self.btnBack, function()
|
|
self:ClosePanel()
|
|
end)
|
|
for i = 1, 6 do
|
|
Util.AddClick(tabs[i], function()
|
|
if i ~= proId then
|
|
proId=i
|
|
end
|
|
self:OnShowHeroFun()
|
|
end)
|
|
end
|
|
end
|
|
--添加事件监听(用于子类重写)
|
|
function HandBookHeroAndEquipListPanel:AddListener()
|
|
|
|
end
|
|
--移除事件监听(用于子类重写)
|
|
function HandBookHeroAndEquipListPanel:RemoveListener()
|
|
|
|
end
|
|
--界面打开时调用(用于子类重写)
|
|
function HandBookHeroAndEquipListPanel:OnOpen(_type)
|
|
|
|
-- proId=ProIdConst.All
|
|
OpenType = _type
|
|
--self.BtView:OnOpen({ sortOrder = self.sortingOrder, panelType = PanelTypeView.RolePanel })
|
|
--self.BtView2:OnOpen({ sortOrder = self.sortingOrder, panelType = PanelTypeView2.HandBookPanel })
|
|
self.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.Main })
|
|
end
|
|
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
|
|
function HandBookHeroAndEquipListPanel:OnShow()
|
|
proId = PlayerManager.headBookListTag
|
|
if OpenType == 1 then
|
|
self.heroScroll:SetActive(true)
|
|
self.heroScrollbar:SetActive(false)
|
|
self.Tabs:SetActive(true)
|
|
-- proId=ProIdConst.All
|
|
self:OnShowHeroFun()
|
|
end
|
|
end
|
|
--界面关闭时调用(用于子类重写)
|
|
function HandBookHeroAndEquipListPanel:OnClose()
|
|
|
|
end
|
|
--界面销毁时调用(用于子类重写)
|
|
function HandBookHeroAndEquipListPanel:OnDestroy()
|
|
|
|
SubUIManager.Close(self.UpView)
|
|
--SubUIManager.Close(self.BtView)
|
|
--SubUIManager.Close(self.BtView2)
|
|
end
|
|
function HandBookHeroAndEquipListPanel:OnSortingOrderChange()
|
|
|
|
orginLayer = self.sortingOrder
|
|
end
|
|
|
|
function HandBookHeroAndEquipListPanel:Clone(_t)
|
|
local res = {}
|
|
res = _t
|
|
return res
|
|
end
|
|
|
|
|
|
function HandBookHeroAndEquipListPanel:GetHeroData()
|
|
--得到所有的对应星级的英雄
|
|
local tenHeroList = {}
|
|
local sexHeroList = {}
|
|
local fiveHeroList = {}
|
|
local fourHeroList = {}
|
|
local threeHeroList = {}
|
|
local twoHeroList = {}
|
|
local oneHeroList = {}
|
|
for id, v in ConfigPairs(ConfigManager.GetConfig(ConfigName.HeroConfig)) do
|
|
--5星最高星级是10的要在十星里面显示出来
|
|
if v.Star == 5 and v.MaxRank >= 10 and (proId == 0 or v.PropertyName == proId) then
|
|
table.insert(tenHeroList,v)
|
|
end
|
|
--所有的5星都要在六星里面显示出来
|
|
if v.Star == 5 and (proId == 0 or v.PropertyName == proId) then
|
|
table.insert(fiveHeroList,v)
|
|
table.insert(sexHeroList,v)
|
|
elseif v.Star >= 4 and (proId == 0 or v.PropertyName == proId) then
|
|
table.insert(fourHeroList,v)
|
|
elseif v.Star >= 3 and (proId == 0 or v.PropertyName == proId) then
|
|
table.insert(threeHeroList,v)
|
|
elseif v.Star >= 2 and (proId == 0 or v.PropertyName == proId) then
|
|
table.insert(twoHeroList,v)
|
|
elseif v.Star >= 1 and (proId == 0 or v.PropertyName == proId) then
|
|
table.insert(oneHeroList,v)
|
|
end
|
|
end
|
|
self:SortHeroNatural(tenHeroList)
|
|
self:SortHeroNatural(sexHeroList)
|
|
self:SortHeroNatural(fiveHeroList)
|
|
self:SortHeroNatural(fourHeroList)
|
|
self:SortHeroNatural(threeHeroList)
|
|
self:SortHeroNatural(twoHeroList)
|
|
self:SortHeroNatural(oneHeroList)
|
|
--设置图鉴的循环列表
|
|
local herodatas={}
|
|
herodatas[10]=tenHeroList
|
|
herodatas[6]=sexHeroList
|
|
herodatas[5]=fiveHeroList
|
|
herodatas[4]=fourHeroList
|
|
herodatas[3]=threeHeroList
|
|
herodatas[2]=twoHeroList
|
|
herodatas[1]=oneHeroList
|
|
PlayerManager.heroHandBookListData = herodatas
|
|
|
|
local heroScrolldatas = {}
|
|
self:HeroHaveNum()
|
|
local temp = 0
|
|
for k,v in pairs(herodatas) do
|
|
temp = 0
|
|
if v and #v > 0 then
|
|
--LogGreen("star:"..k.." heroCount:"..#v.." HeroHaveNum:"..heroNumList[k])
|
|
local str = Language[11096]..heroNumList[k].."/"..#v
|
|
table.insert(heroScrolldatas,{type = 2,star = k,index = 0,content = str })
|
|
for i = 1,#v do
|
|
if i%5 == 0 or i == #v then
|
|
local tempData = {}
|
|
for n = temp + 1, i do
|
|
table.insert(tempData,v[n])
|
|
--LogBlue("v[n].id:"..v[n].Id)
|
|
end
|
|
if i%5 ==0 then
|
|
table.insert(heroScrolldatas,{type = 1,star = k,index = math.floor(i/5), content = tempData})
|
|
else
|
|
table.insert(heroScrolldatas,{type = 1,star = k,index = math.floor(i/5) + 1, content = tempData})
|
|
end
|
|
temp = i
|
|
end
|
|
end
|
|
end
|
|
end
|
|
table.sort(heroScrolldatas,function(a,b)
|
|
if a.star == b.star then
|
|
if a.type == b.type then
|
|
return a.index < b.index
|
|
else
|
|
return a.type > b.type
|
|
end
|
|
else
|
|
return a.star > b.star
|
|
end
|
|
end)
|
|
-- for k,v in ipairs(heroScrolldatas) do
|
|
-- if v.content and v.type ==1 then
|
|
-- LogPink("star:"..v.star.." heroCount:"..#v.content.." index:"..v.index)
|
|
-- for n,m in ipairs(v.content) do
|
|
-- LogYellow("m.Id:"..m.Id.."m.Star:"..m.Star)
|
|
-- end
|
|
-- end
|
|
-- end
|
|
return heroScrolldatas
|
|
end
|
|
|
|
function HandBookHeroAndEquipListPanel:HeroHaveNum()
|
|
local curtenStarActiveNum = 0
|
|
local cursexStarActiveNum = 0
|
|
local curfiveStarActiveNum = 0
|
|
local curfourStarActiveNum = 0
|
|
local curthreeStarActiveNum = 0
|
|
local curtwoStarActiveNum = 0
|
|
local curoneStarActiveNum = 0
|
|
--计算玩家拥有的英雄中对应星级的英雄的数量
|
|
for i, v in pairs(PlayerManager.heroHandBook) do
|
|
local conFig = ConfigManager.GetConfigData(ConfigName.HeroConfig,i)
|
|
if conFig then
|
|
if PlayerManager.GetHeroDataByStar(10,conFig.Id) and (proId == 0 or conFig.PropertyName == proId) then
|
|
curtenStarActiveNum = curtenStarActiveNum + 1
|
|
end
|
|
if PlayerManager.GetHeroDataByStar(6,conFig.Id) and (proId == 0 or conFig.PropertyName == proId) then
|
|
cursexStarActiveNum = cursexStarActiveNum + 1
|
|
end
|
|
if conFig.Star == 5 and (proId == 0 or conFig.PropertyName == proId) then
|
|
curfiveStarActiveNum = curfiveStarActiveNum + 1
|
|
elseif conFig.Star == 4 and (proId == 0 or conFig.PropertyName == proId) then
|
|
curfourStarActiveNum = curfourStarActiveNum + 1
|
|
elseif conFig.Star == 3 and (proId == 0 or conFig.PropertyName == proId) then
|
|
curthreeStarActiveNum = curthreeStarActiveNum + 1
|
|
elseif conFig.Star == 2 and (proId == 0 or conFig.PropertyName == proId) then
|
|
curtwoStarActiveNum = curtwoStarActiveNum + 1
|
|
elseif conFig.Star == 1 and (proId == 0 or conFig.PropertyName == proId) then
|
|
curoneStarActiveNum = curoneStarActiveNum + 1
|
|
end
|
|
end
|
|
end
|
|
heroNumList[1] = curoneStarActiveNum
|
|
heroNumList[2] = curtwoStarActiveNum
|
|
heroNumList[3] = curthreeStarActiveNum
|
|
heroNumList[4] = curfourStarActiveNum
|
|
heroNumList[5] = curfiveStarActiveNum
|
|
heroNumList[6] = cursexStarActiveNum
|
|
heroNumList[10] = curtenStarActiveNum
|
|
end
|
|
|
|
--英雄展示
|
|
function HandBookHeroAndEquipListPanel:OnShowHeroFun()
|
|
self:SetSelectBtn()
|
|
local data = self:GetHeroData()
|
|
local prefabs = {}
|
|
self.SystemScrollView:SetData(data, function(dataIndex, go)
|
|
--LogYellow("dataIndex:"..dataIndex)
|
|
self:showData(go,data[dataIndex],prefabs)
|
|
end,1)
|
|
|
|
orginLayer2 =self.sortingOrder
|
|
orginLayer = self.sortingOrder
|
|
end
|
|
|
|
--生成不同类型图鉴预制的通用方法
|
|
function HandBookHeroAndEquipListPanel:GeneralNewGoPre(_type,_index,_grid)
|
|
local go
|
|
if _type == 1 then
|
|
go=newObject(self.card)
|
|
go.transform:SetParent(_grid.transform)
|
|
go.transform.localScale = Vector3.one
|
|
go.transform.localPosition=Vector3.zero;
|
|
go.gameObject.name = "card (".._index..")"
|
|
end
|
|
return go
|
|
end
|
|
|
|
function HandBookHeroAndEquipListPanel:showData(go,data)
|
|
local star = Util.GetGameObject(go.transform, "star")
|
|
star.gameObject:SetActive(false)
|
|
local item = Util.GetGameObject(go.transform, "singleItem")
|
|
item.gameObject:SetActive(false)
|
|
if data.type == 2 then
|
|
star.gameObject:SetActive(true)
|
|
SetHeroStars(star,data.star,1,Vector2.New(71,71),-14,Vector2(0.5,0.5))
|
|
Util.GetGameObject(go.transform, "star/Text"):GetComponent("Text").text = data.content
|
|
else
|
|
item.gameObject:SetActive(true)
|
|
local prefabs = {}
|
|
for i = 1,5 do
|
|
local _go = Util.GetGameObject(item, "card"..i)
|
|
if i <= #data.content then
|
|
self:OnShowSingleHeroData(_go,data.content[i],data.star)
|
|
_go.gameObject:SetActive(false)
|
|
table.insert(prefabs,_go)
|
|
else
|
|
_go.gameObject:SetActive(false)
|
|
end
|
|
end
|
|
SecTorPlayAnim(prefabs)
|
|
end
|
|
end
|
|
|
|
--设置猎妖师数据
|
|
function HandBookHeroAndEquipListPanel:OnShowSingleHeroData(...)
|
|
local param = {...}
|
|
local heroData = param[2]
|
|
local _go=param[1]
|
|
local star=heroData.Star
|
|
local lv = 1
|
|
if(param[3]) then
|
|
star=param[3]
|
|
end
|
|
if star == 6 then
|
|
lv = 145
|
|
elseif star == 10 then
|
|
lv = 155
|
|
else
|
|
lv = 1
|
|
end
|
|
Util.GetGameObject(_go.transform, "card/choosed").gameObject:SetActive(false)
|
|
Util.GetGameObject(_go.transform, "card/redAndLock").gameObject:SetActive(false)
|
|
SetHeroBg(Util.GetGameObject(_go.transform, "card"), Util.GetGameObject(_go.transform, "card/bg"),star,heroData.Quality)
|
|
|
|
Util.GetGameObject(_go.transform, "card/lv/Text"):GetComponent("Text").text = lv
|
|
|
|
Util.GetGameObject(_go.transform, "card/name"):GetComponent("Text").text = heroData.ReadingName
|
|
Util.GetGameObject(_go.transform, "card/icon"):GetComponent("Image").sprite = Util.LoadSprite(GetResourcePath(heroData.Painting))
|
|
Util.GetGameObject(_go.transform, "card/pro/Image"):GetComponent("Image").sprite = Util.LoadSprite(GetProStrImageByProNum(heroData.PropertyName))
|
|
Util.GetGameObject(_go.transform, "card/heroStage"):SetActive(false)
|
|
local starGrid = Util.GetGameObject(_go.transform, "star")
|
|
SetHeroStars(starGrid, star,1,nil,-15,nil,Vector3.New(0,0,-15))
|
|
Util.AddOnceClick(Util.GetGameObject(_go.transform, "card"), function()
|
|
UIManager.OpenPanel(UIName.HandBookHeroInfoPanel,heroData,proId,star)
|
|
end)
|
|
|
|
if PlayerManager.GetHeroDataByStar(star,heroData.Id) then
|
|
Util.SetGray(Util.GetGameObject(_go.transform, "card/icon"), false)
|
|
Util.SetGray(Util.GetGameObject(_go.transform, "card/pro/Image"), false)
|
|
Util.GetGameObject(_go.transform, "card"):GetComponent("Image").material = nil
|
|
else
|
|
Util.SetGray(Util.GetGameObject(_go.transform, "card/icon"), true)
|
|
Util.SetGray(Util.GetGameObject(_go.transform, "card/pro/Image"), true)
|
|
Util.GetGameObject(_go.transform, "card"):GetComponent("Image").material = Util.GetGameObject(_go.transform, "card/icon"):GetComponent("Image").material
|
|
end
|
|
end
|
|
|
|
--设置选中按钮
|
|
function HandBookHeroAndEquipListPanel:SetSelectBtn()
|
|
PlayerManager.headBookListTag = proId
|
|
-- self.selectBtn:SetActive(proId ~= ProIdConst.All)
|
|
self.selectBtn.transform:SetParent(tabs[proId].transform)
|
|
self.selectBtn.transform.localPosition = Vector3.zero
|
|
end
|
|
function HandBookHeroAndEquipListPanel:SortHeroNatural(heroList)
|
|
table.sort(heroList, function(a, b)
|
|
if a.Natural == b.Natural then
|
|
return a.Id < b.Id
|
|
else
|
|
return a.Natural > b.Natural
|
|
end
|
|
end)
|
|
end
|
|
return HandBookHeroAndEquipListPanel |