miduo_client/Assets/ManagedResources/~Lua/Modules/GeneralPanel/View/GeneralBigPopup_FourElement...

224 lines
6.2 KiB
Lua

require("View/FourTrailSingleHelpHero")
----- 易经宝库弹窗 -----
local this = {}
--传入父脚本模块
local parent
--传入特效层级
local sortingOrder=0
local itemList = {}--克隆预制体列表
local tabs = {}
local curIndex = 0
local friendHelpHeros = {}
local myHeros = {}
local heightPower = 0
local canHelpPower = 0
local rate = 0
local waveId = 0
local curType = 0
local redTrailType = {
[1] = RedPointType.PersonTrailHelp,
[2] = RedPointType.BuddishTrailHelp,
[3] = RedPointType.DemonTrailHelp,
[4] = RedPointType.TaoistTrailHelp,
}
function this:InitComponent(gameObject)
this.titleText=Util.GetGameObject(gameObject,"TitleText"):GetComponent("Text")
this.itemPre = Util.GetGameObject(gameObject, "itemPre")
this.Scroll = Util.GetGameObject(gameObject, "scroller")
this.selectBtn = Util.GetGameObject(gameObject, "tabbox/selectBtn")
this.tabRoot = Util.GetGameObject(gameObject, "tabbox/box")
this.empty = Util.GetGameObject(gameObject, "Empty")
for i = 1,this.tabRoot.transform.childCount do
table.insert(tabs,this.tabRoot.transform:GetChild(i - 1).gameObject)
end
local rootHight = this.Scroll.transform.rect.height
local width = this.Scroll.transform.rect.width
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.Scroll.transform,
this.itemPre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 0))
this.ScrollView.moveTween.MomentumAmount = 1
this.ScrollView.moveTween.Strength = 2
end
function this:BindEvent()
for i = 1,#tabs do
Util.AddClick(tabs[i],function()
this:BtnClick(i)
end)
end
end
function this:BtnClick(i)
if curIndex == i then
return
end
curIndex = i
LogGreen("curIndex:"..curIndex)
this.selectBtn.transform:SetParent(tabs[i].transform)
this.selectBtn:GetComponent("RectTransform").localPosition = Vector3.zero
this.selectBtn.transform:SetAsFirstSibling()
for k,v in pairs(itemList) do
v.gameObject:SetActive(false)
end
this:RefreshItemData()
end
function this:AddListener()
end
function this:RemoveListener()
end
function this:OnShow(_parent,_Data)
parent=_parent
sortingOrder = _parent.sortingOrder
local args = _Data
waveId = args[1]
curType = args[2]
friendHelpHeros = args[3]
myHeros = args[4]
LogGreen("myHeros:"..#myHeros)
this:SetMyHeightPower()
this.titleText.text = FourElementName[curType]
rate = tonumber(string.format("%.2f",ConfigManager.GetConfigData(ConfigName.CampTowerSetting,1).HelpFightMax / 10000))
canHelpPower = heightPower*rate
this:BtnClick(1)
BindRedPointObject(redTrailType[curType],Util.GetGameObject(tabs[#tabs], "redPoint"))
end
function this:SortHeros(data)
local tempData = MonsterCampManager.GetMyHelpHero(curType)
if tempData then
for i = 1 ,#data do
if data[i].dynamicId == tempData.dynamicId then
data[i].fourElementSortId = 1
else
data[i].fourElementSortId = 0
end
end
else
for i = 1 ,#data do
data[i].fourElementSortId = 0
end
end
table.sort(data,function(a,b)
if a.fourElementSortId == b.fourElementSortId then
if a.warPower == b.warPower then
return a.star > b.star
else
return a.warPower > b.warPower
end
else
return a.fourElementSortId > b.fourElementSortId
end
end)
end
function this:SortHeros1(data)
local tempData = MonsterCampManager.GetFriendHelpHero(curType)
if tempData then
for i = 1 ,#data do
if data[i].hero.dynamicId == tempData.hero.dynamicId then
data[i].sortId = 2
else
if data[i].hero.warPower > heightPower then
data[i].sortId = 0
else
data[i].sortId = 1
end
end
end
else
for i = 1 ,#data do
if data[i].hero.warPower > heightPower then
data[i].sortId = 0
else
data[i].sortId = 1
end
end
end
table.sort(data,function(a,b)
if a.sortId == b.sortId then
if a.hero.warPower == b.hero.warPower then
return a.hero.star > b.hero.star
else
return a.hero.warPower > b.hero.warPower
end
else
return a.sortId > b.sortId
end
end)
end
function this:SetMyHeightPower()
heightPower = 0
if not myHeros or #myHeros < 1 then
heightPower = 0
return
end
for k,v in ipairs(myHeros) do
if v.warPower > heightPower then
heightPower = v.warPower
end
end
end
function this:RefreshItemData()
local data = nil
if curIndex == 1 then
data = friendHelpHeros
else
data = myHeros
end
if not data or #data < 1 then
this.empty:SetActive(true)
this.ScrollView.gameObject:SetActive(false)
return
end
this.empty:SetActive(false)
this.ScrollView.gameObject:SetActive(true)
if curIndex == 1 then
this:SortHeros1(data)
else
this:SortHeros(data)
end
for k,v in pairs(itemList) do
v.gameObject:SetActive(false)
end
this.ScrollView:SetData(data,function(index,go)
if not itemList then
itemList = {}
end
if not itemList[go] then
itemList[go] = SubUIManager.Open(SubUIConfig.FourTrailSingleHelpHero,go.transform,sortingOrder)
end
itemList[go].gameObject:SetActive(true)
itemList[go]:OnShow(curIndex,data[index],curType,canHelpPower,sortingOrder)
end)
this.ScrollView:SetIndex(1)
end
function this:OnClose()
curIndex = 0
ClearRedPointObject(redTrailType[curType],Util.GetGameObject(tabs[#tabs], "redPoint"))
end
function this:OnDestroy()
tabs = {}
for k,v in pairs(itemList) do
SubUIManager.Close(v)
end
if this.ScrollView then
SubUIManager.Close(this.ScrollView)
this.ScrollView = nil
end
itemList = {}
end
return this