miduo_client/Assets/ManagedResources/~Lua/Modules/CompoundHero/CompoundHeroFirstUpStarList...

245 lines
11 KiB
Lua

require("Base/BasePanel")
CompoundHeroFirstUpStarListPanel = Inherit(BasePanel)
local this = CompoundHeroFirstUpStarListPanel
local curSelectHeroList={}
local heroDataList={}
local curNeedRoleNum
local openThisPanel
local curHeroData = {}
--初始化组件(用于子类重写)
function CompoundHeroFirstUpStarListPanel:InitComponent()
this.spLoader = SpriteLoader.New()
this.BtnBack = Util.GetGameObject(self.transform, "btnBack")
this.BtnSure = Util.GetGameObject(self.transform, "btnSure")
this.btnAutoSelect = Util.GetGameObject(self.transform, "btnAutoSelect")
this.cardPre = Util.GetGameObject(self.gameObject, "item")
--this.grid = Util.GetGameObject(self.gameObject, "scroll/grid")
this.desText = Util.GetGameObject(self.gameObject, "desText"):GetComponent("Text")
this.numText = Util.GetGameObject(self.gameObject, "numText"):GetComponent("Text")
local v = Util.GetGameObject(self.gameObject, "scroll"):GetComponent("RectTransform").rect
this.Scrollbar= Util.GetGameObject(self.gameObject, "Scrollbar"):GetComponent("Scrollbar")
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView,Util.GetGameObject(self.gameObject, "scroll").transform,
this.cardPre, this.Scrollbar, Vector2.New(v.width, v.height), 1, 5, Vector2.New(20,50))
this.ScrollView.gameObject:GetComponent("RectTransform").anchoredPosition = Vector2.New(6.78, 27)
this.ScrollView.gameObject:GetComponent("RectTransform").anchorMin = Vector2.New(0.5, 0.5)
this.ScrollView.gameObject:GetComponent("RectTransform").anchorMax = Vector2.New(0.5, 0.5)
this.ScrollView.moveTween.MomentumAmount = 1
this.ScrollView.moveTween.Strength = 1
this.NoneImage= Util.GetGameObject(self.gameObject, "NoneImage")
this.NoneImage.gameObject:SetActive(false)
end
--绑定事件(用于子类重写)
function CompoundHeroFirstUpStarListPanel:BindEvent()
Util.AddClick(this.BtnBack, function()
-- PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
self:ClosePanel()
end)
Util.AddClick(this.BtnSure, function()
if LengthOfTable(curSelectHeroList) < 1 then
return
end
self:ClosePanel()
Log("curSelectHeroList "..LengthOfTable(curSelectHeroList))
openThisPanel.UpdateUpStarPosHeroData2(curSelectHeroList)
end)
Util.AddClick(this.btnAutoSelect, function()
self:AutoSelectHero()
end)
end
--添加事件监听(用于子类重写)
function CompoundHeroFirstUpStarListPanel:AddListener()
end
--移除事件监听(用于子类重写)
function CompoundHeroFirstUpStarListPanel:RemoveListener()
end
--界面打开时调用(用于子类重写)
--1 是否是第一位置本体 2 所有可选英雄 3 4 升当前星的规则 5 打开RoleUpStarListPanel的界面 6 当前以选择的英雄 7 需要升级的英雄
function CompoundHeroFirstUpStarListPanel:OnOpen(heroData,_openThisPanel,_curHeroData)
openThisPanel= _openThisPanel
curHeroData = _curHeroData
heroDataList = heroData
curSelectHeroList = {}
if _curHeroData.dynamicId then curSelectHeroList[_curHeroData.dynamicId] = _curHeroData end
this.HeroSortData(heroDataList)
-- for i, v in pairs(heroDataList) do
-- for n,w in pairs(FormationManager.formationList) do
-- if HeroManager.heroResolveLicence[n] then
-- for m = 1, #w.teamHeroInfos do
-- if v.dynamicId==w.teamHeroInfos[m].heroId then
-- local isFormationStr = HeroManager.GetHeroFormationStr(n)
-- v.isFormation = isFormationStr
-- end
-- end
-- end
-- end
-- end
if not heroDataList or #heroDataList < 1 then
this.NoneImage.gameObject:SetActive(true)
else
this.NoneImage.gameObject:SetActive(false)
end
this.ScrollView:SetData(heroDataList, function (index, go)
this.OnShowSingleCardData(go, heroDataList[index])
end)
curNeedRoleNum=1
local str = _curHeroData.heroConfig and GetLanguageStrById(_curHeroData.heroConfig.ReadingName) or GetLanguageStrById(_curHeroData.ReadingName)
this.desText.text=string.format(Language[10402],curNeedRoleNum,str)--HeroRankupGroupData.Name)
this.numText.text=string.format("%s/%s",LengthOfTable(curSelectHeroList) ,curNeedRoleNum)
end
function this.OnClickEnterHero(go,heroData,type)
if type==1 then
if LengthOfTable(curSelectHeroList)>=curNeedRoleNum then
PopupTipPanel.ShowTip(Language[10403])
return
else
curSelectHeroList[heroData.dynamicId] = heroData.dynamicId
end
elseif type==2 then
if curSelectHeroList[heroData.dynamicId] then
curSelectHeroList[heroData.dynamicId] = nil
end
-- for i = 1, #curSelectHeroList do
-- if heroData.dynamicId==curSelectHeroList[i].dynamicId then
-- table.remove(curSelectHeroList,i)
-- break
-- end
-- end
end
this.OnShowSingleCardData(go,heroData,type)
this.numText.text=string.format("%s/%s",LengthOfTable(curSelectHeroList),curNeedRoleNum)
end
local oldSelectGo
function this.OnShowSingleCardData(go,heroData)--isSelect 1选择 2 没选择
local choosed = Util.GetGameObject(go.transform, "choosed")
choosed:SetActive(false)
if curSelectHeroList[heroData.dynamicId] then
curSelectHeroList[heroData.dynamicId]=heroData
choosed:SetActive(true)
oldSelectGo = choosed
end
Util.GetGameObject(go.transform, "frame"):GetComponent("Image").sprite = this.spLoader:LoadSprite(GetHeroQuantityImageByquality(heroData.heroConfig.Quality,heroData.star))
Util.GetGameObject(go.transform, "lv/Text"):GetComponent("Text").text = heroData.lv
Util.GetGameObject(go.transform, "icon"):GetComponent("Image").sprite = this.spLoader:LoadSprite(heroData.icon)
Util.GetGameObject(go.transform, "posIcon"):SetActive(false)--:GetComponent("Image").sprite = this.spLoader:LoadSprite(heroData.professionIcon)
Util.GetGameObject(go.transform, "proIcon"):GetComponent("Image").sprite = this.spLoader:LoadSprite(GetProStrImageByProNum(heroData.changeProId))
local formationMask = Util.GetGameObject(go.transform, "formationMask")
-- formationMask:SetActive(false)
formationMask:SetActive(false)-- LengthOfTable(heroData.formationList) ~= 0 or heroData.lockState == 1)
Util.GetGameObject(formationMask.transform, "formationImage"):SetActive(false)--(LengthOfTable(heroData.formationList) ~= 0 )
Util.GetGameObject(formationMask.transform, "lockImage"):SetActive(false)--( heroData.lockState == 1)
Util.GetGameObject(go.transform, "noumenon"):SetActive( heroData.id == curHeroData.id )
Util.GetGameObject(go.transform, "name"):GetComponent("Text").text = heroData.heroConfig.ReadingName
local starGrid = Util.GetGameObject(go.transform, "star")
local star,starType = heroData.GetStar(1)
SetHeroStars(this.spLoader, starGrid, star,starType,nil,nil,Vector2.New(0,1))
SetHeroFlyEffect(go,this.spLoader,heroData.star,this.sortingOrder + 1,1,2)
Util.SetParticleSortLayer(starGrid,this.sortingOrder + 1)
local cardBtn = Util.GetGameObject(go.transform, "icon")
local GongMingMask = Util.GetGameObject(go.transform, "GongMingMask")
GongMingMask:SetActive(false)--最后检测是否共鸣
Util.AddOnceClick(cardBtn, function()
if curSelectHeroList[heroData.dynamicId] then
choosed:SetActive(false)
curSelectHeroList[heroData.dynamicId]=nil
this.numText.text=string.format("%s/%s",LengthOfTable(curSelectHeroList),curNeedRoleNum)
return
end
-- if LengthOfTable(curSelectHeroList)>=curNeedRoleNum then
-- PopupTipPanel.ShowTip("已达最大选择数量")
-- return
-- end
if oldSelectGo then
oldSelectGo:SetActive(false)
end
curSelectHeroList = {}
curSelectHeroList[heroData.dynamicId]=heroData
choosed:SetActive(true)
oldSelectGo = choosed
this.numText.text=string.format("%s/%s",LengthOfTable(curSelectHeroList),curNeedRoleNum)
end)
Util.AddLongPressClick(cardBtn, function()
UIManager.OpenPanel(UIName.RoleInfoPopup,heroData)
end, 0.5)
-- Util.AddOnceClick(formationMask, function()
-- if #heroData.formationList ~= 0 then
-- local text = ""
-- for index, value in ipairs(heroData.formationList) do
-- text = HeroManager.GetHeroFormationStr(index)
-- end
-- PopupTipPanel.ShowTip(text)
-- return
-- end
-- if heroData.lockState == 1 then
-- PopupTipPanel.ShowTip("该神将已锁定")
-- return
-- end
-- end)
end
function this.HeroSortData(heroData)
-- Log("#heroData "..#heroData)
--"该神将在大闹天宫阵容中已上阵"
table.sort(heroData, function(a, b)
-- if (LengthOfTable( a.formationList) == 0 and LengthOfTable( b.formationList) == 0)
-- or (LengthOfTable(a.formationList) > 0) and (LengthOfTable(b.formationList) > 0) then
-- if a.lockState == b.lockState then
-- if a.heroConfig.Star == b.heroConfig.Star then
-- if a.lv == b.lv then
-- -- if a.id ~= curHeroData.Id and b.id ~= curHeroData.Id or a.id == curHeroData.Id and b.id == curHeroData.Id then
-- return a.id > b.id
-- -- else
-- -- return not a.id ~= curHeroData.Id and b.id == curHeroData.Id
-- -- end
-- else
return a.lv > b.lv
-- end
-- else
-- return a.heroConfig.Star < b.heroConfig.Star
-- end
-- else
-- return a.lockState < b.lockState
-- end
-- else
-- return LengthOfTable( a.formationList) == 0 and LengthOfTable(b.formationList) > 0
-- end
end)
end
--一键放入
function CompoundHeroFirstUpStarListPanel:AutoSelectHero()
curSelectHeroList = {}
for i = 1, #heroDataList do
if LengthOfTable(curSelectHeroList) < curNeedRoleNum and LengthOfTable(heroDataList[i].formationList) == 0 and heroDataList[i].lockState == 0 then--
curSelectHeroList[heroDataList[i].dynamicId]=heroDataList[i]
end
end
this.numText.text=string.format("%s/%s",LengthOfTable(curSelectHeroList),curNeedRoleNum)
this.ScrollView:SetData(heroDataList, function (index, go)
this.OnShowSingleCardData(go, heroDataList[index])
end)
end
--界面关闭时调用(用于子类重写)
function CompoundHeroFirstUpStarListPanel:OnClose()
end
--界面销毁时调用(用于子类重写)
function CompoundHeroFirstUpStarListPanel:OnDestroy()
this.spLoader:Destroy()
this.ScrollView = nil
end
return CompoundHeroFirstUpStarListPanel