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.select = Util.GetGameObject(this.tabbox, "select") 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.count = 3 this.off = (this.moveWidth - this.count * this.itemWidth)/(this.count - 1) -- 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 - 1) + 0 * 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 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 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 = 0 --右 this.MoveTo(2,function() isEnter = 2 end) elseif v2.x < -2 then isEnter = 0 --左 this.MoveTo(3,function() isEnter = 3 end) 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 end function this.OnBeginDrag(Pointgo, data) if isEnter == 0 then isEnter = 1 end 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.3):Start() end --绑定事件(用于子类重写) function RecruitMainPanel:BindEvent() -- 关闭界面打开主城 Util.AddClick(this.btnBack, function() this:ClosePanel() end) Util.AddClick(this.leftBtn, function() 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.mask:SetActive(true) this.MoveTo(2) Timer.New(function() this.SortItemList() this:RightAction() this.mask:SetActive(false) end,0.3):Start() end) Util.AddClick(this.jiantouyou , function() this.mask:SetActive(true) 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 self.curPage = i break end 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:SetIndex() this:PageOnChange() end) Util.AddClick(this.jiantouzuo , function() this.mask:SetActive(true) 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 self.curPage = i break end end end self.curPage = 0 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:SetIndex() this:PageOnChange() 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 --界面打开时调用(用于子类重写) function RecruitMainPanel:OnOpen(_index) if not _index then self.CurRecruitId = RecruitManager.CurRecruitId else self.CurRecruitId = _index RecruitManager.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:SetIndex(self.curPage) this:PageOnChange() 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].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") 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 this.pos4 = Vector3.New(this.off * (#this.itemList) + (#this.itemList + 1) * this.itemWidth,0,0) 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 end local offSet = math.abs(this.itemList[i].index - 2) local isenter = true self.thread = coroutine.start(function() while(offSet > 0) do if isenter then isenter = false this.mask:SetActive(true) this.MoveTo(LOY) Timer.New(function() offSet = offSet - 1 this.SortItemList() isenter = true end,0.21):Start() end coroutine.wait(0.01) end this.mask:SetActive(false) this.select.gameObject:SetActive(true) self:RefreshJianTou() end) end break end end end function this:PageOnChange() RecruitManager.CurRecruitId = self.CurRecruitId if subViewList[lastIndex] and subViewList[lastIndex].config and subViewList[lastIndex].sub then subViewList[lastIndex].sub:OnClose() 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.select.gameObject:SetActive(true) self:RefreshJianTou() this:PageOnChange() --this:RefreshTabData() 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.select.gameObject:SetActive(true) self:RefreshJianTou() this:PageOnChange() --this:RefreshTabData() 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(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 self.dicData = {} end return this