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

589 lines
21 KiB
Lua

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")
this.leftBtn = Util.GetGameObject(this.tabbox, "leftAction")
this.rightBtn = Util.GetGameObject(this.tabbox, "rightAction")
this.jiantouyou = Util.GetGameObject(this.tabbox, "jiantouyou")
this.jiantouzuo = Util.GetGameObject(this.tabbox, "jiantouzuo")
this.mask1 = Util.GetGameObject(this.tabbox, "mask"):GetComponent("Image")
this.mask2 = Util.GetGameObject(this.tabbox, "mask1"):GetComponent("Image")
this.select = Util.GetGameObject(this.tabbox, "select")
this.selectIma = Util.GetGameObject(this.select, "Image"):GetComponent("Image")
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
this.pos0 = Vector3.New(this.off * (0 - 2) + (0 - 1) * this.itemWidth - 30,0,0)
self.lastPage,self.curPage,self.nextPage = 0,0,0
this.trigger = Util.GetEventTriggerListener(this.gameObject) --触摸事件
end
function this.RemoveTrigger()
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.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)
end
---设置拖动左右方向
function this.SetPos(v2)
if isEnter == 1 then
if v2.x > 2 then
isEnter = 2 --右
elseif v2.x < -2 then
isEnter = 3 --左
end
end
end
---手指拖动结束 ui归位
function this.MoveTo(LOR,func)
if LOR < 2 then
return
end
this.select.gameObject:SetActive(false)
for i = 1,#this.itemList do
this.itemList[i].move = true
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
this.itemList[i].move = false
if func then
func()
end
end):SetEase(Ease.Linear)
end
end
function this.OnBeginDrag(Pointgo, data)
if isEnter == 0 then
isEnter = 1
end
end
function this.OnDrag(Pointgo, data)
if isEnter == 1 then
this.SetPos(data.delta)
end
end
function this.OnEndDrag(Pointgo, data)
if isEnter < 1 then
return
end
local ro = isEnter
isEnter = 1
this.mask:SetActive(true)
local localIsenter = false
this.RemoveTrigger()
this.thread1 = coroutine.start(function()
this.MoveTo(ro)
--coroutine.wait(0.2/(this.itemWidth + this.off))
while(not localIsenter) do
local isfinish = true
for j = 1,#this.itemList do
if this.itemList[j].move then
isfinish = false
break
end
end
if isfinish then
localIsenter = true
end
coroutine.wait(0.2/(this.itemWidth + this.off))
end
this.SortItemList()
if ro == 2 then
this:RightAction()
elseif ro == 3 then
this:LeftAction()
end
this.mask:SetActive(false)
this.AddTrigger()
isEnter = 0
end)
end
--绑定事件(用于子类重写)
function RecruitMainPanel:BindEvent()
-- 关闭界面打开主城
Util.AddClick(this.btnBack, function()
this:ClosePanel()
end)
Util.AddClick(this.leftBtn, function()
local localIsenter = false
this.mask:SetActive(true)
this.RemoveTrigger()
self.thread = coroutine.start(function()
this.MoveTo(3)
--coroutine.wait(0.2/(this.itemWidth + this.off))
while(not localIsenter) do
local isfinish = true
for j = 1,#this.itemList do
if this.itemList[j].move then
isfinish = false
break
end
end
if isfinish then
localIsenter = true
end
coroutine.wait(0.2/(this.itemWidth + this.off))
end
this.SortItemList()
this:LeftAction()
this.mask:SetActive(false)
this.AddTrigger()
end)
end)
Util.AddClick(this.rightBtn, function()
local localIsenter = false
this.mask:SetActive(true)
this.RemoveTrigger()
self.thread = coroutine.start(function()
this.MoveTo(2)
--coroutine.wait(0.2/(this.itemWidth + this.off))
while(not localIsenter) do
local isfinish = true
for j = 1,#this.itemList do
if this.itemList[j].move then
isfinish = false
break
end
end
if isfinish then
localIsenter = true
end
coroutine.wait(0.2/(this.itemWidth + this.off))
end
this.SortItemList()
this:RightAction()
this.mask:SetActive(false)
this.AddTrigger()
coroutine.yield()
end)
end)
Util.AddClick(this.jiantouyou , function()
this.mask:SetActive(true)
this.RemoveTrigger()
for i = self.curPage - 1,1,-1 do
if self.dicData[i].RpType and self.dicData[i].RpType > 0 then
if RecruitManager.GetAllRecruitBtnRedpoint(self.dicData[i].RpType) then
lastIndex = self.curPage
self.curPage = i
break
end
end
end
self.CurRecruitId = self.dicData[self.curPage].ShopData[1][1]
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
this:SetIndex()
end)
Util.AddClick(this.jiantouzuo , function()
this.mask:SetActive(true)
this.RemoveTrigger()
for i = self.curPage + 1,#self.dicData,1 do
if self.dicData[i].RpType and self.dicData[i].RpType > 0 then
if RecruitManager.GetAllRecruitBtnRedpoint(self.dicData[i].RpType) then
lastIndex = self.curPage
self.curPage = i
break
end
end
end
self.CurRecruitId = self.dicData[self.curPage].ShopData[1][1]
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
this:SetIndex()
end)
end
function RecruitMainPanel:RefreshJianTou()
local index = 0
for i = self.curPage - 1,1,-1 do
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
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
end
--添加事件监听(用于子类重写)
function RecruitMainPanel:AddListener()
end
--移除事件监听(用于子类重写)
function RecruitMainPanel:RemoveListener()
end
local redSort = {
[1] = 3,
[2] = 2,
[3] = 1,
[4] = 4,
[5] = 5,
}
--界面打开时调用(用于子类重写)
function RecruitMainPanel:OnOpen(_index)
if not _index then
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
elseif GuideManager.IsFunctionGuideExist() and GuideManager.curId == 101402 then
self.CurRecruitId = TableRecruitType.Siyuanzhen
elseif GuideManager.IsFunctionGuideExist() and GuideManager.curId == 103705 then
self.CurRecruitId = TableRecruitType.Shenjiang
else
local data = RecruitManager.GetRecruitData()
local isRed = 0
table.sort(data,function(a,b)
return redSort[a.Sort] < redSort[b.Sort]
end)
for i = 1,#data do
if data[i].RpType and data[i].RpType > 0 then
if RecruitManager.GetAllRecruitBtnRedpoint(data[i].RpType) then
isRed = data[i].ShopData[1][1]
break
end
end
end
if isRed > 0 then
self.CurRecruitId = isRed
else
self.CurRecruitId = TableRecruitType.Shenjiang
end
end
else
self.CurRecruitId = _index
end
end
-- 打开,重新打开时回调
function RecruitMainPanel:OnShow()
orginLayer = self.sortingOrder
self.dicData = RecruitManager.GetRecruitData()
this:RefreshTabData()
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
this.RemoveTrigger()
this:PageOnChange(false)
this:SetIndex(self.curPage)
end
function this:RefreshTabData()
--local curIndex = 0
--清除红点
for k,v in pairs(redPointTypeList) do
ClearRedPointObject(k,v)
end
redPointTypeList = {}
-- 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)
else
if not this.itemList[i] then
this.itemList[i] = {}
this.itemList[i].move = false
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
if #self.dicData==1 then
vec.x=this.off * (#this.itemList - 1) + (#this.itemList) * this.itemWidth - 30
else
vec.x = this.off * (i - 2) + (i - 1) * this.itemWidth - 30
end
vec.y = 0
this.itemList[i].tran.anchoredPosition = vec
this.itemList[i].pos = this.itemList[i].tran.anchoredPosition
this.itemList[i].index = i
--TODO /// 改了配置之后可以放开 2023 11、2
this.itemList[i].img = Util.GetGameObject(this.itemList[i].go, "img"):GetComponent("Image")
this.itemList[i].tipObj=Util.GetGameObject(this.itemList[i].go,"tipObj")
this.itemList[i].tipTxt=Util.GetGameObject(this.itemList[i].go,"tipObj/Text"):GetComponent("Text")
this.itemList[i].titleTxt=Util.GetGameObject(this.itemList[i].go,"Text"):GetComponent("Text")
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].tipObj:SetActive(false)
this.itemList[i].titleTxt.text=self.dicData[i].Sesc
this.itemList[i].img.sprite = this.spLoader:LoadSprite(self.dicData[i].Icon[1])
local isOpen=true
local tip=""
if self.dicData[i].ActId==2 then
isOpen =CheckFunctionOpen(FUNCTION_OPEN_TYPE.EquipWish)
tip=GetFunctionOpenTip(FUNCTION_OPEN_TYPE.EquipWish)
elseif self.dicData[i].ActId==121 then
isOpen=CheckFunctionOpenClient(FUNCTION_OPEN_TYPE.ChouJiangRukou)
tip=GetFunctionOpenTipClient(FUNCTION_OPEN_TYPE.ChouJiangRukou)
end
this.itemList[i].tipObj:SetActive(not isOpen)
this.itemList[i].tipTxt.text=tip
BindRedPointObject(self.dicData[i].RpType,this.itemList[i].redpot)
redPointTypeList[self.dicData[i].RpType] = this.itemList[i].redpot
end
end
this.pos4 = Vector3.New(this.off * (#this.itemList - 1) + (#this.itemList) * this.itemWidth - 30,0,0)
--print(tostring(this.pos4))
LogError(tostring(this.pos4))
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
this:RefreshJianTou()
this.AddTrigger()
this:PageOnChange(true)
this.mask:SetActive(false)
return
else
local LOY = 0
if this.itemList[i].index - 2 > 0 then
LOY = 3
else
LOY = 2
end
local offSet = math.abs(this.itemList[i].index - 2)
local localIsenter = true
self.thread = coroutine.start(function()
while(offSet > 0) do
if localIsenter then
localIsenter = false
this.MoveTo(LOY)
--coroutine.wait(0.2/(this.itemWidth + this.off))
while(not localIsenter) do
local isfinish = true
for j = 1,#this.itemList do
if this.itemList[j].move then
isfinish = false
break
end
end
if isfinish then
offSet = offSet - 1
this.SortItemList()
localIsenter = true
end
coroutine.wait(0.2/(this.itemWidth + this.off))
end
end
end
this:RefreshJianTou()
this.AddTrigger()
this:PageOnChange(true)
this.mask:SetActive(false)
end)
end
break
end
end
end
function this:PageOnChange(isShow)
if isShow then
for i = 1,#this.itemList do
if this.itemList[i].pageIndex == self.curPage then
this.select.transform:SetParent(this.itemList[i].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])
this.itemList[i].tipObj.transform:SetAsLastSibling()
end
end
end
for k,v in pairs(subViewList) do
if k ~= self.curPage then
v.sub:OnClose()
end
end
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
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
this:RefreshJianTou()
this:PageOnChange(true)
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
this:RefreshJianTou()
this:PageOnChange(true)
end
function this:OnSortingOrderChange()
orginLayer = self.sortingOrder
for k,v in pairs(subViewList) do
v.sub:OnSortingOrderChange(self.sortingOrder)
end
end
--界面关闭时调用(用于子类重写)
function RecruitMainPanel:OnClose()
for k,v in pairs(subViewList) do
v.sub:OnClose()
end
--清除红点
this.select.transform:SetParent(this.tabbox.transform)
if self.thread then
coroutine.stop(self.thread)
self.thread = nil
end
if this.thread1 then
coroutine.stop(this.thread1)
self.thread = nil
end
for k,v in pairs(redPointTypeList) do
ClearRedPointObject(k,v)
end
redPointTypeList = {}
ClearChild(this.grid)
this.itemList = {}
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
ClearChild(this.grid)
this.itemList = {}
subViewList = {}
self.dicData = {}
SubUIManager.Close(this.upView)
this.upView = nil
end
return this