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

141 lines
4.0 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 configData = {}
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
this.selectBtn.transform:SetParent(tabs[i].transform)
this.selectBtn:GetComponent("RectTransform").localPosition = Vector3.zero
this.selectBtn.transform:SetAsFirstSibling()
curIndex = i
if i == 1 then
friendHelpHeros = MonsterCampManager.GetFriendHelpHeros(curType)
end
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,...)
parent=_parent
sortingOrder = _parent.sortingOrder
local args = {...}
waveId = args[1]
curType = args[2]
myHeros = HeroManager.GetHeroDataByProperty(curType,0)
this:SetMyHeightPower()
configData = ConfigManager.GetConfigDataByDoubleKey(ConfigName.CampTowerConfig,"FloorId",waveId,"CampId",curType)
this.titleText.text = FourElementName[curType]
rate = tonumber(string.format("%.2f",ConfigManager.GetConfigData(ConfigName.CampTowerSetting,1).HelpFightMax / 10000))
canHelpPower = heightPower*rate
this:BtnClick(1)
end
function this:SortHeros(data)
table.sort(data,function(a,b)
if a.warPower == b.warPower then
return a.star > b.star
else
return a.warPower > b.warPower
end
end)
end
function this:SetMyHeightPower()
heightPower = 0
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)
return
end
this.empty:SetActive(false)
this:SortHeros(data)
this.ScrollView:SetData(data,function(index,go)
--this:SetSingleData(index,go,data[index])
LogGreen(go.name)
go.gameObject:SetActive(true)
local tempData = FourTrailSingleHelpHero:New(go)
tempData:OnOpen(curIndex,data[index],curType,heightPower)
local tempId = curIndex == 1 and data[index].hero.dynamicId or data[index].dynamicId
itemList[tempId] = tempData
end)
end
function this:OnClose()
end
function this:OnDestroy()
tabs = {}
if this.ScrollView then
SubUIManager.Close(this.ScrollView)
this.ScrollView = nil
end
itemList = {}
end
return this