local UIPKRoomList = UIViewClass() local NUM_COUNT_FORMAT = "%s/%s" local REQUEST_INTERVAL = DataSheetManager.ConstData:GetDataByID("PK_Hall_RefreshTime").IntValue -- 60s local QUERY_LIMIT_REFRESH_INTERVAL = DataSheetManager.ConstData:GetDataByID("PK_Hall_ManualRefreshCD").IntValue -- 上次请求的时间戳 local lastQueryTimestamp = 0 local SOLO_TYPE = LuaConst.ActivityType.SyncSoloPK function UIPKRoomList:OnOpened(context) self:RegistSystemEvent(EventID.UI_UpdateCustomRoomQuery, self.RefreshPanelInfo) self:RegistSystemEvent(EventID.FunctionUnlockUpdate, self.RefreshByGMS) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS["IDS_PK_Entry_Name"]) UIUtils.SetLabelText(self.txt_Create, Const_IDS["IDS_PK_CreateRoom"]) self.filterObj = self.loop_LevelSelect -- 隐藏搜索按钮 UIUtils.SetActive(self.btn_CloseInput, false) -- 默认选中1v1页签 if context.needQuery then self:RefreshLeftTabs() self.activityID = context.activityID local index = self:GetTabIndexByActivityID(self.LeftTabs) -- 清空选中活动方便select self.activityID = -1 self.Loop_LeftTab:SelectIndex(index and index or 0) else self.activityID = context.activityID end self:StartRepeatFunc(self.UpdateBtnFreeze, 1, -1) -- 默认筛选等级设置 self.filterRankLevel = 0 self:SetFilterLoopShow(false) end function UIPKRoomList:RefreshLeftTabs() self.LeftTabs = CTL.CustomRoom.GetPKRoomListLeftTab() self.Loop_LeftTab:ReloadAll(self.LeftTabs) end function UIPKRoomList:RefreshByGMS(funcID, isUnlock) if funcID == MDL.Unlock.FunctionType.SyncSoloPK or funcID == MDL.Unlock.FunctionType.SyncTVTPK then self:RefreshLeftTabs() local index = self:GetTabIndexByActivityID(self.LeftTabs) -- GMS 刷新重置活动ID缓存,方便刷新 self.activityID = -1 self.Loop_LeftTab:SelectIndex(index and index or 0) end end function UIPKRoomList:GetTabIndexByActivityID(tabs) local index for i, v in ipairs(tabs) do if v.activityID == self.activityID then index = i - 1 end end return index end function UIPKRoomList:RefreshFilterInfo() UIUtils.SetActive(self.event_Level, true) self.loop_LevelSelect:ReloadAll(CTL.CustomRoom.GetPKLimitRankLevelList(self.activityID, true)) end function UIPKRoomList:OnValueChanged(comp, index) if comp == self.obj_InputField then if string.isNilOrEmpty(self.obj_InputField.text) and self.btn_CloseInput.gameObject.activeSelf == true then UIUtils.SetActive(self.btn_CloseInput, false) elseif not string.isNilOrEmpty(self.obj_InputField.text) and self.btn_CloseInput.gameObject.activeSelf == false then UIUtils.SetActive(self.btn_CloseInput, true) end end end function UIPKRoomList:RefreshPanelInfo(curPage, totalPage, roomList) self.curPage, self.totalPage = curPage, totalPage UIUtils.SetActive(self.txt_Empty, false) if self.totalPage == 0 then UIUtils.SetActive(self.group_Room.gameObject, false) UIUtils.SetActive(self.section_Page.gameObject, false) UIUtils.SetActive(self.txt_Empty, true) else UIUtils.SetActive(self.section_Page.gameObject, true) UIUtils.SetActive(self.group_Room.gameObject, true) UIUtils.SetActive(self.btn_PageLeft, curPage > 1) UIUtils.SetActive(self.btn_PageRight, curPage < totalPage) UIUtils.SetLabel(self.txt_Page, string.format(NUM_COUNT_FORMAT, curPage, totalPage)) UIUtils.SetActive(self.txt_Empty, false) if self.group_Room.Count > 0 then self.group_Room:ClearCells() end self.group_Room:ReloadAll(roomList) end if not self.updateRequestTimer then self.updateRequestTimer = self:StartRepeatFunc(self.UpdateQuery, REQUEST_INTERVAL, -1) end end -- Update事件 function UIPKRoomList:UpdateBtnFreeze(deltaTime, timeSinceUpdate) self.btn_Refresh:SetGray(UTL.Time.GetServerTimestamp() - lastQueryTimestamp <= QUERY_LIMIT_REFRESH_INTERVAL, true) end function UIPKRoomList:UpdateQuery(deltaTime, timeSinceUpdate) self:SendQueryRequest() end function UIPKRoomList:SendQueryRequest(param) -- 自动请求上次成功的参数查询 MDL.CustomRoom.QueryCustomRoomReq(param) end function UIPKRoomList:SetFilterLoopShow(isShow) if isShow and self.loop_LevelSelect.gameObject.activeInHierarchy == false then self:RefreshFilterInfo() UIUtils.SetActive(self.img_Arrow01.gameObject, false) UIUtils.SetActive(self.img_Arrow02.gameObject, true) UIUtils.SetActive(self.loop_LevelSelect, true) else UIUtils.SetActive(self.img_Arrow01.gameObject, true) UIUtils.SetActive(self.img_Arrow02.gameObject, false) UIUtils.SetActive(self.loop_LevelSelect, false) UIUtils.SetLabel(self.labLocal_Level, self:GetRankDes(self.filterRankLevel, true)) end end function UIPKRoomList:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIPKRoomList:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_Info then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, {id = LuaConst.NoteID.PKHall}) elseif comp == self.UITemplateTitlePanel.btn_close then self:CloseView() elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.btn_PageLeft then -- Query上一页 MDL.CustomRoom.QueryPreviousPage() elseif comp == self.btn_PageRight then -- Query下一页 MDL.CustomRoom.QueryNextPage() elseif comp == self.btn_Refresh then if UTL.Time.GetServerTimestamp() - lastQueryTimestamp <= QUERY_LIMIT_REFRESH_INTERVAL then CTL.Tips.AddTipsMsg(Const_IDS["IDS_PK_ManualRefreshCDTips"]) return end lastQueryTimestamp = UTL.Time.GetServerTimestamp() self:SendQueryRequest() elseif comp == self.btn_CreateTeam then -- 创建房间 self:ClickCreateBtn() elseif comp == self.event_Level then self:SetFilterLoopShow(true) elseif comp == self.event_Close then self:SetFilterLoopShow(false) elseif comp == self.btn_Search then -- 搜索房间 self:Search() elseif comp == self.btn_CloseInput then self.obj_InputField.text = nil UIUtils.SetActive(self.event_Level, true) self:SendQueryRequest(MDL.CustomRoom.CreateParam(self.activityID, self.filterRankLevel, nil, 1)) end end function UIPKRoomList:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_LevelSelect then self.filterRankLevel = data.level UIUtils.SetLabel(self.labLocal_Level, data.desc) self:SendQueryRequest(MDL.CustomRoom.CreateParam(self.activityID, data.level, nil, 1)) self:OnButtonClicked(self.event_Close) elseif scrollRect == self.group_Room then if target == cellTable.event_AddIn then -- 进入房间 CTL.CustomRoom.OnClickEnterRoom(false, data.BriefInfo.ActivityID, data.BriefInfo.RoomID, nil, MDL.CustomRoom.MemberEnterType_Fighter) elseif target == cellTable.event_Watch then CTL.CustomRoom.OnClickEnterRoom(false, data.BriefInfo.ActivityID, data.BriefInfo.RoomID, nil, MDL.CustomRoom.MemberEnterType_Watcher) end elseif scrollRect == self.Loop_LeftTab then -- 页签玩法未解锁 local isUnlock, des = CTL.CustomRoom.GetTabUnlockByActivityID(data.activityID) if not isUnlock then CTL.Tips.AddTipsMsg(des) return end if self.activityID == data.activityID then return end if self.activityID ~= data.activityID then self.activityID = data.activityID self.filterRankLevel = 0 -- 设置默认刷新参数所属页签 MDL.CustomRoom.SetCurRoomActivity(self.activityID) lastQueryTimestamp = 0 self:SetFilterLoopShow(true) self:RefreshFilterInfo() self:SetFilterLoopShow(false) self.Loop_LeftTab:RefreshCells() end self.roomPlayerCountLimit = data.playerCount -- 切换页签重新请求 self:SendQueryRequest(MDL.CustomRoom.CreateParam(data.activityID, nil, nil, 1)) -- 自己的段位 local ids = self.activityID == SOLO_TYPE and "IDS_PK_Hall_MyLevel_1v1" or "IDS_PK_Hall_MyLevel_3V3" UIUtils.SetLabel(self.txt_MyLevel_1V1, string.FormatByIdsId(Const_IDS[ids], self:GetRankDes())) end end function UIPKRoomList:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.group_Room then local ownerInfo = data.HouseOwner local roomInfo = data.BriefInfo -- 房主的头像 CTL.Character.SetPortraitAndFrame(cellTable.group_Head.UIHeroHead, ownerInfo.PortraitID, ownerInfo.FrameID) -- 房主等级 UIUtils.SetLabel(cellTable.txt_Level, self:GetRankDes(ownerInfo.Dan)) cellTable.group_Gender:SetState(ownerInfo.Sex == 1 and 0 or 1) UIUtils.SetLabel(cellTable.txt_Name, CTL.CrossServer.GetServerShowStr(ownerInfo.ShowServerID)) UIUtils.SetLabel(cellTable.lab_RoleName, ownerInfo.Name) -- 房间名称 UIUtils.SetLabel(cellTable.txt_RoomName, roomInfo.RoomName) -- 是否需要密码 UIUtils.SetActive(cellTable.txt_Code, roomInfo.RequirePassword) UIUtils.SetLabelText(cellTable.txt_Code, Const_IDS["IDS_PK_Hall_PasswordLimit"]) -- 准入标准 local accessDanDesc = roomInfo.AccessDan == 0 and string.FormatByIdsId(Const_IDS["IDS_PK_RoomInfo_1"], UIUtils.GetLocalizedTxt(Const_IDS["IDS_PK_Hall_EnterLimit_Null"])) or string.FormatByIdsId(Const_IDS["IDS_PK_RoomInfo_1"], self:GetRankDes(roomInfo.AccessDan)) UIUtils.SetLabel(cellTable.txt_LevelLimit, accessDanDesc) -- 房间满人图标 local isRoomFull = roomInfo.CurrentNum >= self.roomPlayerCountLimit -- 房间状态(战斗中) local inWaiting = roomInfo.CurState == MDL.CustomRoom.RoomState.Waiting UIUtils.SetActive(cellTable.img_Full, isRoomFull or not inWaiting) local btnDesIDS = inWaiting and Const_IDS["IDS_PK_Hall_RoomFull"] or Const_IDS["IDS_PK_Hall_RoomInBattle"] UIUtils.SetLabel(cellTable.labLocal_Full, string.FormatByIdsId(btnDesIDS, self.roomPlayerCountLimit, self.roomPlayerCountLimit)) UIUtils.SetLabel(cellTable.labLocal_AddIn, string.FormatByIdsId(Const_IDS["IDS_PK_Hall_EnterButton"], roomInfo.CurrentNum, self.roomPlayerCountLimit)) -- 房间可加入并且在等待中(加入按钮) UIUtils.SetActive(cellTable.event_AddIn, not isRoomFull and inWaiting) -- 观战按钮 if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.PKRoomWatch) == false or roomInfo.CanBeWatch == false then cellTable.event_Watch:SetGray(true, false) else cellTable.event_Watch:SetGray(false) end elseif scrollRect == self.loop_LevelSelect then UIUtils.SetLabel(cellTable.txt_Uncheck, data.desc) UIUtils.SetActive(cellTable.img_Selected, self.filterRankLevel == data.level) elseif scrollRect == self.Loop_LeftTab then UIUtils.SetLabel(cellTable.txt, data.desc) UIUtils.SetActive(cellTable.img_Lock.gameObject, not MDL.Unlock.IsUnlock(data.funcID)) UIUtils.SetActive(cellTable.effect_Toggle.gameObject, self.activityID == data.activityID) UIUtils.SetActive(cellTable.mark.gameObject, self.activityID == data.activityID) cellTable.state_Color:SetState(self.activityID == data.activityID and 1 or 0) end end function UIPKRoomList:Search() if string.isNilOrEmpty(self.obj_InputField.text) then CTL.Tips.AddTipsMsg(Const_IDS["IDS_PK_Hall_SearchTips_2"]); return false end -- 更新一下缓存 self:SendQueryRequest(MDL.CustomRoom.CreateParam(self.activityID, nil, tonumber(self.obj_InputField.text), false)) self:StartRepeatFunc(self.DelayExecuteCheckResult, 0.5, 1) end function UIPKRoomList:DelayExecuteCheckResult() if not MDL.CustomRoom.IsRoomExit(self.obj_InputField.text) then CTL.Tips.AddTipsMsg(Const_IDS["IDS_PK_Hall_SearchTips_3"]); self.obj_InputField.text = nil return end UIUtils.SetActive(self.event_Level, false) end function UIPKRoomList:GetRankDes(rankLv, isFilter) return CTL.CustomRoom.GetLevelDescByActivityID(self.activityID, rankLv, isFilter) end function UIPKRoomList:ClickCreateBtn() if CTL.Team.IsInTeam() then CTL.Tips.AddTipsMsg(Const_IDS["IDS_PK_InRanksToCreateRoom"]) return end if CTL.GuildEscort.IsTransport() then -- 势力押运中 CTL.Tips.AddTipsMsg(Const_IDS["IDS_Escort_Escorting"]) return end UIManager.OpenView(Const_UI_Lua.UIEnum.UIPKCreatePanel, {activityID = self.activityID}) end function UIPKRoomList:OnClosed() self.context.needQuery = true self.context.activityID = self.activityID end return UIPKRoomList