滑动修改提交

dev_chengFeng
jiaoyangna 2021-07-20 17:08:36 +08:00
parent 1e80b80c82
commit 5cac652fa3
1 changed files with 48 additions and 29 deletions

View File

@ -56,18 +56,17 @@ function RecruitMainPanel:InitComponent()
--LogGreen("this.pos0:"..tostring(this.pos0)) --LogGreen("this.pos0:"..tostring(this.pos0))
--this.pos4 = Vector3.New(this.off * (4 - 1) + 4 * this.itemWidth,0,0) --this.pos4 = Vector3.New(this.off * (4 - 1) + 4 * this.itemWidth,0,0)
self.lastPage,self.curPage,self.nextPage = 0,0,0 self.lastPage,self.curPage,self.nextPage = 0,0,0
this.trigger = Util.GetEventTriggerListener(this.gameObject) --触摸事件
this.AddTrigger() this.AddTrigger()
end end
function this.RemoveTrigger() function this.RemoveTrigger()
this.trigger = Util.GetEventTriggerListener(this.gameObject) --触摸事件
this.trigger.onBeginDrag = this.trigger.onBeginDrag - this.OnBeginDrag this.trigger.onBeginDrag = this.trigger.onBeginDrag - this.OnBeginDrag
this.trigger.onDrag = this.trigger.onDrag - this.OnDrag this.trigger.onDrag = this.trigger.onDrag - this.OnDrag
this.trigger.onEndDrag = this.trigger.onEndDrag - this.OnEndDrag this.trigger.onEndDrag = this.trigger.onEndDrag - this.OnEndDrag
end end
function this.AddTrigger() function this.AddTrigger()
this.trigger = Util.GetEventTriggerListener(this.gameObject) --触摸事件
this.trigger.onBeginDrag = this.trigger.onBeginDrag + this.OnBeginDrag this.trigger.onBeginDrag = this.trigger.onBeginDrag + this.OnBeginDrag
this.trigger.onDrag = this.trigger.onDrag + this.OnDrag this.trigger.onDrag = this.trigger.onDrag + this.OnDrag
this.trigger.onEndDrag = this.trigger.onEndDrag + this.OnEndDrag this.trigger.onEndDrag = this.trigger.onEndDrag + this.OnEndDrag
@ -83,21 +82,18 @@ end
function this.SetPos(v2) function this.SetPos(v2)
if isEnter == 1 then if isEnter == 1 then
if v2.x > 2 then if v2.x > 2 then
isEnter = 0 --右 isEnter = 2 --右
this.MoveTo(2,function()
isEnter = 2
end)
elseif v2.x < -2 then elseif v2.x < -2 then
isEnter = 0 --左 isEnter = 3 --左
this.MoveTo(3,function()
isEnter = 3
end)
end end
end end
end end
---手指拖动结束 ui归位 ---手指拖动结束 ui归位
function this.MoveTo(LOR,func) function this.MoveTo(LOR,func)
if LOR < 2 then
return
end
this.select.gameObject:SetActive(false) this.select.gameObject:SetActive(false)
for i = 1,#this.itemList do for i = 1,#this.itemList do
local targetPos = "" local targetPos = ""
@ -136,21 +132,35 @@ function this.OnBeginDrag(Pointgo, data)
end end
end end
function this.OnDrag(Pointgo, data) function this.OnDrag(Pointgo, data)
if isEnter == 1 then
this.SetPos(data.delta) this.SetPos(data.delta)
end end
end
function this.OnEndDrag(Pointgo, data) function this.OnEndDrag(Pointgo, data)
Timer.New(function() if isEnter < 1 then
if isEnter == 2 or isEnter == 3 then return
--this.SetPos(data.delta) end
local ro = isEnter
isEnter = 1
this.mask:SetActive(true)
this.thread1 = coroutine.start(function()
this.RemoveTrigger()
coroutine.wait(0.01)
this.MoveTo(ro)
coroutine.wait(0.25)
this.SortItemList() this.SortItemList()
if isEnter == 2 then coroutine.wait(0.1)
if ro == 2 then
this:RightAction() this:RightAction()
elseif isEnter == 3 then elseif ro == 3 then
this:LeftAction() this:LeftAction()
end end
coroutine.wait(0.01)
this.mask:SetActive(false)
this.AddTrigger()
isEnter = 0 isEnter = 0
end coroutine.yield()
end,0.23):Start() end)
end end
--绑定事件(用于子类重写) --绑定事件(用于子类重写)
@ -161,6 +171,7 @@ function RecruitMainPanel:BindEvent()
end) end)
Util.AddClick(this.leftBtn, function() Util.AddClick(this.leftBtn, function()
this.mask:SetActive(true) this.mask:SetActive(true)
this.RemoveTrigger()
self.thread = coroutine.start(function() self.thread = coroutine.start(function()
coroutine.wait(0.01) coroutine.wait(0.01)
this.MoveTo(3) this.MoveTo(3)
@ -169,10 +180,12 @@ function RecruitMainPanel:BindEvent()
coroutine.wait(0.01) coroutine.wait(0.01)
this:LeftAction() this:LeftAction()
this.mask:SetActive(false) this.mask:SetActive(false)
this.AddTrigger()
end) end)
end) end)
Util.AddClick(this.rightBtn, function() Util.AddClick(this.rightBtn, function()
this.mask:SetActive(true) this.mask:SetActive(true)
this.RemoveTrigger()
self.thread = coroutine.start(function() self.thread = coroutine.start(function()
coroutine.wait(0.01) coroutine.wait(0.01)
this.MoveTo(2) this.MoveTo(2)
@ -181,11 +194,13 @@ function RecruitMainPanel:BindEvent()
coroutine.wait(0.01) coroutine.wait(0.01)
this:RightAction() this:RightAction()
this.mask:SetActive(false) this.mask:SetActive(false)
this.AddTrigger()
end) end)
end) end)
Util.AddClick(this.jiantouyou , function() Util.AddClick(this.jiantouyou , function()
this.mask:SetActive(true) this.mask:SetActive(true)
this.RemoveTrigger()
for i = self.curPage - 1,1,-1 do for i = self.curPage - 1,1,-1 do
if self.dicData[i].RpType and self.dicData[i].RpType > 0 then if self.dicData[i].RpType and self.dicData[i].RpType > 0 then
if RecruitManager.GetAllRecruitBtnRedpoint(self.dicData[i].RpType) then if RecruitManager.GetAllRecruitBtnRedpoint(self.dicData[i].RpType) then
@ -199,10 +214,10 @@ function RecruitMainPanel:BindEvent()
self.lastPage = self.curPage - 1 > 0 and self.curPage - 1 or #self.dicData 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 self.nextPage = self.curPage + 1 > #self.dicData and 1 or self.curPage + 1
this:SetIndex() this:SetIndex()
this:PageOnChange(true)
end) end)
Util.AddClick(this.jiantouzuo , function() Util.AddClick(this.jiantouzuo , function()
this.mask:SetActive(true) this.mask:SetActive(true)
this.RemoveTrigger()
for i = self.curPage + 1,#self.dicData,1 do for i = self.curPage + 1,#self.dicData,1 do
if self.dicData[i].RpType and self.dicData[i].RpType > 0 then if self.dicData[i].RpType and self.dicData[i].RpType > 0 then
if RecruitManager.GetAllRecruitBtnRedpoint(self.dicData[i].RpType) then if RecruitManager.GetAllRecruitBtnRedpoint(self.dicData[i].RpType) then
@ -216,7 +231,6 @@ function RecruitMainPanel:BindEvent()
self.lastPage = self.curPage - 1 > 0 and self.curPage - 1 or #self.dicData 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 self.nextPage = self.curPage + 1 > #self.dicData and 1 or self.curPage + 1
this:SetIndex() this:SetIndex()
this:PageOnChange(true)
end) end)
end end
@ -293,6 +307,7 @@ function RecruitMainPanel:OnShow()
self.lastPage = self.curPage - 1 > 0 and self.curPage - 1 or #self.dicData 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 self.nextPage = self.curPage + 1 > #self.dicData and 1 or self.curPage + 1
lastIndex = self.curPage lastIndex = self.curPage
this.RemoveTrigger()
this:SetIndex(self.curPage) this:SetIndex(self.curPage)
this:PageOnChange(false) this:PageOnChange(false)
end end
@ -351,6 +366,7 @@ function this:SetIndex()
for i = 1,#this.itemList do for i = 1,#this.itemList do
if this.itemList[i].pageIndex == self.curPage then if this.itemList[i].pageIndex == self.curPage then
if this.itemList[i].index == 2 then if this.itemList[i].index == 2 then
this.AddTrigger()
return return
else else
local LOY = 0 local LOY = 0
@ -362,7 +378,6 @@ function this:SetIndex()
local offSet = math.abs(this.itemList[i].index - 2) local offSet = math.abs(this.itemList[i].index - 2)
local localIsenter = true local localIsenter = true
self.thread = coroutine.start(function() self.thread = coroutine.start(function()
this.RemoveTrigger()
while(offSet > 0) do while(offSet > 0) do
if localIsenter then if localIsenter then
localIsenter = false localIsenter = false
@ -453,6 +468,10 @@ function RecruitMainPanel:OnClose()
coroutine.stop(self.thread) coroutine.stop(self.thread)
self.thread = nil self.thread = nil
end end
if this.thread1 then
coroutine.stop(this.thread1)
self.thread = nil
end
for k,v in pairs(redPointTypeList) do for k,v in pairs(redPointTypeList) do
ClearRedPointObject(k,v) ClearRedPointObject(k,v)
end end