miduo_client/Assets/ManagedResources/~Lua/Modules/Recruit/RecruitMainPanel.lua

480 lines
17 KiB
Lua
Raw Normal View History

2021-07-08 18:40:43 +08:00
require("Base/BasePanel")
local RecruitMainPanel = Inherit(BasePanel)
local this = RecruitMainPanel
local GlobalActConfig = ConfigManager.GetConfig(ConfigName.GlobalActivity)
local _CurPageIndex = 0
local orginLayer
local redPointTypeList = {}
local subViewList = {}
local isEnter = 0
local lastIndex = 0
--初始化组件(用于子类重写)
function RecruitMainPanel:InitComponent()
this.spLoader = SpriteLoader.New()
orginLayer = 0
this.mask = Util.GetGameObject(self.gameObject,"mask")
this.mask:SetActive(false)
this.tabbox = Util.GetGameObject(self.gameObject, "bg/tabbox")
this.btnBack = Util.GetGameObject(self.gameObject, "bg/btnBack")
this.content = Util.GetGameObject(self.gameObject, "bg/pageContent")
this.item = Util.GetGameObject(this.tabbox, "tab")
this.grid = Util.GetGameObject(this.tabbox, "box")
2021-07-16 14:18:25 +08:00
this.leftBtn = Util.GetGameObject(this.tabbox, "leftAction")
this.rightBtn = Util.GetGameObject(this.tabbox, "rightAction")
2021-07-10 18:12:50 +08:00
this.jiantouyou = Util.GetGameObject(this.tabbox, "jiantouyou")
this.jiantouzuo = Util.GetGameObject(this.tabbox, "jiantouzuo")
2021-07-15 19:40:09 +08:00
this.mask1 = Util.GetGameObject(this.tabbox, "mask"):GetComponent("Image")
this.mask2 = Util.GetGameObject(this.tabbox, "mask1"):GetComponent("Image")
2021-07-08 18:40:43 +08:00
this.select = Util.GetGameObject(this.tabbox, "select")
this.selectIma = Util.GetGameObject(this.select, "Image"):GetComponent("Image")
2021-07-08 18:40:43 +08:00
this.select.gameObject:SetActive(false)
this.upView = SubUIManager.Open(SubUIConfig.UpView,self.gameObject.transform)
this.itemList = {}
this.moveWidth = this.grid:GetComponent("RectTransform").rect.width
this.itemWidth = this.item:GetComponent("RectTransform").rect.width
this.off = 51
2021-07-10 18:12:50 +08:00
-- for i = 1,this.count do
-- if not this.itemList[i] then
-- this.itemList[i] = {}
-- this.itemList[i].go = newObjToParent(this.item,this.grid)
-- this.itemList[i].go.name = "tab_"..i
-- this.itemList[i].tran = this.itemList[i].go:GetComponent("RectTransform")
-- local vec = this.itemList[i].tran.anchoredPosition
-- vec.x = this.off * (i - 1) + i * this.itemWidth
-- vec.y = 0
-- this.itemList[i].tran.anchoredPosition = vec
-- this.itemList[i].pos = this.itemList[i].tran.anchoredPosition
-- this.itemList[i].index = i
-- this.itemList[i].img = Util.GetGameObject(this.itemList[i].go, "img"):GetComponent("Image")
-- this.itemList[i].redpot = Util.GetGameObject(this.itemList[i].go, "redpot")
-- end
-- end
this.pos0 = Vector3.New(this.off * (0 - 2) + (0 - 1) * this.itemWidth - 30,50,0)
2021-07-16 14:09:53 +08:00
--LogGreen("this.pos0:"..tostring(this.pos0))
2021-07-10 18:12:50 +08:00
--this.pos4 = Vector3.New(this.off * (4 - 1) + 4 * this.itemWidth,0,0)
2021-07-08 18:40:43 +08:00
self.lastPage,self.curPage,self.nextPage = 0,0,0
2021-07-20 10:08:06 +08:00
this.AddTrigger()
end
2021-07-08 18:40:43 +08:00
2021-07-20 10:08:06 +08:00
function this.RemoveTrigger()
this.trigger = Util.GetEventTriggerListener(this.gameObject) --触摸事件
this.trigger.onBeginDrag = this.trigger.onBeginDrag - this.OnBeginDrag
this.trigger.onDrag = this.trigger.onDrag - this.OnDrag
this.trigger.onEndDrag = this.trigger.onEndDrag - this.OnEndDrag
end
function this.AddTrigger()
this.trigger = Util.GetEventTriggerListener(this.gameObject) --触摸事件
2021-07-08 18:40:43 +08:00
this.trigger.onBeginDrag = this.trigger.onBeginDrag + this.OnBeginDrag
this.trigger.onDrag = this.trigger.onDrag + this.OnDrag
this.trigger.onEndDrag = this.trigger.onEndDrag + this.OnEndDrag
end
function this.SortItemList()
table.sort(this.itemList,function(a,b)
return a.index < b.index
end)
2021-07-08 18:40:43 +08:00
end
---设置位置
function this.SetPos(v2)
2021-07-08 18:40:43 +08:00
if isEnter == 1 then
if v2.x > 2 then
isEnter = 0 --右
this.MoveTo(2,function()
isEnter = 2
end)
2021-07-08 18:40:43 +08:00
elseif v2.x < -2 then
isEnter = 0 --左
this.MoveTo(3,function()
isEnter = 3
end)
2021-07-08 18:40:43 +08:00
end
end
end
---手指拖动结束 ui归位
function this.MoveTo(LOR,func)
this.select.gameObject:SetActive(false)
for i = 1,#this.itemList do
local targetPos = ""
if LOR == 2 then
if i + 1 > #this.itemList then
targetPos = 1
this.itemList[i].tran.anchoredPosition = this.pos0
else
targetPos = i + 1
end
elseif LOR == 3 then
if i - 1 < 1 then
targetPos = #this.itemList
this.itemList[i].tran.anchoredPosition = this.pos4
else
targetPos = i - 1
end
end
local targetPos1 = this.itemList[targetPos].pos
this.itemList[i].go.transform:DOAnchorPos(targetPos1, 0.2, false)
:OnStart(function() end)
:OnUpdate(function()end)
:OnComplete(function ()
this.itemList[i].index = targetPos
this.itemList[i].pos = targetPos1
if func then
func()
end
end):SetEase(Ease.Linear)
end
2021-07-08 18:40:43 +08:00
end
function this.OnBeginDrag(Pointgo, data)
if isEnter == 0 then
isEnter = 1
end
2021-07-08 18:40:43 +08:00
end
function this.OnDrag(Pointgo, data)
this.SetPos(data.delta)
end
function this.OnEndDrag(Pointgo, data)
Timer.New(function()
if isEnter == 2 or isEnter == 3 then
--this.SetPos(data.delta)
this.SortItemList()
if isEnter == 2 then
this:RightAction()
elseif isEnter == 3 then
this:LeftAction()
end
isEnter = 0
end
end,0.23):Start()
2021-07-08 18:40:43 +08:00
end
--绑定事件(用于子类重写)
function RecruitMainPanel:BindEvent()
-- 关闭界面打开主城
Util.AddClick(this.btnBack, function()
this:ClosePanel()
end)
2021-07-16 14:18:25 +08:00
Util.AddClick(this.leftBtn, function()
this.mask:SetActive(true)
2021-07-19 21:35:11 +08:00
self.thread = coroutine.start(function()
coroutine.wait(0.01)
this.MoveTo(3)
coroutine.wait(0.25)
2021-07-16 14:18:25 +08:00
this.SortItemList()
2021-07-19 21:35:11 +08:00
coroutine.wait(0.01)
2021-07-16 14:18:25 +08:00
this:LeftAction()
this.mask:SetActive(false)
2021-07-19 21:35:11 +08:00
end)
2021-07-16 14:18:25 +08:00
end)
Util.AddClick(this.rightBtn, function()
this.mask:SetActive(true)
2021-07-19 21:35:11 +08:00
self.thread = coroutine.start(function()
coroutine.wait(0.01)
this.MoveTo(2)
coroutine.wait(0.25)
2021-07-16 14:18:25 +08:00
this.SortItemList()
2021-07-19 21:35:11 +08:00
coroutine.wait(0.01)
2021-07-16 14:18:25 +08:00
this:RightAction()
this.mask:SetActive(false)
2021-07-19 21:35:11 +08:00
end)
2021-07-16 14:18:25 +08:00
end)
2021-07-10 18:12:50 +08:00
Util.AddClick(this.jiantouyou , function()
this.mask:SetActive(true)
for i = self.curPage - 1,1,-1 do
2021-07-10 18:12:50 +08:00
if self.dicData[i].RpType and self.dicData[i].RpType > 0 then
if RecruitManager.GetAllRecruitBtnRedpoint(self.dicData[i].RpType) then
lastIndex = self.curPage
2021-07-10 18:12:50 +08:00
self.curPage = i
break
end
end
end
2021-07-16 10:30:56 +08:00
self.CurRecruitId = self.dicData[self.curPage].ShopData[1][1]
2021-07-10 18:12:50 +08:00
self.lastPage = self.curPage - 1 > 0 and self.curPage - 1 or #self.dicData
self.nextPage = self.curPage + 1 > #self.dicData and 1 or self.curPage + 1
2021-07-10 18:12:50 +08:00
this:SetIndex()
2021-07-19 11:58:43 +08:00
this:PageOnChange(true)
2021-07-10 18:12:50 +08:00
end)
Util.AddClick(this.jiantouzuo , function()
this.mask:SetActive(true)
for i = self.curPage + 1,#self.dicData,1 do
2021-07-10 18:12:50 +08:00
if self.dicData[i].RpType and self.dicData[i].RpType > 0 then
if RecruitManager.GetAllRecruitBtnRedpoint(self.dicData[i].RpType) then
lastIndex = self.curPage
2021-07-10 18:12:50 +08:00
self.curPage = i
break
end
end
end
2021-07-16 10:30:56 +08:00
self.CurRecruitId = self.dicData[self.curPage].ShopData[1][1]
2021-07-10 18:12:50 +08:00
self.lastPage = self.curPage - 1 > 0 and self.curPage - 1 or #self.dicData
self.nextPage = self.curPage + 1 > #self.dicData and 1 or self.curPage + 1
2021-07-10 18:12:50 +08:00
this:SetIndex()
2021-07-19 11:58:43 +08:00
this:PageOnChange(true)
2021-07-10 18:12:50 +08:00
end)
end
function RecruitMainPanel:RefreshJianTou()
local index = 0
for i = self.curPage - 1,1,-1 do
2021-07-10 18:12:50 +08:00
if self.dicData[i].RpType and self.dicData[i].RpType > 0 then
if RecruitManager.GetAllRecruitBtnRedpoint(self.dicData[i].RpType) then
index = i
break
end
end
end
if index == 0 then
this.jiantouyou.gameObject:SetActive(false)
else
this.jiantouyou.gameObject:SetActive(true)
end
index = 0
for i = self.curPage + 1,#self.dicData,1 do
2021-07-10 18:12:50 +08:00
if self.dicData[i].RpType and self.dicData[i].RpType > 0 then
if RecruitManager.GetAllRecruitBtnRedpoint(self.dicData[i].RpType) then
index = i
break
end
end
end
if index == 0 then
this.jiantouzuo.gameObject:SetActive(false)
else
this.jiantouzuo.gameObject:SetActive(true)
end
2021-07-08 18:40:43 +08:00
end
--添加事件监听(用于子类重写)
function RecruitMainPanel:AddListener()
end
--移除事件监听(用于子类重写)
function RecruitMainPanel:RemoveListener()
end
--界面打开时调用(用于子类重写)
function RecruitMainPanel:OnOpen(_index)
if not _index then
2021-07-16 11:19:36 +08:00
if GuideManager.IsInMainGuide() and GuideManager.GetCurId(1) == 105 then
self.CurRecruitId = TableRecruitType.Putong
elseif GuideManager.IsInMainGuide() and GuideManager.GetCurId(1) == 1003 then
self.CurRecruitId = TableRecruitType.Shenjiang
2021-07-16 14:09:53 +08:00
elseif GuideManager.IsFunctionGuideExist() then
self.CurRecruitId = TableRecruitType.Siyuanzhen
2021-07-16 11:19:36 +08:00
else
self.CurRecruitId = RecruitManager.CurRecruitId
end
2021-07-08 18:40:43 +08:00
else
self.CurRecruitId = _index
RecruitManager.CurRecruitId = _index
end
end
-- 打开,重新打开时回调
function RecruitMainPanel:OnShow()
orginLayer = self.sortingOrder
self.dicData = RecruitManager.GetRecruitData()
2021-07-10 18:12:50 +08:00
this:RefreshTabData()
2021-07-08 18:40:43 +08:00
for i = 1,#self.dicData do
if self.dicData[i].ShopData[1][1] == self.CurRecruitId then
self.curPage = i
break
end
end
self.lastPage = self.curPage - 1 > 0 and self.curPage - 1 or #self.dicData
self.nextPage = self.curPage + 1 > #self.dicData and 1 or self.curPage + 1
lastIndex = self.curPage
2021-07-10 18:12:50 +08:00
this:SetIndex(self.curPage)
2021-07-19 11:58:43 +08:00
this:PageOnChange(false)
2021-07-08 18:40:43 +08:00
end
function this:RefreshTabData()
2021-07-10 18:12:50 +08:00
--local curIndex = 0
2021-07-10 14:56:28 +08:00
--清除红点
for k,v in pairs(redPointTypeList) do
ClearRedPointObject(k,v)
end
redPointTypeList = {}
2021-07-10 18:12:50 +08:00
-- for i = 1,#this.itemList do
-- if i == 1 then
-- curIndex = self.lastPage
-- elseif i == 2 then
-- curIndex = self.curPage
-- else
-- curIndex = self.nextPage
-- end
-- this.itemList[i].img.sprite = this.spLoader:LoadSprite(self.dicData[curIndex].Icon[1])
-- BindRedPointObject(self.dicData[curIndex].RpType,this.itemList[i].redpot)
-- redPointTypeList[self.dicData[curIndex].RpType] = this.itemList[i].redpot
-- end
for i = 1,math.max(#this.itemList,#self.dicData) do
if not self.dicData[i] then
this.itemList[i].go.gameObject:SetActive(false)
2021-07-08 18:40:43 +08:00
else
2021-07-10 18:12:50 +08:00
if not this.itemList[i] then
this.itemList[i] = {}
this.itemList[i].go = newObjToParent(this.item,this.grid)
this.itemList[i].go.name = "tab_"..i
this.itemList[i].tran = this.itemList[i].go:GetComponent("RectTransform")
local vec = this.itemList[i].tran.anchoredPosition
vec.x = this.off * (i - 2) + (i - 1) * this.itemWidth - 30
vec.y = 50
2021-07-10 18:12:50 +08:00
this.itemList[i].tran.anchoredPosition = vec
2021-07-16 14:09:53 +08:00
--LogGreen("vec:"..i.." "..tostring(vec))
2021-07-10 18:12:50 +08:00
this.itemList[i].pos = this.itemList[i].tran.anchoredPosition
this.itemList[i].index = i
this.itemList[i].img = Util.GetGameObject(this.itemList[i].go, "img"):GetComponent("Image")
this.itemList[i].redpot = Util.GetGameObject(this.itemList[i].go, "redpot")
this.itemList[i].pageIndex = i
end
this.itemList[i].go.gameObject:SetActive(true)
this.itemList[i].img.sprite = this.spLoader:LoadSprite(self.dicData[i].Icon[1])
BindRedPointObject(self.dicData[i].RpType,this.itemList[i].redpot)
redPointTypeList[self.dicData[i].RpType] = this.itemList[i].redpot
end
end
2021-07-16 10:18:57 +08:00
this.pos4 = Vector3.New(this.off * (#this.itemList - 1) + (#this.itemList) * this.itemWidth - 30,50,0)
2021-07-16 14:09:53 +08:00
--LogGreen("this.pos4:"..tostring(this.pos4))
2021-07-10 18:12:50 +08:00
end
function this:SetIndex()
for i = 1,#this.itemList do
if this.itemList[i].pageIndex == self.curPage then
if this.itemList[i].index == 2 then
return
else
local LOY = 0
if this.itemList[i].index - 2 > 0 then
LOY = 3
else
LOY = 2
2021-07-16 16:54:17 +08:00
end
local offSet = math.abs(this.itemList[i].index - 2)
local isenter = true
self.thread = coroutine.start(function()
while(offSet > 0) do
2021-07-10 18:12:50 +08:00
if isenter then
isenter = false
this.mask:SetActive(true)
this.MoveTo(LOY)
2021-07-19 21:35:11 +08:00
coroutine.wait(0.25)
offSet = offSet - 1
this.SortItemList()
isenter = true
2021-07-16 16:54:17 +08:00
end
coroutine.wait(0.01)
2021-07-10 18:12:50 +08:00
end
this.mask:SetActive(false)
2021-07-10 18:27:28 +08:00
this:RefreshJianTou()
2021-07-19 11:58:43 +08:00
this:PageOnChange(true)
2021-07-10 18:12:50 +08:00
end)
end
break
end
2021-07-08 18:40:43 +08:00
end
end
2021-07-19 11:58:43 +08:00
function this:PageOnChange(isShow)
if isShow then
this.select.transform:SetParent(this.itemList[2].go.transform)
this.select.transform:GetComponent("RectTransform").anchoredPosition = Vector3.zero
this.select.gameObject:SetActive(true)
this.selectIma.sprite = this.spLoader:LoadSprite(self.dicData[self.curPage].Icon[2])
end
2021-07-08 18:40:43 +08:00
RecruitManager.CurRecruitId = self.CurRecruitId
if subViewList[lastIndex] and subViewList[lastIndex].config and subViewList[lastIndex].sub then
subViewList[lastIndex].sub:OnClose()
2021-07-16 16:54:17 +08:00
end
2021-07-08 18:40:43 +08:00
if subViewList[self.curPage] and subViewList[self.curPage].config and subViewList[self.curPage].sub then
subViewList[self.curPage].sub:OnShow(orginLayer)
else
subViewList[self.curPage] = {}
if self.dicData[self.curPage].UIName then
subViewList[self.curPage].config = SubUIConfig[self.dicData[self.curPage].UIName[1]]
subViewList[self.curPage].sub = SubUIManager.Open(subViewList[self.curPage].config,this.content.transform,self.dicData[self.curPage],self.curPage,this)
subViewList[self.curPage].sub:OnShow(orginLayer)
end
end
if self.dicData[self.curPage].UpView and #self.dicData[self.curPage].UpView > 0 then
this.upView:OnOpen({showType = self.dicData[self.curPage].UpView[1][1], panelType = self.dicData[self.curPage].UpView[2] })
this.upView.gameObject:SetActive(true)
else
this.upView.gameObject:SetActive(false)
end
end
function this:LeftAction()
lastIndex = self.curPage
2021-07-08 18:40:43 +08:00
self.CurRecruitId = self.dicData[self.nextPage].ShopData[1][1]
self.lastPage = self.curPage
self.curPage = self.nextPage
self.nextPage = self.curPage + 1 > #self.dicData and 1 or self.curPage + 1
2021-07-10 18:27:28 +08:00
this:RefreshJianTou()
2021-07-19 11:58:43 +08:00
this:PageOnChange(true)
2021-07-08 18:40:43 +08:00
end
function this:RightAction()
lastIndex = self.curPage
self.CurRecruitId = self.dicData[self.lastPage].ShopData[1][1]
self.nextPage = self.curPage
self.curPage = self.lastPage
self.lastPage = self.curPage - 1 > 0 and self.curPage - 1 or #self.dicData
2021-07-10 18:27:28 +08:00
this:RefreshJianTou()
2021-07-19 11:58:43 +08:00
this:PageOnChange(true)
2021-07-08 18:40:43 +08:00
end
function this:OnSortingOrderChange()
orginLayer = self.sortingOrder
for k,v in pairs(subViewList) do
v.sub:OnSortingOrderChange(self.sortingOrder)
end
end
--界面关闭时调用(用于子类重写)
function RecruitMainPanel:OnClose()
2021-07-16 16:54:17 +08:00
--清除红点
this.select.transform:SetParent(this.tabbox.transform)
if self.thread then
coroutine.stop(self.thread)
self.thread = nil
end
2021-07-08 18:40:43 +08:00
for k,v in pairs(redPointTypeList) do
ClearRedPointObject(k,v)
end
redPointTypeList = {}
2021-07-10 18:12:50 +08:00
ClearChild(this.grid)
this.itemList = {}
2021-07-08 18:40:43 +08:00
end
--界面销毁时调用(用于子类重写)
function RecruitMainPanel:OnDestroy()
--清除红点
for k,v in pairs(redPointTypeList) do
ClearRedPointObject(k,v)
end
redPointTypeList = {}
--关闭弹窗界面
for k,v in pairs(subViewList) do
--UIManager.ClosePanel(k)
v.sub:OnDestroy()
this.spLoader:Destroy()
SubUIManager.Close(v.sub)
end
2021-07-10 18:12:50 +08:00
ClearChild(this.grid)
this.itemList = {}
2021-07-08 18:40:43 +08:00
subViewList = {}
self.dicData = {}
SubUIManager.Close(this.upView)
this.upView = nil
self.dicData = {}
end
return this