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

134 lines
3.7 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
if i == 1 then
2021-01-04 11:39:58 +08:00
friendHelpHeros = MonsterCampManager.GetFriendHelpHeros(curType)
2020-12-10 16:23:13 +08:00
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]
myHeros = HeroManager.GetHeroDataByProperty(curType,0)
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-04 15:12:37 +08:00
this.empty:SetActive(false)
this:SortHeros(data)
2021-01-04 11:39:58 +08:00
this.ScrollView:SetData(data,function(index,go)
--this:SetSingleData(index,go,data[index])
LogGreen(go.name)
local tempData = FourTrailSingleHelpHero:New(go)
2021-02-04 15:12:37 +08:00
tempData:OnOpen(curIndex,data[index],curType,heightPower)
local tempId = curIndex == 1 and data[index].hero.dynamicId or data[index].dynamicId
2021-01-04 11:39:58 +08:00
itemList[tempId] = tempData
2021-02-04 15:12:37 +08:00
end)
2020-12-08 17:01:53 +08:00
end
function this:OnClose()
2021-02-04 15:12:37 +08:00
tabs = {}
2020-12-08 17:01:53 +08:00
end
function this:OnDestroy()
2021-02-04 15:12:37 +08:00
tabs = {}
2020-12-10 16:23:13 +08:00
itemList = {}
2020-12-08 17:01:53 +08:00
end
return this