sk-client/Assets/ManagedResources/~Lua/Modules/PowerCenter/PowerCenteSelectrLinkPanel.lua

198 lines
6.4 KiB
Lua

require("Base/BasePanel")
PowerCenteSelectrLinkPanel = Inherit(BasePanel)
local this = PowerCenteSelectrLinkPanel
local PowerCenterConfig = ConfigManager.GetConfig(ConfigName.PowerCenterConfig)
local func, selectId, tabs = nil, nil, {}
local sortType = SortTypeConst.Natural
local proId = ProIdConst.All
local heros = {}
local lasetSelect = nil
--初始化组件(用于子类重写)
function PowerCenteSelectrLinkPanel:InitComponent()
this.btnCancel = Util.GetGameObject(this.gameObject, "btnCancel")
this.btnSure = Util.GetGameObject(this.gameObject, "btnSure")
this.btnBack = Util.GetGameObject(this.gameObject, "btnBack")
for i = 0, 5 do
tabs[i] = Util.GetGameObject(this.gameObject, "Tabs/grid/btn" .. i)
end
this.btnSort = Util.GetGameObject(this.gameObject, "Tabs/btnSort")
this.lv = Util.GetGameObject(this.gameObject, "Tabs/btnSort/lv")
this.quality = Util.GetGameObject(this.gameObject, "Tabs/btnSort/quality")
this.no = Util.GetGameObject(this.gameObject, "scroll/no")
local scroll = Util.GetGameObject(this.gameObject, "scroll").transform
local pre = Util.GetGameObject(scroll, "pre")
local v = scroll:GetComponent("RectTransform").rect
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, scroll,
pre, this.ScrollBar, Vector2.New(v.width, v.height), 1, 5, Vector2.New(5, 5))
this.ScrollView.moveTween.MomentumAmount = 1
this.ScrollView.moveTween.Strength = 1
end
--绑定事件(用于子类重写)
function PowerCenteSelectrLinkPanel:BindEvent()
Util.AddClick(this.btnCancel, function()
this:ClosePanel()
end)
Util.AddClick(this.btnSure, function()
this:ClosePanel()
if func and selectId then
func(selectId)
end
end)
Util.AddClick(this.btnBack, function()
this:ClosePanel()
end)
for i = 0, 5 do
Util.AddClick(tabs[i], function()
if i == proId then
proId = ProIdConst.All
else
proId = i
end
this.OnClickTabBtn()
end)
end
Util.AddClick(this.btnSort, function()
if sortType == SortTypeConst.Lv then
sortType = SortTypeConst.Natural
else
sortType = SortTypeConst.Lv
end
this.lv:SetActive(sortType ~= SortTypeConst.Lv)
this.quality:SetActive(sortType ~= SortTypeConst.Natural)
this.OnClickTabBtn()
end)
end
--添加事件监听(用于子类重写)
function PowerCenteSelectrLinkPanel:AddListener()
end
--移除事件监听(用于子类重写)
function PowerCenteSelectrLinkPanel:RemoveListener()
end
--界面打开时调用(用于子类重写)
function PowerCenteSelectrLinkPanel:OnOpen(_func)
func = _func
end
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
function PowerCenteSelectrLinkPanel:OnShow()
this.OnClickTabBtn()
end
--界面关闭时调用(用于子类重写)
function PowerCenteSelectrLinkPanel:OnClose()
end
--界面销毁时调用(用于子类重写)
function PowerCenteSelectrLinkPanel:OnDestroy()
heros = {}
lasetSelect = nil
func, selectId, tabs = nil, nil, {}
end
function this.OnClickTabBtn()
for i = 0, #tabs do
Util.GetGameObject(tabs[i], "select"):SetActive(i == proId)
end
for key, value in pairs(heros) do
value.gameObject:SetActive(false)
end
local heros = HeroManager.GetPowerCenterLinkHeros(proId)
-- if #heros > 0 then
-- this.SetScroll(heros)
-- end
this.SetScroll(heros)
this.ScrollView:SetData(heros, function(index, go)
this.SingleHeroDataShow(go, heros[index])
end)
this.no:SetActive(#heros == 0)
end
function this.SetScroll(datas)
table.sort(datas, function(a, b)
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
end)
end
function this.SingleHeroDataShow(go, data)
local pos = Util.GetGameObject(go, "pos")
local select = Util.GetGameObject(go, "select")
if not heros[go] then
heros[go] = SubUIManager.Open(SubUIConfig.ItemView, pos.transform)
end
heros[go]:OnOpen(false, {data.id, 0}, 0.9)
heros[go]:SetCorner(6, true, {lv = data.lv, star = data.star})
heros[go]:ClickEnable(false)
heros[go].gameObject:SetActive(true)
select:SetActive(lasetSelect == select)
Util.AddOnceClick(go, function ()
if lasetSelect then
lasetSelect:SetActive(false)
end
if select ~= lasetSelect then
lasetSelect = select
select:SetActive(true)
selectId = data.dynamicId
else
if lasetSelect then
lasetSelect = nil
selectId = nil
end
end
end)
end
return PowerCenteSelectrLinkPanel