miduo_client/Assets/ManagedResources/~Lua/Modules/Formation/FormationEditPopup.lua

407 lines
15 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

require("Base/BasePanel")
FormationEditPopup = Inherit(BasePanel)
local this = FormationEditPopup
local chooseIndex=0
local choosedList={}
local deleteList={}
local curFormationIndex
local order=0
-- local orderImageTextList={}
-- 妖灵师等级限制显示
local _LimitLevel = 0
local _LimitNum = 0
local _BloodList = nil
-- local curFormation
local sortType = 1 -- 1品阶 2等级
local proId=0--0 全部 1 火 2风 3 水 4 地
local tabs = {}--筛选按钮
local maxNum =5 --最大上阵人数
local goList={} --当前英雄对应预设的集合
local func=nil --回调
function FormationEditPopup:InitComponent()
this.BtnBack = Util.GetGameObject(this.gameObject, "bg/btnBack")
this.BtnSure = Util.GetGameObject(this.gameObject, "bg/btnSure")
this.allBtn=Util.GetGameObject(this.gameObject,"bg/allBtn")
this.cardPre = Util.GetGameObject(this.gameObject, "item")
this.grid = Util.GetGameObject(this.gameObject, "bg/scroll")
this.desc=Util.GetGameObject(this.gameObject,"bg/desc"):GetComponent("Text")
--筛选按钮
for i = 0, 4 do
tabs[i] = Util.GetGameObject(this.gameObject, "bg/Tabs/Grid/Btn" .. i)
end
this.selectBtn = Util.GetGameObject(this.gameObject, "bg/Tabs/SelectBtn")
this.ShaiXuanBtn = Util.GetGameObject(self.gameObject, "bg/ShaiXuanBtn")
this.ShaiXuanBtnLv = Util.GetGameObject(self.gameObject, "bg/ShaiXuanBtn/Lv")
this.ShaiXuanBtnQu = Util.GetGameObject(self.gameObject, "bg/ShaiXuanBtn/Qu")
this.ScrollBar = Util.GetGameObject(self.gameObject, "bg/Scrollbar"):GetComponent("Scrollbar")
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, Util.GetGameObject(self.gameObject, "scroll").transform,
this.cardPre, this.ScrollBar, Vector2.New(927.5, 927), 1, 5, Vector2.New(19.32, 40))
this.ScrollView.gameObject:GetComponent("RectTransform").anchoredPosition = Vector2.New(0, 0)
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.gameObject:GetComponent("RectTransform").pivot = Vector2.New(0.5, 0.5)
this.ScrollView.moveTween.MomentumAmount = 1
this.ScrollView.moveTween.Strength = 1
-- this.isHaveInTeam = false
end
function FormationEditPopup:BindEvent()
Util.AddClick(this.BtnBack, function()
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
Game.GlobalEvent:DispatchEvent(GameEvent.Map.Out,0)
self:ClosePanel()
end)
--选定按钮
Util.AddClick(this.BtnSure, function()
local go=function()
Log(Language[10668])
local dids={}
for i, v in ipairs(choosedList) do
table.insert(dids,v.did)
end
if #choosedList <= maxNum and #choosedList > 0 then
NetManager.TrialHeroInfoSaveRequest(dids,function()
PopupTipPanel.ShowTip(Language[10669])
if func~=nil then --保存完毕后 将英雄did合集传递过去 此时我拥有这些英雄 不用担心英雄已被删除
func(dids)
end
self:ClosePanel()
end)
else
PopupTipPanel.ShowTip(Language[12323])
end
end
if #choosedList < maxNum and #choosedList > 0 then
MsgPanel.ShowTwo(Language[10670], nil, function()
go()
end)
else
go()
end
end)
--一键选择
Util.AddClick(this.allBtn,function()
for i, v in pairs(goList) do --先关闭全部选择项 清空选择列表
Util.GetGameObject(v, "choosed"):SetActive(false)
end
choosedList={}
--按战力从大到小排序
local heros = {}
if proId == ProIdConst.All then
heros = HeroManager.GetAllHeroDatas(_LimitLevel)
else
heros = HeroManager.GetHeroDataByProperty(proId, _LimitLevel)
end
table.sort(heros,function(a,b)
local aWarPower = HeroManager.CalculateHeroAllProValList(1,a.dynamicId,false)[HeroProType.WarPower]
local bWarPower = HeroManager.CalculateHeroAllProValList(1,b.dynamicId,false)[HeroProType.WarPower]
if aWarPower==bWarPower then
return a.id>b.id
else
return aWarPower>bWarPower
end
end)
--将战力前5英雄选中赋值
for j = 1, maxNum do
local go
for k, v in pairs(goList) do
if k and heros[j] and k==heros[j].dynamicId then --goList的键值是英雄did 若它与当前英雄列表中的did相等
go=Util.GetGameObject(v, "choosed")
go.gameObject:SetActive(true)
end
end
order=order+1
if heros[j] then --若存在该索引 就插入数据当我筛选某一元素时该元素英雄长度可能不为5
table.insert(choosedList,{did = heros[j].dynamicId, choosed = go,position=order})
end
end
LogRed(#choosedList)
this.RefreshDesc()
end)
--筛选按钮
for i = 0, 4 do
Util.AddClick(tabs[i], function()
if i == proId then
proId=ProIdConst.All
else
proId=i
end
this.OnClickTabBtn(proId)
end)
end
--品阶等级筛选
Util.AddClick(this.ShaiXuanBtn, function()
if sortType == SortTypeConst.Lv then
sortType = SortTypeConst.Natural
else
sortType = SortTypeConst.Lv
end
this.ShaiXuanBtnLv:SetActive(sortType ~= SortTypeConst.Lv)
this.ShaiXuanBtnQu:SetActive(sortType ~= SortTypeConst.Natural)
this.OnClickTabBtn(proId)
end)
end
function FormationEditPopup:AddListener()
end
function FormationEditPopup:RemoveListener()
end
function FormationEditPopup:OnOpen(...)
local args={...}
func=args[1]
-- curFormationIndex = formationIndex
-- _LimitLevel = limitLevel or 0
-- _LimitNum = limitNum or 1
-- logErrorTrace("限制等级是" .. limitLevel)
choosedList ={}
-- curFormation = FormationManager.GetFormationByID(curFormationIndex)
-- for j = 1, #curFormation.teamHeroInfos do
-- local teamInfo = curFormation.teamHeroInfos[j]
-- table.insert(choosedList, {did =teamInfo.heroId, choosed = 0,position=teamInfo.position})
-- end
order = 0--#curFormation.teamHeroInfos
sortType = SortTypeConst.Lv
proId = ProIdConst.All
this.OnClickTabBtn(proId)
this.ShaiXuanBtnLv:SetActive(sortType ~= SortTypeConst.Lv)
this.ShaiXuanBtnQu:SetActive(sortType ~= SortTypeConst.Natural)
end
function FormationEditPopup:OnClose()
end
function FormationEditPopup:OnDestroy()
this.ScrollView = nil
end
--点击页签__根据sortType和职业属性/类型进行排序
function this.OnClickTabBtn(_proId)
local heros
this.selectBtn:SetActive(proId ==_proId)
this.selectBtn.transform:SetParent(tabs[_proId].transform)
this.selectBtn.transform:DOAnchorPos(Vector3.zero,0)
this.selectBtn.transform:DOScale(Vector3.one,0)
if _proId == ProIdConst.All then
heros = HeroManager.GetAllHeroDatas(_LimitLevel)
else
heros = HeroManager.GetHeroDataByProperty(_proId, _LimitLevel)
end
this.SetRoleList(heros)
this.RefreshDesc()
end
--设置英雄列表数据
function this.SetRoleList(_roleDatas)
this:SortHeroDatas(_roleDatas)
-- curFormation = FormationManager.formationList[curFormationIndex]
goList={}
-- orderImageTextList={}
this.ScrollView:SetData(_roleDatas, function(index, go)
this.SingleHeroDataShow(go, _roleDatas[index])
end)
end
--设置单个英雄数据
function this.SingleHeroDataShow(_go, _heroData)
local heroData = _heroData
local go = _go
goList[heroData.dynamicId]=go
local choosed = Util.GetGameObject(go, "choosed")
-- local orderImage= Util.GetGameObject(go, "orderImage")
-- local orderImageText=Util.GetGameObject(go, "orderImage/orderImageText"):GetComponent("Text")
choosed:SetActive(false)
-- orderImage:SetActive(false)
-- orderImageText.text=""
for i,v in ipairs(choosedList) do
if(heroData.dynamicId==v.did) then
choosed:SetActive(true)
-- orderImage:SetActive(true)
-- orderImageText.text=v.position
-- table.insert(orderImageTextList,orderImageText)
end
end
Util.GetGameObject(go, "frame"):GetComponent("Image").sprite = Util.LoadSprite(GetHeroQuantityImageByquality(heroData.heroConfig.Quality,heroData.star))
Util.GetGameObject(go, "icon"):GetComponent("Image").sprite = Util.LoadSprite(heroData.icon)
Util.GetGameObject(go, "lv/Text"):GetComponent("Text").text = heroData.lv
Util.GetGameObject(go, "icon"):GetComponent("Image").sprite = Util.LoadSprite(GetResourcePath(heroData.heroConfig.Icon))
-- Util.GetGameObject(go, "posIcon"):GetComponent("Image").sprite = Util.LoadSprite(heroData.professionIcon)
Util.GetGameObject(go, "proIcon"):GetComponent("Image").sprite = Util.LoadSprite(GetProStrImageByProNum(heroData.heroConfig.PropertyName))
-- Util.GetGameObject(go, "heroStage"):GetComponent("Image").sprite = Util.LoadSprite(HeroStageSprite[heroData.heroConfig.HeroStage])
--剩余血量 无尽副本才显示
local hpExp = Util.GetGameObject(go, "hpExp")
local heroHp = FormationManager.GetFormationHeroHp(curFormationIndex, heroData.dynamicId)
local starGrid = Util.GetGameObject(go, "star")
local starPre = Util.GetGameObject(go, "starPre")
SetHeroStars(starGrid, heroData.star)
this.SetHeroBlood(hpExp, heroHp, go)
--hpExp:SetActive(false)
--hpExp:GetComponent("Slider").value = 0.5
-- Click On
Util.AddOnceClick(go, function()
for k, v in ipairs(choosedList) do
if v.did == heroData.dynamicId then
--选择的条目已存在移除选择的item
choosed:SetActive(false)
-- orderImage:SetActive(false)
-- orderImageText.text=""
table.remove(choosedList,k)
order=order-1
-- table.remove(orderImageTextList,k)
chooseIndex=v.position
for i,v in ipairs(choosedList) do
if(choosedList[i].position>chooseIndex) then
choosedList[i].position=v.position-1
end
end
this.OnClickTabBtn(proId)
return
end
end
-- 当前可选的最大上阵人数
maxNum = 5--ActTimeCtrlManager.MaxArmyNum()
if #choosedList >= maxNum then
-- if maxNum < 5 then
-- PopupTipPanel.ShowTip(ActTimeCtrlManager.NextArmCondition())
-- end
PopupTipPanel.ShowTip(Language[10671])
return
end
-- 判断是否有血量
if heroHp and heroHp <= 0 then PopupTipPanel.ShowTip(Language[10672]) return end
choosed:SetActive(true)
-- orderImage:SetActive(true)
order=order+1
table.insert(choosedList, {did = heroData.dynamicId, choosed = choosed, position=order})
-- table.insert(orderImageTextList,orderImageText)
this.OnClickTabBtn(proId)
choosedList[heroData.dynamicId] = choosed
end)
Util.AddLongPressClick(go, function()
UIManager.OpenPanel(UIName.RoleInfoPopup, heroData)
end, 0.5)
end
--刷新描述信息
function this.RefreshDesc()
this.desc.text=string.format(Language[10673],maxNum,#choosedList,maxNum)
end
-- 设置妖灵师血量
function this.SetHeroBlood(hpExp, heroHp, go)
if heroHp then
hpExp:SetActive(true)
hpExp:GetComponent("Slider").value = heroHp
Util.SetGray(go, heroHp <= 0)
else
hpExp:SetActive(false)
end
end
function this:SortHeroDatas(_heroDatas)
local choosed = {}
local dieHeros = {}
-- local curFormation = FormationManager.GetFormationByID(curFormationIndex)
for i = 1, #_heroDatas do
local heroHp = FormationManager.GetFormationHeroHp(curFormationIndex, _heroDatas[i].dynamicId)
if heroHp then
if heroHp <= 0 then
dieHeros[_heroDatas[i].dynamicId] = _heroDatas[i].dynamicId
end
end
end
-- for j = 1, #curFormation.teamHeroInfos do
-- local teamInfo = curFormation.teamHeroInfos[j]
-- choosed[teamInfo.heroId] = j
-- end
table.sort(_heroDatas, function(a, b)
if (choosed[a.dynamicId] and choosed[b.dynamicId]) or
(not choosed[a.dynamicId] and not choosed[b.dynamicId])
then
if (dieHeros[a.dynamicId] and dieHeros[b.dynamicId]) or
(not dieHeros[a.dynamicId] and not dieHeros[b.dynamicId])
then
if sortType == SortTypeConst.Natural then
if a.heroConfig.Natural == b.heroConfig.Natural then
if a.heroConfig.Quality == b.heroConfig.Quality then
if a.star == b.star then
if a.lv == b.lv then
if a.id == b.id then
return a.sortId > b.sortId
else
return a.id > b.id
end
else
return a.lv > b.lv
end
else
return a.star > b.star
end
else
return a.heroConfig.Quality > b.heroConfig.Quality
end
else
return a.heroConfig.Natural > b.heroConfig.Natural
end
else
if a.lv == b.lv then
if a.heroConfig.Quality == b.heroConfig.Quality then
if a.star == b.star then
if a.heroConfig.Natural == b.heroConfig.Natural then
if a.id == b.id then
return a.sortId > b.sortId
else
return a.id > b.id
end
else
return a.heroConfig.Natural > b.heroConfig.Natural
end
else
return a.star > b.star
end
else
return a.heroConfig.Quality > b.heroConfig.Quality
end
else
return a.lv > b.lv
end
end
else
return not dieHeros[a.dynamicId] and dieHeros[b.dynamicId]
end
else
return choosed[a.dynamicId] and not choosed[b.dynamicId]
end
end)
end
function this.OnClickEnterHeroInfo(_curhero, _heros)
UIManager.OpenPanel(UIName.RoleInfoPanel, _curhero, _heros)
end
return FormationEditPopup