miduo_client/Assets/ManagedResources/~Lua/Modules/Resolve/View/Resolve_Pokemon.lua

420 lines
16 KiB
Lua
Raw Normal View History

----- 献祭 -----
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.text=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.text=selectChipNum
end)
Util.AddClick(this.helpBtn,function()
UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.PokemonResolve,this.helpPos.x,this.helpPos.y)
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)
--放生按钮
Util.AddClick(this.confirmBtn,function()
if isPokemon and tonumber(LengthOfTable(selectHeroData))==0 then
PopupTipPanel.ShowTip(Language[12394])
return
end
if not isPokemon and (selectChipId==0 or selectChipNum==0) then
PopupTipPanel.ShowTip(Language[12394])
return
end
--奖励物品
--所有材料
local allMaterials={}
local pokemonIds={}
--灵兽
if isPokemon then
local allCoin=0
for key, value in pairs(selectHeroData) do
--升级消耗
table.insert(pokemonIds,key)
local lvConfig=ConfigManager.GetConfigDataByDoubleKey(ConfigName.SpiritAnimalLevel,"Level",value.lv,"Quality",value.quality)
if lvConfig then
local matrs=lvConfig.SumConsume
if matrs then
for i = 1, #matrs do
local mat=matrs[i]
table.insert(allMaterials,{mat[1],mat[2]})
end
end
end
--升星消耗
local lingshouConfig=ConfigManager.GetConfigData(ConfigName.SpiritAnimal,value.id)
local haveNum=0
if value.star>0 then
local starConfig=ConfigManager.GetConfigDataByDoubleKey(ConfigName.SpiritAnimalStar,"Star",value.star,"Quality",value.quality)
if starConfig then
haveNum=starConfig.SumItemNum
local starMatrs=starConfig.SumConsume
--消耗材料
if starMatrs then
for i = 1, #starMatrs do
local starm=starMatrs[i]
table.insert(allMaterials,{starm[1],starm[2]})
end
end
end
end
--消耗本体数量,分解成碎片
allCoin=allCoin+lingshouConfig.CoinReturn[2]*(haveNum+1)
end
--加上所有的分解币
table.insert(allMaterials,{1205,allCoin})
else--灵兽碎片
local itemConfig=ConfigManager.GetConfigData(ConfigName.ItemConfig,selectChipId)
if itemConfig then
local groupId=itemConfig.RewardGroup[1]
local groupConfig=ConfigManager.GetConfigData(ConfigName.RewardGroup,groupId)
if groupConfig then
LogError("掉落组显示:"..groupConfig.ShowItem[1][1])
local pokemon=ConfigManager.GetConfigData(ConfigName.SpiritAnimal,groupConfig.ShowItem[1][1])
if pokemon then
table.insert(allMaterials,{pokemon.PiecesCoinReturn[1],pokemon.PiecesCoinReturn[2]*selectChipNum})
end
end
end
end
--显示分解界面
UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.PokemonRestore,allMaterials,function()
LogError("灵兽长度 "..#pokemonIds.."碎片id "..selectChipId.." num"..selectChipNum)
NetManager.PokemonFreeRequest(pokemonIds,selectChipId,selectChipNum,function(msg)
UIManager.OpenPanel(UIName.RewardItemPopup,msg.drop,1,function()
end)
if pokemonIds and #pokemonIds>0 then
PokemonManager.RemovePokemonData(pokemonIds)
-- else
-- LogError("分解前数量"..BagManager.GetItemCountById(selectChipId))
-- BagManager.HeroLvUpUpdateItemsNum(selectChipId,selectChipNum)
-- LogError("分解后数量"..BagManager.GetItemCountById(selectChipId))
end
this.SortTypeClick(sortingOrder)
end)
end)
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 items={}
local heros=PokemonManager.GetPokemonResolveDatas()
if heros then
for i, v in pairs(heros) do
local hero={}
local heroConfig=v.config
if heroConfig then
hero.star=v.star
hero.lv=v.lv
hero.dynamicId=v.dynamicId
hero.ischip=0
hero.icon= GetResourcePath(heroConfig.Icon)
hero.id=v.id
hero.quality=heroConfig.Quality
hero.name=heroConfig.Name
hero.returnCoin=heroConfig.CoinReturn
hero.frame=GetHeroQuantityImageByquality(heroConfig.Quality)
hero.num=1
table.insert(items,hero)
end
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(items,chip)
end
end
heroDatas=items
this.chipObj:SetActive(selectChipId~=0)
this.selectText.gameObject:SetActive(selectChipId==0)
this.selectText.text = Language[11775].."0/"..maxSelectNum
this.SortHeroDatas(heroDatas)
if oldChoosed then
oldChoosed:SetActive(false)
end
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"):SetActive(false)
Util.GetGameObject(_go.transform, "num"):SetActive(true)
Util.GetGameObject(_go.transform, "num"):GetComponent("Text").text = heroData.num
else
Util.GetGameObject(_go.transform, "lv"):SetActive(true)
Util.GetGameObject(_go.transform, "num"):SetActive(false)
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==1 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
--如果灵兽是选中状态,取消选中
selectChipId=0
selectChipNum=0
if oldChoosed then
oldChoosed:SetActive(false)
oldChoosed=nil
end
if selectHeroData[heroData.dynamicId] then
choosed:SetActive(false)
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
choosed:SetActive(true)
selectHeroData[heroData.dynamicId]=heroData
this.selectText.text = Language[11775]..LengthOfTable(selectHeroData).."/"..maxSelectNum
if isPokemon==false then
--todo 首次点击灵兽,置灰所有碎片
this.ScrollView:SetData(heroDatas, function (index, go)
this.SingleHeroDataShow(go, heroDatas[index],true)
end)
this.selectText.gameObject:SetActive(true)
this.chipObj:SetActive(false)
isPokemon = true
end
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.ischip==b.ischip then
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
else
return a.ischip<b.ischip
end
end)
end
function this:OnClose()
selectChipId=0
selectHeroData={}
isPokemon=false
oldChoosed=nil
end
function this:OnDestroy()
end
return this