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

150 lines
4.0 KiB
Lua
Raw Normal View History

2021-01-04 11:39:58 +08:00
require("View/FourTrailSingleHelpHero")
2020-12-08 17:01:53 +08:00
----- 易经宝库弹窗 -----
local this = {}
--传入父脚本模块
local parent
--传入特效层级
local sortingOrder=0
local itemList = {}--克隆预制体列表
2020-12-10 16:23:13 +08:00
local tabs = {}
2021-01-04 11:39:58 +08:00
local curIndex = 0
local friendHelpHeros = {}
local myHeros = {}
local heightPower = 0
local canHelpPower = 0
local rate = 0
2020-12-10 16:23:13 +08:00
local waveId = 0
2021-01-04 11:39:58 +08:00
local curType = 0
2020-12-10 16:23:13 +08:00
local configData = {}
2021-01-04 11:39:58 +08:00
2020-12-08 17:01:53 +08:00
function this:InitComponent(gameObject)
this.titleText=Util.GetGameObject(gameObject,"TitleText"):GetComponent("Text")
2020-12-10 16:23:13 +08:00
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")
2021-01-04 11:39:58 +08:00
this.empty = Util.GetGameObject(gameObject, "Empty")
for i = 1,this.tabRoot.transform.childCount do
2020-12-10 16:23:13 +08:00
table.insert(tabs,this.tabRoot.transform:GetChild(i - 1).gameObject)
end
2020-12-08 17:01:53 +08:00
local rootHight = this.Scroll.transform.rect.height
local width = this.Scroll.transform.rect.width
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.Scroll.transform,
2021-01-04 11:39:58 +08:00
this.itemPre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 0))
2020-12-08 17:01:53 +08:00
this.ScrollView.moveTween.MomentumAmount = 1
this.ScrollView.moveTween.Strength = 2
end
function this:BindEvent()
2020-12-10 16:23:13 +08:00
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
2021-01-04 11:39:58 +08:00
this.selectBtn.transform:SetAsFirstSibling()
2020-12-10 16:23:13 +08:00
curIndex = i
2021-02-04 17:41:44 +08:00
for k,v in pairs(itemList) do
v.gameObject:SetActive(false)
end
2021-01-04 11:39:58 +08:00
this:RefreshItemData()
2020-12-08 17:01:53 +08:00
end
function this:AddListener()
end
function this:RemoveListener()
end
function this:OnShow(_parent,...)
parent=_parent
sortingOrder = _parent.sortingOrder
2020-12-10 16:23:13 +08:00
local args = {...}
waveId = args[1]
2021-01-04 11:39:58 +08:00
curType = args[2]
2021-02-05 17:57:59 +08:00
friendHelpHeros = args[3]
myHeros = args[4]
2021-01-04 11:39:58 +08:00
this:SetMyHeightPower()
2021-02-04 15:12:37 +08:00
configData = ConfigManager.GetConfigDataByDoubleKey(ConfigName.CampTowerConfig,"FloorId",waveId,"CampId",curType)
this.titleText.text = FourElementName[curType]
2021-01-04 11:39:58 +08:00
rate = tonumber(string.format("%.2f",ConfigManager.GetConfigData(ConfigName.CampTowerSetting,1).HelpFightMax / 10000))
canHelpPower = heightPower*rate
2020-12-10 16:23:13 +08:00
this:BtnClick(1)
2020-12-08 17:01:53 +08:00
end
2021-01-04 11:39:58 +08:00
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)
2020-12-10 16:23:13 +08:00
end
2020-12-08 17:01:53 +08:00
2021-01-04 11:39:58 +08:00
function this:SetMyHeightPower()
heightPower = 0
for k,v in ipairs(myHeros) do
if v.warPower > heightPower then
heightPower = v.warPower
end
end
2020-12-10 16:23:13 +08:00
end
2020-12-08 17:01:53 +08:00
2021-01-04 11:39:58 +08:00
function this:RefreshItemData()
2021-02-04 15:12:37 +08:00
local data = nil
if curIndex == 1 then
data = friendHelpHeros
else
data = myHeros
end
2021-01-04 11:39:58 +08:00
if not data or #data < 1 then
this.empty:SetActive(true)
2021-02-04 15:12:37 +08:00
return
2020-12-08 17:01:53 +08:00
end
2021-02-05 17:57:59 +08:00
LogGreen(#data)
2021-02-04 15:12:37 +08:00
this.empty:SetActive(false)
this:SortHeros(data)
2021-02-05 17:57:59 +08:00
for k,v in pairs(itemList) do
v.gameObject:SetActive(false)
end
2021-01-04 11:39:58 +08:00
this.ScrollView:SetData(data,function(index,go)
2021-02-05 17:57:59 +08:00
if not itemList then
itemList = {}
end
if not itemList[go] then
itemList[go] = SubUIManager.Open(SubUIConfig.FourTrailSingleHelpHero,go.transform)
end
itemList[go].gameObject:SetActive(true)
LogGreen(tostring(data[index]))
itemList[go]:OnShow(curIndex,data[index],curType,heightPower)
2021-02-04 15:12:37 +08:00
end)
2020-12-08 17:01:53 +08:00
end
function this:OnClose()
2021-02-07 14:09:05 +08:00
curIndex = 0
2020-12-08 17:01:53 +08:00
end
function this:OnDestroy()
2021-02-04 15:12:37 +08:00
tabs = {}
2021-02-05 17:57:59 +08:00
for k,v in pairs(itemList) do
SubUIManager.Close(v)
end
2021-02-04 17:41:44 +08:00
if this.ScrollView then
SubUIManager.Close(this.ScrollView)
this.ScrollView = nil
end
2020-12-10 16:23:13 +08:00
itemList = {}
2020-12-08 17:01:53 +08:00
end
return this