318 lines
12 KiB
Lua
318 lines
12 KiB
Lua
----- 献祭 -----
|
||
local this = {}
|
||
local sortingOrder=0
|
||
local tabSortType = 0
|
||
local tarHero
|
||
local selectHeroData={}--选择的英雄list did = data
|
||
local maxSelectNum = 30--最大选择数量
|
||
--选择碎片的数量
|
||
local selectChipNum = 0
|
||
--显示的灵兽及碎片数据
|
||
local heroDatas={}
|
||
local oldChoosed=nil--上一个选中英雄
|
||
--选择的碎片id
|
||
local selectChipId=0
|
||
--碎片最大数量
|
||
local maxChipNum =0
|
||
--是否为灵兽/灵兽碎片
|
||
local isPokemon = false
|
||
function this:InitComponent(gameObject)
|
||
--上部内容
|
||
this.helpBtn=Util.GetGameObject(gameObject,"Content/Resolve_Pokemon/HelpBtn")
|
||
this.helpPos=this.helpBtn:GetComponent("RectTransform").localPosition
|
||
--回溯按钮
|
||
this.confirmBtn=Util.GetGameObject(gameObject,"Content/Resolve_Pokemon/ConfirmBtn")
|
||
Util.GetGameObject(gameObject,"Content/Resolve_Pokemon/ConfirmBtn/Image"):GetComponent("Image").sprite=Util.LoadSprite("lingshou_fangshenganniu")
|
||
this.shopBtn=Util.GetGameObject(gameObject,"Content/Resolve_Pokemon/shopBtn")
|
||
this.selectText = Util.GetGameObject(gameObject,"Content/Resolve_Pokemon/selectNumText"):GetComponent("Text")
|
||
this.selectBtn = Util.GetGameObject(gameObject,"Content/Resolve_Pokemon/btns/selectBtn")
|
||
this.cardPre = Util.GetGameObject(gameObject,"Content/Resolve_Pokemon/equipTreasurePre")
|
||
this.scrollbar = Util.GetGameObject(gameObject,"Content/Resolve_Pokemon/Scrollbar"):GetComponent("Scrollbar")
|
||
this.Empty = Util.GetGameObject(gameObject,"Content/Resolve_Pokemon/Empty")
|
||
local v21 = Util.GetGameObject(gameObject, "Content/Resolve_Pokemon/ItemListRoot"):GetComponent("RectTransform").rect
|
||
Util.GetGameObject(gameObject, "Content/Resolve_Pokemon/Empty/Bg/Text"):GetComponent("Text").text=Language[12393]
|
||
this.chipObj=Util.GetGameObject(gameObject, "Content/Resolve_Pokemon/chipObj")
|
||
this.btn_remove=Util.GetGameObject(gameObject, "Content/Resolve_Pokemon/chipObj/btn_remove")
|
||
this.btn_add=Util.GetGameObject(gameObject, "Content/Resolve_Pokemon/chipObj/btn_add")
|
||
this.chipNumTxt=Util.GetGameObject(gameObject, "Content/Resolve_Pokemon/chipObj/Text"):GetComponent("Text")
|
||
|
||
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, Util.GetGameObject(gameObject, "Content/Resolve_Pokemon/ItemListRoot").transform,
|
||
this.cardPre, this.scrollbar, Vector2.New(v21.width, v21.height), 1, 5, Vector2.New(43,15))
|
||
this.ScrollView.moveTween.MomentumAmount = 1
|
||
this.ScrollView.moveTween.Strength = 1
|
||
maxSelectNum = tonumber(ConfigManager.GetConfigData(ConfigName.SpecialConfig,54).Value)
|
||
end
|
||
|
||
function this:BindEvent()
|
||
--减少按钮
|
||
Util.AddClick(this.btn_remove,function()
|
||
if selectChipNum==1 then
|
||
--减少按钮置灰
|
||
Util.SetGray(this.btn_remove,true)
|
||
return
|
||
end
|
||
if selectChipNum== maxChipNum-1 then
|
||
--取消增加按钮置灰
|
||
Util.SetGray(this.btn_add,false)
|
||
end
|
||
selectChipNum=selectChipNum-1
|
||
this.chipNumTxt=selectChipNum
|
||
end
|
||
)
|
||
--增加按钮
|
||
Util.AddClick(this.btn_add,function()
|
||
if selectChipNum==maxChipNum then
|
||
--增加按钮置灰
|
||
Util.SetGray(this.btn_add,true)
|
||
return
|
||
end
|
||
if selectChipNum== 2 then
|
||
--取消减少按钮置灰
|
||
Util.SetGray(this.btn_remove,false)
|
||
end
|
||
selectChipNum=selectChipNum + 1
|
||
this.chipNumTxt=selectChipNum
|
||
end
|
||
)
|
||
Util.AddClick(this.helpBtn,function()
|
||
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.Resolve_Dismantle,this.helpPos.x,this.helpPos.y)
|
||
end)
|
||
Util.AddClick(this.confirmBtn,function()
|
||
if tonumber(LengthOfTable(selectHeroData))==0 then
|
||
PopupTipPanel.ShowTip(Language[12394])
|
||
else
|
||
UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.ResolveDismantle,
|
||
HeroManager.GetHeroReturnItems(selectHeroData,GENERAL_POPUP_TYPE.ResolveDismantle),selectHeroData,selectChipId,selectChipNum)
|
||
end
|
||
end)
|
||
|
||
Util.AddClick(this.shopBtn, function()
|
||
local isActive, errorTip = ShopManager.IsActive(SHOP_TYPE.SOUL_CONTRACT_SHOP)
|
||
if not isActive then
|
||
PopupTipPanel.ShowTip(errorTip or Language[10528])
|
||
return
|
||
end
|
||
UIManager.OpenPanel(UIName.MainShopPanel, SHOP_TYPE.SOUL_CONTRACT_SHOP)
|
||
end)
|
||
end
|
||
|
||
function this:AddListener()
|
||
end
|
||
|
||
function this:RemoveListener()
|
||
end
|
||
|
||
function this:OnShow(...)
|
||
sortingOrder =0
|
||
this.SortTypeClick(sortingOrder)
|
||
end
|
||
|
||
--展示数据
|
||
function this.SortTypeClick(_sortType)
|
||
tabSortType=_sortType
|
||
selectHeroData={}
|
||
--所有灵兽数据
|
||
|
||
local heros=PokemonManager.GetPokemonDatas()
|
||
if heros then
|
||
for i, v in pairs(heros) do
|
||
local hero={}
|
||
local heroConfig=v.config
|
||
hero.star=v.star
|
||
hero.lv=v.lv
|
||
hero.dynamicId=v.dynamicId
|
||
hero.ischip=0
|
||
hero.icon=heroConfig.Icon
|
||
hero.id=v.id
|
||
hero.quality=heroConfig.Quality
|
||
hero.name=heroConfig.Name
|
||
hero.returnCoin=heroConfig.CoinReturn
|
||
hero.frame=GetHeroQuantityImageByquality(heroConfig.Quality,1)
|
||
hero.num=1
|
||
table.insert(heroDatas,hero)
|
||
end
|
||
end
|
||
|
||
--所有灵兽碎片
|
||
local chips=BagManager.GetDataByItemType(22)
|
||
if chips then
|
||
for i, v in pairs(chips) do
|
||
local chip={}
|
||
chip.star=0
|
||
chip.lv=0
|
||
chip.ischip=1
|
||
chip.frame=v.frame
|
||
chip.icon=v.icon
|
||
chip.id=v.id
|
||
chip.quality=v.quality
|
||
chip.num=v.num
|
||
chip.name=v.name
|
||
chip.returnCoin=0
|
||
chip.dynamicId=v.id
|
||
table.insert(heroDatas,chip)
|
||
end
|
||
end
|
||
|
||
this.chipObj:SetActive(false)
|
||
this.selectText.gameObject:SetActive(true)
|
||
this.selectText.text = Language[11775].."0/"..maxSelectNum
|
||
-- this.SortHeroDatas(heroDatas)
|
||
this.Empty:SetActive(#heroDatas <= 0)
|
||
this.ScrollView:SetData(heroDatas, function (index, go)
|
||
this.SingleHeroDataShow(go, heroDatas[index],false)
|
||
end)
|
||
this.ScrollView:ForeachItemGO(function(index, go)
|
||
Timer.New(function()
|
||
go.gameObject:SetActive(true)
|
||
PlayUIAnim(go.gameObject)
|
||
end, 0.001 * (index - 1)):Start()
|
||
end)
|
||
end
|
||
|
||
--英雄单个数据展示
|
||
function this.SingleHeroDataShow(go,_heroData,isGray)
|
||
local heroData = _heroData
|
||
local _go = go
|
||
Util.GetGameObject(_go.transform, "frame"):GetComponent("Image").sprite = Util.LoadSprite(heroData.frame)
|
||
if heroData.ischip==1 then
|
||
Util.GetGameObject(_go.transform, "lv/Text"):GetComponent("Text").text = heroData.num
|
||
else
|
||
Util.GetGameObject(_go.transform, "lv/Text"):GetComponent("Text").text = heroData.lv
|
||
end
|
||
|
||
Util.GetGameObject(_go.transform, "Text"):GetComponent("Text").text = heroData.name
|
||
Util.GetGameObject(_go.transform, "icon"):GetComponent("Image").sprite = Util.LoadSprite(heroData.icon)
|
||
local chipImg=Util.GetGameObject(_go.transform, "chipImg"):GetComponent("Image")
|
||
local formationMask =Util.GetGameObject(_go.transform, "mask")
|
||
if heroData.ischip==1 then
|
||
chipImg.gameObject:SetActive(true)
|
||
formationMask:SetActive(isGray)
|
||
chipImg.sprite=Util.LoadSprite(GetHeroChipQuantityImageByquality(heroData.quality))
|
||
else
|
||
chipImg.gameObject:SetActive(false)
|
||
formationMask:SetActive(false)
|
||
end
|
||
local starGrid = Util.GetGameObject(_go.transform, "star")
|
||
SetHeroStars(starGrid, heroData.star,1,Vector2.New(32.5,32.5),-15)
|
||
local choosed =Util.GetGameObject(_go.transform, "choosed")
|
||
if heroData.ischip then
|
||
choosed:SetActive(selectChipId==heroData.dynamicId)
|
||
else
|
||
choosed:SetActive(selectHeroData[heroData.dynamicId] ~= nil)
|
||
end
|
||
local cardclickBtn = Util.GetGameObject(_go.transform, "icon")
|
||
this.selectText.text = Language[11775]..LengthOfTable(selectHeroData).."/"..maxSelectNum
|
||
Util.AddOnceClick(cardclickBtn, function()
|
||
--如果点击的是碎片
|
||
if heroData.ischip==1 then
|
||
--第一个选中的碎片
|
||
if oldChoosed==nil then
|
||
this.selectText.gameObject:SetActive(false)
|
||
this.chipObj:SetActive(true)
|
||
choosed:SetActive(true)
|
||
oldChoosed=choosed
|
||
else
|
||
--如果选中之前选中的,就取消选中
|
||
if oldChoosed==choosed then
|
||
oldChoosed=nil
|
||
selectChipId=0
|
||
choosed:SetActive(false)
|
||
this.selectText.gameObject:SetActive(true)
|
||
this.selectText.text = Language[11775].."0".."/"..maxSelectNum
|
||
this.chipObj:SetActive(false)
|
||
return
|
||
else
|
||
oldChoosed:SetActive(false)
|
||
choosed:SetActive(true)
|
||
oldChoosed=choosed
|
||
end
|
||
end
|
||
selectChipId=heroData.dynamicId
|
||
Util.SetGray(this.btn_add,true)
|
||
selectChipNum=heroData.num
|
||
maxChipNum=heroData.num
|
||
this.chipNumTxt.text=selectChipNum
|
||
isPokemon=false
|
||
--点击的是灵兽
|
||
else
|
||
--如果灵兽是选中状态,取消选中
|
||
if selectHeroData[heroData.dynamicId] then
|
||
choosed:SetActive(false)
|
||
if oldChoosed then
|
||
oldChoosed:SetActive(false)
|
||
end
|
||
selectChipId=0
|
||
selectHeroData[heroData.dynamicId] = nil
|
||
local haveNum=LengthOfTable(selectHeroData)
|
||
this.selectText.text = Language[11775]..haveNum.."/"..maxSelectNum
|
||
if haveNum==0 then
|
||
-- --todo 取消所有碎片置灰
|
||
this.ScrollView:SetData(heroDatas, function (index, go)
|
||
this.SingleHeroDataShow(go, heroDatas[index],false)
|
||
end)
|
||
isPokemon=false
|
||
end
|
||
return
|
||
end
|
||
--如果选中灵兽的数量为最大
|
||
if LengthOfTable(selectHeroData)==maxSelectNum then
|
||
PopupTipPanel.ShowTip(string.format(Language[12396],maxSelectNum))
|
||
return
|
||
end
|
||
if isPokemon==false then
|
||
--todo 首次点击灵兽,置灰所有碎片
|
||
this.ScrollView:SetData(heroDatas, function (index, go)
|
||
this.SingleHeroDataShow(go, heroDatas[index],true)
|
||
end)
|
||
selectChipId=0
|
||
this.selectText.gameObject:SetActive(true)
|
||
this.chipObj:SetActive(false)
|
||
isPokemon = true
|
||
end
|
||
selectHeroData[heroData.dynamicId]=heroData
|
||
choosed:SetActive(true)
|
||
this.selectText.text = Language[11775]..LengthOfTable(selectHeroData).."/"..maxSelectNum
|
||
end
|
||
end)
|
||
|
||
--灰色遮罩点击
|
||
Util.AddOnceClick(formationMask, function()
|
||
PopupTipPanel.ShowTip(Language[12395])
|
||
end)
|
||
|
||
end
|
||
--英雄排序
|
||
function this.SortHeroDatas(_heroDatas)
|
||
--上阵最优先,星级优先,同星级等级优先,同星级同等级按sortId排序。排序时降序排序。
|
||
table.sort(_heroDatas, function(a, b)
|
||
if a ==nil or b == nil then
|
||
return
|
||
end
|
||
if a.quality ==b.quality then
|
||
if a.star == b.star then
|
||
if a.lv == b.lv then
|
||
return a.id > b.id
|
||
else
|
||
return a.lv < b.lv
|
||
end
|
||
else
|
||
return a.star < b.star
|
||
end
|
||
else
|
||
return a.quality < b.quality
|
||
end
|
||
|
||
end)
|
||
end
|
||
|
||
|
||
|
||
|
||
|
||
function this:OnClose()
|
||
end
|
||
|
||
function this:OnDestroy()
|
||
end
|
||
|
||
return this |