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

409 lines
19 KiB
Lua

require("Base/BasePanel")
RoleUpStarListPanel = Inherit(BasePanel)
local this = RoleUpStarListPanel
local curSelectHeroList={}
local heroDataList={}
local curNeedRoleNum
local openThisPanel
local curHeroData = {}
--初始化组件(用于子类重写)
function RoleUpStarListPanel:InitComponent()
this.spLoader = SpriteLoader.New()
this.BtnBack = Util.GetGameObject(self.gameObject, "btnBack")
this.mask = Util.GetGameObject(self.gameObject, "mask")
this.BtnSure = Util.GetGameObject(self.gameObject, "btnSure")
this.btnAutoSelect = Util.GetGameObject(self.gameObject, "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
--LogGreen("v.width:".. v.width.." v.height:"..v.height)
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(19.32,40))
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 RoleUpStarListPanel:BindEvent()
Util.AddClick(this.BtnBack, function()
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
self:ClosePanel()
end)
Util.AddClick(this.mask, function()
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
self:ClosePanel()
end)
Util.AddClick(this.BtnSure, function()
self:ClosePanel()
openThisPanel:UpdateUpStarPosHeroData(curSelectHeroList)
end)
Util.AddClick(this.btnAutoSelect, function()
self:AutoSelectHero()
end)
end
--添加事件监听(用于子类重写)
function RoleUpStarListPanel:AddListener()
end
--移除事件监听(用于子类重写)
function RoleUpStarListPanel:RemoveListener()
end
--界面打开时调用(用于子类重写)
function RoleUpStarListPanel:OnOpen(heroData,HeroRankupGroupData,RankupConsumeMaterialData,_openThisPanel,_curSelectHeroList,_curHeroData)
openThisPanel= _openThisPanel
curSelectHeroList={}
LogError("dsgdrfshfhjgfj")
print(#_curSelectHeroList)
for i = 1, #_curSelectHeroList do
-- curSelectHeroList[_curSelectHeroList[i]]=_curSelectHeroList[i]
table.insert(curSelectHeroList,_curSelectHeroList[i])
end
curHeroData = _curHeroData
heroDataList = heroData
this.HeroSortData(heroDataList)
local text = ""
for i, v in pairs(heroDataList) do
text = ""
for n,w in pairs(FormationManager.formationList) do
if HeroManager.heroResolveLicence[n] then
for m = 1, #w.teamHeroInfos do
if v.type == RoleUpStarMatType.hero and v.dynamicId==w.teamHeroInfos[m].heroId then
local isFormationStr = HeroManager.GetHeroFormationStr2(n)
if isFormationStr ~= "" then
if not text or text == "" then
text = isFormationStr
else
text = text .. ""..isFormationStr
end
end
end
end
end
end
if not text or text == "" then
v.isFormation = ""
else
v.isFormation = Language[10411]..text..Language[10412]
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,false,false)
curNeedRoleNum=RankupConsumeMaterialData[4]
local str = ""
if HeroRankupGroupData.Issame == 1 then
str = HeroRankupGroupData.StarLimit..Language[10406]
else
if HeroRankupGroupData.IsId ~= 0 then
str = HeroRankupGroupData.StarLimit..Language[10407]..GetLanguageStrById(ConfigManager.GetConfigData(ConfigName.HeroConfig,HeroRankupGroupData.IsId).ReadingName)
else
if HeroRankupGroupData.IsSameClan == 0 then
str = HeroRankupGroupData.StarLimit..Language[10408]
else
str = HeroRankupGroupData.StarLimit..Language[10409]
end
end
end
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 #curSelectHeroList>=curNeedRoleNum then
PopupTipPanel.ShowTip(Language[10403])
return
else
table.insert(curSelectHeroList,heroData)
end
elseif type==2 then
for i = 1, #curSelectHeroList do
if heroData.type == RoleUpStarMatType.hero and 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",#curSelectHeroList,curNeedRoleNum)
end
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)
-- end
for i = 1, #curSelectHeroList do
if curSelectHeroList[i].type == RoleUpStarMatType.hero then
if curSelectHeroList[i].dynamicId == heroData.dynamicId then
choosed:SetActive(true)
end
elseif curSelectHeroList[i].type == RoleUpStarMatType.item then
if curSelectHeroList[i].id == heroData.id and curSelectHeroList[i].index == heroData.index then
choosed:SetActive(true)
end
end
end
Util.GetGameObject(go.transform, "posIcon"):SetActive(false)
local frame = Util.GetGameObject(go.transform, "frame"):GetComponent("Image")
local lvGo = Util.GetGameObject(go.transform, "lv")
local icon = Util.GetGameObject(go.transform, "icon"):GetComponent("Image")
local proIcon = Util.GetGameObject(go.transform, "proIcon")
local name = Util.GetGameObject(go.transform, "name"):GetComponent("Text")
local formationMask = Util.GetGameObject(go.transform, "formationMask")
local formationImage = Util.GetGameObject(formationMask.transform, "formationImage")
local lockImage = Util.GetGameObject(formationMask.transform, "lockImage")
local noumenon = Util.GetGameObject(go, "noumenon")
local starGrid = Util.GetGameObject(go.transform, "star")
local cardBtn = Util.GetGameObject(go.transform, "icon")
local GongMingMask = Util.GetGameObject(go.transform, "GongMingMask")
if heroData.type == RoleUpStarMatType.hero then
frame.sprite = this.spLoader:LoadSprite(GetHeroQuantityImageByquality(heroData.heroConfig.Quality,heroData.star))
lvGo:SetActive(true)
Util.GetGameObject(lvGo.transform, "Text"):GetComponent("Text").text = heroData.lv
icon.sprite = this.spLoader:LoadSprite(heroData.icon)
proIcon:GetComponent("Image").sprite = this.spLoader:LoadSprite(GetProStrImageByProNum(heroData.changeProId))
formationMask:SetActive((heroData.isFormation ~= "" and heroData.isFormation ~= Language[10410]) or heroData.lockState == 1)
formationImage:SetActive(heroData.isFormation ~= "" )
lockImage:SetActive( heroData.lockState == 1)
noumenon:SetActive( heroData.id == curHeroData.id )
name.text = SubString2(GetLanguageStrById(heroData.heroConfig.ReadingName),8)
local star,starType = heroData.GetStar(1)
SetHeroStars(this.spLoader, starGrid, star,starType,nil,nil,Vector2.New(0,1))
LogError("hero star=="..star)
local effect=SetHeroFlyEffect(go,this.spLoader,heroData.star,this.sortingOrder+1,1)
if effect then
local particles=effect:GetComponentsInChildren(typeof(UnityEngine.ParticleSystem))
for key, value in pairs(particles:ToTable()) do
local mat=value:GetComponent(typeof(UnityEngine.Renderer))
if mat.material.shader.name=="YXZ/Effect/Mix Masking(Without Moving)_alphablend" then
mat.material.shader=poolManager:LoadAsset("YXZ_MixMaskingWithoutMoving_alphablend_1",poolManager.AssetType.Other)
end
end
end
Util.SetParticleSortLayer(starGrid,this.sortingOrder + 1)
GongMingMask:SetActive(false)--最后检测是否共鸣
if heroData.lockState == 1 or (heroData.isFormation ~= "" and heroData.isFormation ~= Language[10410]) then
else
if HarmonyManager.IsChangeColor(heroData.dynamicId) then
Util.GetGameObject(go.transform, "lv/Text"):GetComponent("Text").text = "<color=#0f0>"..heroData.lv.."</color>"
GongMingMask:SetActive(true)
elseif HarmonyManager:IsEnvoy(heroData.dynamicId) and HarmonyManager.GetSingleAdditionsData(HarmonyAddType.AddLv) then
if HarmonyManager.GetSingleAdditionsData(HarmonyAddType.AddLv).heroTid == 0 then
-- body
Util.GetGameObject(go.transform, "lv/Text"):GetComponent("Text").text = "<color=#ffbe22>"..heroData.lv.."</color>"
GongMingMask:SetActive(true)
end
end
end
Util.AddOnceClick(GongMingMask, function()
PopupTipPanel.ShowTip(Language[12184])
end)
Util.AddOnceClick(cardBtn, function()
if TrainBuildManager.CheckHeroIsTraining(heroData.dynamicId) then
PopupTipPanel.ShowTip("该神将正在特训")
return
end
local isSelect = false
local selectIndex = 0
for i = 1, #curSelectHeroList do
if curSelectHeroList[i].type == RoleUpStarMatType.hero then
if curSelectHeroList[i].dynamicId == heroData.dynamicId then
isSelect = true
selectIndex = i
end
end
end
if isSelect then
choosed:SetActive(false)
-- curSelectHeroList[heroData.dynamicId]=nil
table.remove(curSelectHeroList,selectIndex)
this.numText.text=string.format("%s/%s",LengthOfTable(curSelectHeroList),curNeedRoleNum)
return
end
if LengthOfTable(curSelectHeroList)>=curNeedRoleNum then
PopupTipPanel.ShowTip(Language[10403])
return
end
-- curSelectHeroList[heroData.dynamicId]=heroData
table.insert(curSelectHeroList,heroData)
choosed:SetActive(true)
this.numText.text=string.format("%s/%s",LengthOfTable(curSelectHeroList),curNeedRoleNum)
end)
Util.AddOnceClick(formationMask, function()
if heroData.isFormation ~= "" then
PopupTipPanel.ShowTip( heroData.isFormation)
return
end
if heroData.lockState == 1 then
PopupTipPanel.ShowTip(Language[10413])
return
end
end)
Util.AddLongPressClick(cardBtn, function()
UIManager.OpenPanel(UIName.RoleInfoPopup,heroData)
end, 0.5)
elseif heroData.type == RoleUpStarMatType.item then
LogError("22222222222")
local itemConfig = ConfigManager.TryGetConfigData(ConfigName.ItemConfig,heroData.id)
if not itemConfig then return end
frame.sprite = this.spLoader:LoadSprite(GetHeroQuantityImageByquality(itemConfig.Quantity,itemConfig.HeroStar[1]))
lvGo:SetActive(false)
icon.sprite = this.spLoader:LoadSprite(GetResourcePath(itemConfig.ResourceID))
if itemConfig.PropertyName and itemConfig.PropertyName > 0 then
proIcon:SetActive(true)
proIcon:GetComponent("Image").sprite = this.spLoader:LoadSprite(GetProStrImageByProNum(itemConfig.PropertyName))
else
proIcon:SetActive(false)
end
formationMask:SetActive(false)
formationImage:SetActive(false)
lockImage:SetActive(false)
noumenon:SetActive(false)
GongMingMask:SetActive(false)
name.text = SubString2(GetLanguageStrById(itemConfig.Name),8)
SetHeroStars(this.spLoader,starGrid, itemConfig.HeroStar[1] or 6,1,nil,nil,Vector2.New(0,1))
local effect=SetHeroFlyEffect(go,this.spLoader,itemConfig.HeroStar[1] or 6,this.sortingOrder+1,1)
if effect then
local particles=effect:GetComponentsInChildren(typeof(UnityEngine.ParticleSystem))
for key, value in pairs(particles:ToTable()) do
local mat=value:GetComponent(typeof(UnityEngine.Renderer))
if mat.material.shader.name=="YXZ/Effect/Mix Masking(Without Moving)_alphablend" then
mat.material.shader=poolManager:LoadAsset("YXZ_MixMaskingWithoutMoving_alphablend_1",poolManager.AssetType.Other)
end
end
end
local meshs1=starGrid:GetComponentsInChildren(typeof(UnityEngine.ParticleSystem))
for key, value in pairs(meshs1:ToTable()) do
local mat=value:GetComponent(typeof(UnityEngine.Renderer))
if mat.material.shader.name=="UI Particles/Additive" then
mat.material.shader=poolManager:LoadAsset("UI-Particle-Add_1",poolManager.AssetType.Other)
end
end
Util.SetParticleSortLayer(starGrid,this.sortingOrder + 1)
Util.AddOnceClick(cardBtn, function()
local isSelect = false
local selectIndex = 0
for i = 1, #curSelectHeroList do
if curSelectHeroList[i].type == RoleUpStarMatType.item then
if curSelectHeroList[i].id == heroData.id and curSelectHeroList[i].index == heroData.index then
isSelect = true
selectIndex = i
choosed:SetActive(true)
end
end
end
if isSelect then
choosed:SetActive(false)
-- curSelectHeroList[heroData.dynamicId]=nil
table.remove(curSelectHeroList,selectIndex)
this.numText.text=string.format("%s/%s",LengthOfTable(curSelectHeroList),curNeedRoleNum)
return
end
if LengthOfTable(curSelectHeroList)>=curNeedRoleNum then
PopupTipPanel.ShowTip(Language[10403])
return
end
-- curSelectHeroList[heroData.dynamicId]=heroData
table.insert(curSelectHeroList,heroData)
choosed:SetActive(true)
this.numText.text=string.format("%s/%s",LengthOfTable(curSelectHeroList),curNeedRoleNum)
end)
Util.AddLongPressClick(cardBtn, function()
UIManager.OpenPanel(UIName.RewardItemSingleShowPopup, heroData.id)
end, 0.5)
end
end
function this.HeroSortData(heroData)
Log("#heroData "..#heroData)
--"该神将在大闹天宫阵容中已上阵"
table.sort(heroData, function(a, b)
if a.type == b.type and a.type == RoleUpStarMatType.hero and b.type == RoleUpStarMatType.hero then
if (a.isFormation == "" or (a.isFormation ~= "" and a.isFormation == Language[10410])) and (b.isFormation == "" or (b.isFormation ~= "" and b.isFormation == Language[10410]))
or (a.isFormation ~= "" and a.isFormation ~= Language[10410]) and (b.isFormation ~= "" and b.isFormation ~= Language[10410]) 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.heroConfig.Sort > b.heroConfig.Sort
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 (a.isFormation == "" or (a.isFormation ~= "" and a.isFormation == Language[10410])) and (not b.dynamicId ~= "" and b.isFormation ~= Language[10410])
end
elseif a.type == b.type and a.type == RoleUpStarMatType.item and b.type == RoleUpStarMatType.item then
return a.id > b.id
else
return a.type > b.type
end
end)
end
function RoleUpStarListPanel:AutoSelectHero()
curSelectHeroList = {}
for i = 1, #heroDataList do
if heroDataList[i].type == RoleUpStarMatType.item and LengthOfTable(curSelectHeroList) < curNeedRoleNum or heroDataList[i].type == RoleUpStarMatType.hero and LengthOfTable(curSelectHeroList) < curNeedRoleNum
and heroDataList[i].isFormation == "" and heroDataList[i].lockState == 0 and (not HarmonyManager.IsChangeColor(heroDataList[i].dynamicId) and(not HarmonyManager:IsEnvoy(heroDataList[i].dynamicId)))
and TrainBuildManager.CheckHeroIsTraining(heroDataList[i].dynamicId)==false then
-- curSelectHeroList[heroDataList[i].dynamicId]=heroDataList[i]
table.insert(curSelectHeroList,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,true,true)
end
--界面关闭时调用(用于子类重写)
function RoleUpStarListPanel:OnClose()
end
--界面销毁时调用(用于子类重写)
function RoleUpStarListPanel:OnDestroy()
this.spLoader:Destroy()
this.ScrollView = nil
end
return RoleUpStarListPanel