autoImport("WrapCellHelper") autoImport("YoyoRoomCombineCell"); autoImport("YoyoRoomToggleCell"); YoyoViewPage = class("YoyoViewPage",SubView) local yoyoView_Path = ResourcePathHelper.UIView("YoyoViewPage"); local Y_PVP_TYPE = nil; local RaidMap = GameConfig.PVPConfig[1].RaidMap local MaxPlayerNum = GameConfig.PVPConfig[1].PeopleLimit YoyoViewPage.timeTick = nil local intervalTime = GameConfig.PVPConfig[1] and GameConfig.PVPConfig[1].Refresh or 3 local resID = ResourcePathHelper.UICell("YoyoRoomToggleCell") function YoyoViewPage:Init() Y_PVP_TYPE = PvpProxy.Type.Yoyo; self:FindObjs() self:AddUIEvts() self:AddViewEvts() end function YoyoViewPage:UpdateView() self:ClearLeanTick() self.roomlist={} self:CallReqRoomList() -- self.roomlist = PvpProxy.Instance:GetRoomList(Y_PVP_TYPE) -- if(nil==self.roomlist or #self.roomlist<=0)then -- self:CallReqRoomList() -- else -- local firstMapID = RaidMap[1][1] -- self:ShowUIByPage(firstMapID); -- end end function YoyoViewPage:ReUniteCellData(datas, perRowNum) local newData = {}; if(datas~=nil and #datas>0)then for i = 1,#datas do local i1 = math.floor((i-1)/perRowNum)+1; local i2 = math.floor((i-1)%perRowNum)+1; newData[i1] = newData[i1] or {}; if(datas[i] == nil)then newData[i1][i2] = nil; else newData[i1][i2] = datas[i]; end end end return newData; end function YoyoViewPage:FindObjs() self:LoadSubView() self.itemRoot = self:FindGO("cutWrap", self.objRoot) self.quickJoin = self:FindGO("quickJoin", self.objRoot); self.HelpButton=self:FindGO("RuleBtn", self.objRoot) self.scrollView = self:FindComponent("RoomRoot", ROUIScrollView, self.objRoot); self.refreshTipLab=self:FindComponent("refreshTipLab", UILabel, self.objRoot); self.backToTopBtn=self:FindGO("backToTop", self.objRoot) self.RoomBtnRoot=self:FindGO("RoomBtnRoot", self.objRoot) local ListTable = self.RoomBtnRoot:GetComponent(UIGrid) self.gridListCtl = UIGridListCtrl.new(ListTable,YoyoRoomToggleCell,"YoyoRoomToggleCell") self.gridListCtl:AddEventListener(MouseEvent.MouseClick, self._freshClickChoose, self); local list = {} for i=1,#RaidMap do table.insert(list,RaidMap[i][1]) end self.gridListCtl:ResetDatas(list) self.chooseMapId=RaidMap[1][1] self:_refreshChoose() end function YoyoViewPage:_freshClickChoose(cellctl) if(nil~=cellctl) then if(cellctl.data ~=self.chooseMapId) then self.chooseMapId = cellctl.data; self:ShowUIByPage(self.chooseMapId); self:_refreshChoose() end end if(self.itemWrapHelper)then self.itemWrapHelper:ResetPosition() end end function YoyoViewPage:LoadSubView() self.objRoot = self:FindGO("YoyoView") local obj = self:LoadPreferb_ByFullPath(yoyoView_Path, self.objRoot, true); obj.name = "YoyoViewPage"; end function YoyoViewPage:AddUIEvts() self:AddClickEvent(self.quickJoin, function (go) self:CallQuickjoin(); end); self:AddClickEvent(self.HelpButton,function (go) self:ClickRuleButton(); end) self.scrollView.OnPulling = function (offsetY, triggerY) self.refreshTipLab.text = offsetYright.playerNum end end function YoyoViewPage:ShowSingleRoom(singleRoomData) local newData = self:ReUniteCellData(singleRoomData, 1); if(self.itemWrapHelper == nil)then local wrapConfig = { wrapObj = self.itemRoot, pfbNum = 5, cellName = "YoyoRoomCombineCell", control = YoyoRoomCombineCell, dir = 1, } self.itemWrapHelper = WrapCellHelper.new(wrapConfig) self.itemWrapHelper:AddEventListener(YoyoJoinRoomEvent.JoinRoom,self.handleJoinRoom,self) end self.itemWrapHelper:UpdateInfo(newData) end function YoyoViewPage:_handleRefreshRoom() self:_removeLeanTween() self.scrollView:Revert() end function YoyoViewPage:_removeLeanTween() if(self.refreshLean)then self.refreshLean:cancel() self.refreshLean=nil end end function YoyoViewPage:_timeCountDown() local deltaTime, lastTime = 0; self.timeTick=TimeTickManager.Me():CreateTick(0, 33, function (self) if(lastTime)then deltaTime = deltaTime + (RealTime.time - lastTime); if(deltaTime>intervalTime)then self:_stopTick() end end lastTime = RealTime.time; end, self, 1); end function YoyoViewPage:_stopTick() TimeTickManager.Me():ClearTick(self,1) self.timeTick=nil; end function YoyoViewPage:GetClassifiedRoomData() local yoyoData = PvpProxy.Instance:GetRoomList(PvpProxy.Type.Yoyo) if(nil==yoyoData)then return nil end local mapTab = {} if(nil==RaidMap)then helplog("配置有誤,請檢查配置——> GameConfig.PVPConfig RaidMap ") return end for i=1,#RaidMap do mapTab[i]=RaidMap[i][1] end local classifiedRoomData = {} -- 分類的房間數據 for i=1,#mapTab do local configID = mapTab[i] local temp = {} for _,v in pairs(yoyoData) do if(v.raidid==configID)then table.insert(temp,v); end end classifiedRoomData[configID]=temp end return classifiedRoomData end function YoyoViewPage:_refreshChoose() if(self.gridListCtl)then local childCells = self.gridListCtl:GetCells(); for i=1,#childCells do local childCell = childCells[i]; childCell:ShowChooseImg(self.chooseMapId) end end end