require("Base/BasePanel")
TrainingItemListPanel = Inherit(BasePanel)
local this = TrainingItemListPanel
local curSelectItemOrHeroList = {}
local heroOrItemDataList = {}
local curNeedRoleNum = 1
local openThisPanel
local curData = {}
local openType = 0
local currentSelectItems = {}
local currentSelectItem = {}
local curSelectGO
local sendFunc = nil
local openPanel = nil
--初始化组件(用于子类重写)
function TrainingItemListPanel:InitComponent()
this.spLoader = SpriteLoader.New()
curSelectGO = nil
this.BtnBack = Util.GetGameObject(self.gameObject, "btnBack")
this.mask = Util.GetGameObject(self.gameObject, "mask")
this.BtnSure = Util.GetGameObject(self.gameObject, "btnSure")
this.BtnSure:SetActive(true)
this.btnAutoSelect = Util.GetGameObject(self.gameObject, "btnAutoSelect")
this.cardPre = Util.GetGameObject(self.gameObject, "item")
--this.grid = Util.GetGameObject(self.gameObject, "scroll/grid")
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 TrainingItemListPanel: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()
if sendFunc then
sendFunc(currentSelectItems, curSelectItemOrHeroList)
-- openPanel:UpdateUpStarPosHeroData(cu)
self:ClosePanel()
end
end)
-- Util.AddClick(this.btnAutoSelect, function()
-- self:AutoSelectHero()
-- end)
end
--添加事件监听(用于子类重写)
function TrainingItemListPanel:AddListener()
end
--移除事件监听(用于子类重写)
function TrainingItemListPanel:RemoveListener()
end
--界面打开时调用(用于子类重写)
function TrainingItemListPanel:OnOpen(_curData, _func, NeedNum, selectItems1, selectItems2, _openPanel)
sendFunc = _func
openPanel = _openPanel
curSelectItemOrHeroList = {}
currentSelectItems = {}
curNeedRoleNum = NeedNum
heroOrItemDataList = {}
for i = 1, #selectItems1 do
-- curSelectHeroList[_curSelectHeroList[i]]=_curSelectHeroList[i]
table.insert(currentSelectItems, selectItems1[i])
end
for i = 1, #selectItems2 do
-- curSelectHeroList[_curSelectHeroList[i]]=_curSelectHeroList[i]
table.insert(curSelectItemOrHeroList, selectItems2[i])
end
-- print(#_curSelectHeroList)
-- for i = 1, #_curSelectHeroList do
-- -- curSelectHeroList[_curSelectHeroList[i]]=_curSelectHeroList[i]
-- table.insert(curSelectHeroList,_curSelectHeroList[i])
-- end
curData = _curData
-- heroDataList = heroData
if _curData.type == 1 then
local itemDatas = BagManager.GetBagItemDataByItemTypeV3(_curData.data[2], _curData.data[1], _curData.data[3])
local index = 0
for i = 1, #itemDatas do
local haveNum = BagManager.GetItemCountById(itemDatas[i].id)
if haveNum > 0 then
for j = 1 + index, haveNum + index do
local v = {}
v.id = itemDatas[i].id
v.itemData = itemDatas[i]
v.index = j --用于祭品选择界面 查看是否选中
table.insert(heroOrItemDataList, v)
end
end
index = haveNum
-- heroOrItemDataList[i]=itemDatas[i]
end
elseif _curData.type == 3 then
local pokemonList = PokemonManager.GetNoUpFigthPokemonDatas()
local index = 0
for i = 1, #pokemonList do
local v = {}
v.dynamicId = pokemonList[i].dynamicId
v.pokemonData = pokemonList[i]
v.type = 3
v.index = i --用于祭品选择界面 查看是否选中
v.star = v.star
v.lv = v.lv
local config = pokemonList[i].config
v.ischip = 0
v.icon = GetResourcePath(config.Icon)
v.id = v.id
v.quality = config.Quality
v.name = config.Name
v.returnCoin = config.CoinReturn
v.frame = GetHeroQuantityImageByquality(config.Quality)
v.num = 1
--LogError("v.quality==================="..v.quality)
--LogError("curdata.qua=================="..curData.qua)
if curData.qua == v.quality then
table.insert(heroOrItemDataList, v)
end
-- heroOrItemDataList[i]=itemDatas[i]
end
elseif _curData.type == 4 then
local pokemonList = GodWeaponManager.GetNoUpZhenWeapons()
local index = 0
for i = 1, #pokemonList do
local v = {}
v.dynamicId = pokemonList[i].dynamicId
v.pokemonData = pokemonList[i]
v.type = 4
v.index = i --用于祭品选择界面 查看是否选中
v.star = pokemonList[i].star
v.lv = pokemonList[i].lv
local config = pokemonList[i].config
v.ischip = 0
v.icon = GetResourcePath(config.Icon)
--LogError("v.id========================================="..v.id)
v.id = pokemonList[i].id
v.quality = config.Quality
v.name = config.Name
v.returnCoin = config.CoinReturn
v.frame = GetHeroQuantityImageByquality(config.Quality)
v.num = 1
table.insert(heroOrItemDataList, v)
end
else
local titemDatas = {}
if _curData.NeedHeroOther ~= 0 then
local itemId = _curData.NeedHeroOther
local haveNum = BagManager.GetItemCountById(itemId)
if haveNum > 0 then
for i = 1, haveNum do
local v = {}
v.id = itemId
v.type = 2 --1道具 2 英雄 需要传给后端
v.index = i --用于祭品选择界面 查看是否选中
table.insert(titemDatas, v)
end
end
end
if #titemDatas > 0 then
local HeroDatas = HeroManager.GetAllNumStarData(curData.heroGroupData[1])
for i = 1, #titemDatas do
heroOrItemDataList[i] = titemDatas[i]
end
local index = #titemDatas
for i = 1 + index, #HeroDatas + index do
heroOrItemDataList[i] = HeroDatas[i - index]
heroOrItemDataList[i].type = 1
end
else
local HeroDatas = HeroManager.GetAllNumStarData(curData.heroGroupData[1])
for i = 1, #HeroDatas do
heroOrItemDataList[i] = HeroDatas[i]
heroOrItemDataList[i].type = 1
end
end
end
this.ScrollView:SetData(heroOrItemDataList, function(index, go)
this.OnShowSingleCardData(go, heroOrItemDataList[index])
end, false, false)
end
function this.OnClickEnterHero(go, heroData, type)
-- this.OnShowSingleCardData(go,heroData,type)
end
function this.OnShowSingleCardData(go, heroData) --isSelect 1选择 2 没选择
local choosed = Util.GetGameObject(go.transform, "choosed")
choosed:SetActive(false)
local frame = Util.GetGameObject(go.transform, "frame"):GetComponent("Image")
local lvGo = Util.GetGameObject(go.transform, "lv"):GetComponent("Text")
local icon = Util.GetGameObject(go.transform, "icon"):GetComponent("Image")
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")
if curData.type == 2 then
-- icon.sprite = this.spLoader:LoadSprite(heroData.icon)
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, #curSelectItemOrHeroList do
if curSelectItemOrHeroList[i].type == RoleUpStarMatType.hero then
if curSelectItemOrHeroList[i].dynamicId == heroData.dynamicId then
choosed:SetActive(true)
end
elseif curSelectItemOrHeroList[i].type == RoleUpStarMatType.item then
if curSelectItemOrHeroList[i].id == heroData.id and curSelectItemOrHeroList[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)
lvGo: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 ~= nil and heroData.isFormation ~= "" and heroData.isFormation ~= Language[10476]) or
heroData.lockState == 1)
formationImage:SetActive(heroData.isFormation ~= nil and 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[10476]) then
else
if HarmonyManager.IsChangeColor(heroData.dynamicId) then
Util.GetGameObject(go.transform, "lv"):GetComponent("Text").text = "" ..
heroData.lv .. ""
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 = "" ..
heroData.lv .. ""
GongMingMask:SetActive(true)
end
end
end
Util.AddOnceClick(GongMingMask, function()
PopupTipPanel.ShowTip(Language[10477])
end)
Util.AddOnceClick(cardBtn, function()
local isSelect = false
local selectIndex = 0
for i = 1, #curSelectItemOrHeroList do
if curSelectItemOrHeroList[i].type == RoleUpStarMatType.hero then
if curSelectItemOrHeroList[i].dynamicId == heroData.dynamicId then
isSelect = true
selectIndex = i
end
end
end
if isSelect then
choosed:SetActive(false)
-- curSelectHeroList[heroData.dynamicId]=nil
table.remove(curSelectItemOrHeroList, selectIndex)
-- this.numText.text=string.format("%s/%s",LengthOfTable(curSelectItemOrHeroList),curNeedRoleNum)
return
end
if LengthOfTable(curSelectItemOrHeroList) >= curNeedRoleNum then
PopupTipPanel.ShowTip(Language[10470])
return
end
-- curSelectHeroList[heroData.dynamicId]=heroData
table.insert(curSelectItemOrHeroList, heroData)
choosed:SetActive(true)
-- this.numText.text=string.format("%s/%s",LengthOfTable(currentSelectItems),curNeedRoleNum)
end)
Util.AddOnceClick(formationMask, function()
if heroData.isFormation ~= "" then
PopupTipPanel.ShowTip(heroData.isFormation)
return
end
if heroData.lockState == 1 then
PopupTipPanel.ShowTip(Language[10480])
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
]]
Util.SetParticleSortLayer(starGrid, this.sortingOrder + 1)
Util.AddOnceClick(cardBtn, function()
local isSelect = false
local selectIndex = 0
for i = 1, #curSelectItemOrHeroList do
if curSelectItemOrHeroList[i].type == RoleUpStarMatType.item then
if curSelectItemOrHeroList[i].id == heroData.id and curSelectItemOrHeroList[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(curSelectItemOrHeroList, selectIndex)
-- this.numText.text=string.format("%s/%s",LengthOfTable(curSelectItemOrHeroList),curNeedRoleNum)
return
end
if LengthOfTable(curSelectItemOrHeroList) >= curNeedRoleNum then
PopupTipPanel.ShowTip(Language[10470])
return
end
-- curSelectHeroList[heroData.dynamicId]=heroData
table.insert(curSelectItemOrHeroList, heroData)
choosed:SetActive(true)
-- this.numText.text=string.format("%s/%s",LengthOfTable(curSelectItemOrHeroList),curNeedRoleNum)
end)
Util.AddLongPressClick(cardBtn, function()
UIManager.OpenPanel(UIName.RewardItemSingleShowPopup, heroData.id)
end, 0.5)
end
elseif curData.type == 3 or curData.type == 4 then
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, #currentSelectItems do
if currentSelectItems[i].dynamicId == heroData.dynamicId then
choosed:SetActive(true)
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")
frame.sprite = this.spLoader:LoadSprite(GetHeroQuantityImageByquality(heroData.pokemonData.config.Quality,
heroData.star))
lvGo:SetActive(true)
lvGo: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 ~= nil and heroData.isFormation ~= "" and heroData.isFormation ~= Language[10476]) or
heroData.lockState == 1)
formationImage:SetActive(heroData.isFormation ~= nil and heroData.isFormation ~= "")
lockImage:SetActive(heroData.lockState == 1)
--noumenon:SetActive( heroData.id == curHeroData.id )
name.text = SubString2(GetLanguageStrById(heroData.name), 8)
local star = heroData.pokemonData.star
local starSize = Vector2.New(32.5, 32.5)
if star > 5 then
star = star + 5
starSize = Vector2.New(1, -13)
end
SetHeroStars(this.spLoader, starGrid, star, 1, starSize, -15)
Util.SetParticleSortLayer(starGrid, this.sortingOrder + 1)
GongMingMask:SetActive(false) --最后检测是否共鸣
Util.AddOnceClick(cardBtn, function()
local isSelect = false
local selectIndex = 0
for i = 1, #currentSelectItems do
if currentSelectItems[i].dynamicId == heroData.dynamicId then
isSelect = true
selectIndex = i
end
end
if isSelect then
choosed:SetActive(false)
-- curSelectHeroList[heroData.dynamicId]=nil
table.remove(currentSelectItems, selectIndex)
-- this.numText.text=string.format("%s/%s",LengthOfTable(curSelectItemOrHeroList),curNeedRoleNum)
return
end
if LengthOfTable(currentSelectItems) >= curNeedRoleNum then
PopupTipPanel.ShowTip(Language[10470])
return
end
-- curSelectHeroList[heroData.dynamicId]=heroData
table.insert(currentSelectItems, heroData)
choosed:SetActive(true)
-- this.numText.text=string.format("%s/%s",LengthOfTable(currentSelectItems),curNeedRoleNum)
end)
Util.AddOnceClick(formationMask, function()
if heroData.isFormation ~= "" then
PopupTipPanel.ShowTip(heroData.isFormation)
return
end
if heroData.lockState == 1 then
PopupTipPanel.ShowTip(Language[10480])
return
end
end)
Util.AddLongPressClick(cardBtn, function()
--UIManager.OpenPanel(UIName.RoleInfoPopup,heroData)
end, 0.5)
else
for i = 1, #currentSelectItems do
if currentSelectItems[i].itemData.id == heroData.itemData.id and currentSelectItems[i].index == heroData.index then
choosed:SetActive(true)
end
end
icon.sprite = this.spLoader:LoadSprite(heroData.itemData.icon)
local proIcon = Util.GetGameObject(go.transform, "proIcon")
proIcon:SetActive(false)
lvGo.gameObject:SetActive(true)
lvGo.text = heroData.index
name.text = GetLanguageStrById(heroData.itemData.name)
frame.sprite = this.spLoader:LoadSprite(heroData.itemData.frame)
local isSelect = CheckListIsContainValue1(curSelectItemOrHeroList, heroData.itemData.did)
Util.AddOnceClick(cardBtn, function()
local isSelect = false
local selectIndex = 0
for i = 1, #currentSelectItems do
if currentSelectItems[i].index == heroData.index then
isSelect = true
selectIndex = i
end
end
if isSelect then
choosed:SetActive(false)
-- curSelectHeroList[heroData.dynamicId]=nil
table.remove(currentSelectItems, selectIndex)
-- this.numText.text=string.format("%s/%s",LengthOfTable(currentSelectItems),curNeedRoleNum)
return
end
if LengthOfTable(currentSelectItems) >= curNeedRoleNum then
PopupTipPanel.ShowTip(Language[10470])
return
end
-- curSelectHeroList[heroData.dynamicId]=heroData
table.insert(currentSelectItems, heroData)
choosed:SetActive(true)
-- this.numText.text=string.format("%s/%s",LengthOfTable(currentSelectItems),curNeedRoleNum)
end)
end
end
--界面关闭时调用(用于子类重写)
function TrainingItemListPanel:OnClose()
end
--界面销毁时调用(用于子类重写)
function TrainingItemListPanel:OnDestroy()
this.spLoader:Destroy()
sendFunc = nil
heroOrItemDataList = {}
currentSelectItem = nil
this.ScrollView = nil
end
return TrainingItemListPanel