diff --git a/Assets/ManagedResources/~Lua/Modules/Recruit/RecruitMainPanel.lua b/Assets/ManagedResources/~Lua/Modules/Recruit/RecruitMainPanel.lua index c95515788b..bced08487a 100644 --- a/Assets/ManagedResources/~Lua/Modules/Recruit/RecruitMainPanel.lua +++ b/Assets/ManagedResources/~Lua/Modules/Recruit/RecruitMainPanel.lua @@ -35,81 +35,116 @@ function RecruitMainPanel:InitComponent() if not this.itemList[i] then this.itemList[i] = {} this.itemList[i].go = newObjToParent(this.item,this.grid) - local tran = this.itemList[i].go:GetComponent("RectTransform") - local vec = tran.anchoredPosition + 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 = off * (i - 1) + i * this.itemWidth vec.y = 0 - tran.anchoredPosition = vec - this.itemList[i].pos = tran.anchoredPosition - this.itemList[i].off = 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(off * (0 - 1) + 0 * this.itemWidth,0,0) + this.pos4 = Vector3.New(off * (4 - 1) + 4 * this.itemWidth,0,0) self.lastPage,self.curPage,self.nextPage = 0,0,0 - this.trigger = Util.GetEventTriggerListener(self.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 - this.moveTween = this.grid:GetComponent(typeof(UITweenSpring)) - if not this.moveTween then - this.moveTween = this.grid:AddComponent(typeof(UITweenSpring)) - end - this.moveTween.enabled = false - this.moveTween.OnUpdate = this.SetPos - this.moveTween.OnMoveEnd = this.MoveTo - this.moveTween.MomentumAmount = 0.5 - this.moveTween.Strength = 1 + -- this.moveTween = this.grid:GetComponent(typeof(UITweenSpring)) + -- if not this.moveTween then + -- this.moveTween = this.grid:AddComponent(typeof(UITweenSpring)) + -- end + -- this.moveTween.enabled = false + -- this.moveTween.OnUpdate = this.SetPos + -- this.moveTween.OnMoveEnd = this.MoveTo + -- this.moveTween.MomentumAmount = 0.5 + -- this.moveTween.Strength = 1 +end + +function this.SortItemList() + table.sort(this.itemList,function(a,b) + return a.index < b.index + end) end ---设置位置 -function this.SetPos(v2) +function this.SetPos(v2) if isEnter == 1 then if v2.x > 2 then - isEnter = 0 - this:RightAction() + isEnter = 0 --右 + this.MoveTo(2,function() + isEnter = 2 + end) elseif v2.x < -2 then - isEnter = 0 - this:LeftAction() + isEnter = 0 --左 + this.MoveTo(3,function() + isEnter = 3 + end) end end end ---手指拖动结束 ui归位 -function this.MoveTo() - -- local d = 1 - -- local targetIdx - -- for i=1, this.count do - -- local item = this.ItemList[i] - - -- local dd = math.abs(this.ItemList[i].off) - -- if dd < d then - -- targetIdx = i - -- d = dd - -- end - -- end - -- curIndex=targetIdx - -- this.MoveTween(-this.ItemList[targetIdx].off) - -- this.SetInfo(targetIdx) +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 end function this.OnBeginDrag(Pointgo, data) - isEnter = 1 - this.moveTween.enabled = true - this.moveTween.Momentum = Vector3.zero - this.moveTween.IsUseCallBack = false + if isEnter == 0 then + isEnter = 1 + end end function this.OnDrag(Pointgo, data) - this.moveTween:LerpMomentum(data.delta) this.SetPos(data.delta) end function this.OnEndDrag(Pointgo, data) - --this.SetPos(data.delta) - isEnter = 0 - this.moveTween.IsUseCallBack = true + 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.3):Start() end --绑定事件(用于子类重写) @@ -119,10 +154,22 @@ function RecruitMainPanel:BindEvent() this:ClosePanel() end) Util.AddClick(this.leftBtn, function() - this:LeftAction() + this.mask:SetActive(true) + this.MoveTo(3) + Timer.New(function() + this.SortItemList() + this:LeftAction() + this.mask:SetActive(false) + end,0.3):Start() end) Util.AddClick(this.rightBtn, function() - this:RightAction() + this.mask:SetActive(true) + this.MoveTo(2) + Timer.New(function() + this.SortItemList() + this:RightAction() + this.mask:SetActive(false) + end,0.3):Start() end) end @@ -164,15 +211,14 @@ end function this:RefreshTabData() local curIndex = 0 - for i = 1,#this.itemList do + for i = 1,#this.itemList do if i == 1 then - curIndex = self.lastPage + 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]) this.itemList[i].redpot.gameObject:SetActive(false) end @@ -204,8 +250,7 @@ function this:PageOnChange() end function this:LeftAction() - lastIndex = self.curPage - this.select.gameObject:SetActive(false) + lastIndex = self.curPage self.CurRecruitId = self.dicData[self.nextPage].ShopData[1][1] self.lastPage = self.curPage self.curPage = self.nextPage @@ -214,7 +259,6 @@ function this:LeftAction() end function this:RightAction() lastIndex = self.curPage - this.select.gameObject:SetActive(false) self.CurRecruitId = self.dicData[self.lastPage].ShopData[1][1] self.nextPage = self.curPage self.curPage = self.lastPage diff --git a/Assets/ManagedResources/~Lua/Modules/Recruit/RecruitPanelNew.lua b/Assets/ManagedResources/~Lua/Modules/Recruit/RecruitPanelNew.lua index ef2afb0823..c569a87c1b 100644 --- a/Assets/ManagedResources/~Lua/Modules/Recruit/RecruitPanelNew.lua +++ b/Assets/ManagedResources/~Lua/Modules/Recruit/RecruitPanelNew.lua @@ -187,7 +187,6 @@ function RecruitPanelNew:UpdataWishPanel() self.wishNoOpen.gameObject:SetActive(false) self.wishOpen.gameObject:SetActive(true) NetManager.ChoiceWishHeroRequest(nil,function () - LogGreen("#self.upHeroPreList:"..#self.upHeroPreList) for i = 1,3 do local data = RecruitManager.WishCardData[i] local id = data.heroTid