local UILoginSelectServer = UIViewClass() local EventSystem = require('Event/EventSystem') local LocalizationRegionCfg = require "Localization/LocalizationRegionCfg" local IconPath = ConstAssetPathConfig.IconPath local GroupCount = 10--一组服务器数量 local RefreshInterval = 30 -- 刷新间隔 local Default_Tab_Path_Selected = ConstAssetPathConfig.Default_Tab_Path_Selected local Default_Tab_Path_UnSelected = ConstAssetPathConfig.Default_Tab_Path_UnSelected local Default_Cell_Path = ConstAssetPathConfig.Default_Cell_Path local Default_Tab_Width = 350 local Default_Tab_Height = 96 function UILoginSelectServer:OnOpened(content) self.tabInfoList = {} self.group = {} UIUtils.SetLabelText(self.UICommonPopUpTab.txt_Title,Const_IDS.IDS_LOGIN_BUTTON_CHOOSESERVER) self:RegistSystemEvent(EventID.UI_Login_GetCurShardInfo,self.RefreshServerList) self:RequestServerList() self:Init() self.curSelectTabIndex = 0 self:RefreshServerList() self:InitRegion() self:StartRepeatFunc(self.RequestServerList, RefreshInterval) end function UILoginSelectServer:Init() local list = self:GetHaveRoleShardList() self.baseTabCount = 0 if #list>0 then self.havaRole = true table.insert(self.tabInfoList, Const_IDS.IDS_MyPlayer) self.baseTabCount = self.baseTabCount + 1 end if not CTL.Login.IsFierceServerOpen() then table.insert(self.tabInfoList, Const_IDS.IDS_LoginSystem_RecommendServer) self.baseTabCount = self.baseTabCount + 1 end UIUtils.SetLabelText(self.txt_AreaSelect, Const_IDS.IDS_VirtualGidC_Name2) end function UILoginSelectServer:GetHaveRoleShardList() return MDL.Login.GetHaveRoleShardList() end function UILoginSelectServer:GetServerList() return MDL.Login.GetServerList() end function UILoginSelectServer:RefreshServerList() for i = #self.tabInfoList, self.baseTabCount + 1, -1 do self.tabInfoList[i] = nil end self:RefreshGroupData() local isSpServerOpen = self:GetIfSpServerOpen() for i, v in ipairs(self.group) do local startIndex = tonumber(MDL.Login.GetFirstName(v[#v])) local endIndex if isSpServerOpen then endIndex = tonumber(MDL.Login.GetFirstName(v[1])) else endIndex = startIndex + GroupCount - 1 end local str = string.FormatByIdsId(Const_IDS.IDS_ServerGroup, startIndex, endIndex) table.insert(self.tabInfoList, str) end self.UICommonPopUpTab.loop_Tab:ReloadAll(self.tabInfoList) if self.curSelectTabIndex > self.UICommonPopUpTab.loop_Tab.Count - 1 then self.UICommonPopUpTab.loop_Tab:SelectIndex(0) else self.UICommonPopUpTab.loop_Tab:SelectIndex(self.curSelectTabIndex) end end function UILoginSelectServer:RefreshGroupData() local serverList = self:GetServerList() table.clear(self.group) --需求调整:原来是按顺序每10个在一组,现在新增一个标识,把同一个标识的放在同一组,可能会打断连续10个的排序 --比如配置第8个服特殊,则1-7在一组,8单独在一组,9-19在一组 local curSpId local targetCount for i = 1, #serverList do local server = serverList[i] local spId = server.group_id and tonumber(server.group_id) or 0 if spId ~= curSpId then table.insert(self.group, 1, {}) if spId > 0 then targetCount = 9999 --专属服务器组无数量限制 else targetCount = self:GetGroupTargetCount(i) end else if #self.group[1] >= targetCount then table.insert(self.group, 1, {}) targetCount = self:GetGroupTargetCount(i) end end table.insert(self.group[1], 1, server) curSpId = spId end end function UILoginSelectServer:GetGroupTargetCount(index) local targetCount = 0 if self:GetIfSpServerOpen() == false then targetCount = GroupCount else local single = index % 10 if single > 5 then --个位数>5,targetCount为(个位数+10)下一个整0数 local target = (index + 20) - (index + 20) % 10 targetCount = target - index + 1 else --个位数<=5,targetCount为(个位数)下一个整0数 local target = (index + 10) - (index + 10) % 10 targetCount = target - index + 1 end end return targetCount end function UILoginSelectServer:RequestServerList() CTL.Login.RequestServerList() end function UILoginSelectServer:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUpTab.btn_Close) end function UILoginSelectServer:OnButtonClicked(obj) if obj == self.UICommonPopUpTab.btn_Close then self:CloseView() elseif obj == self.btn_Area then UIManager.OpenView(Const_UI_Lua.UIEnum.UISelectRegionView) elseif obj == self.btn_AreaSelect then UIManager.OpenView(Const_UI_Lua.UIEnum.UISelectRegionViewVirtualGidC) end end function UILoginSelectServer:ClickTabs(cellTable, index) if CTL.Login.IsFierceServerOpen() then self:RefreshNoRecmdListData(index + 1) else self:RefreshData(index + 1) end end function UILoginSelectServer:InitTabs(cellTable, data, index) if type(data) == "table" then cellTable.txt_Name_Selected.text = data.str cellTable.txt_Name_Nomal.text = data.str else UTL.String.SetLabelContent(cellTable.txt_Name_Selected,data) UTL.String.SetLabelContent(cellTable.txt_Name_Nomal,data) end UIUtils.SetActive(cellTable.group_SignStateS, false) UIUtils.SetActive(cellTable.group_SignState, false) UIUtils.SetActive(cellTable.img_Arrow, false) UIUtils.SetActive(cellTable.img_ArrowS, false) cellTable.txt_Name_Nomal_S.text = nil cellTable.txt_Name_Selected_S.text = nil local spCfg local group = self.group[index + 1 - self.baseTabCount] if group then local spId = tonumber(group[1].group_id) if spId > 0 then spCfg = DataSheetManager.SpecialServerTab:GetDataByTabID(spId) end end if spCfg then UIUtils.SetImageByAssetBundle(cellTable.Img_UnSelectedBg, spCfg.GroupTabPicture) UIUtils.SetImageByAssetBundle(cellTable.Img_SelectedBg, spCfg.GroupTabPicture2) cellTable.Img_UnSelectedBg:SetNativeSize() cellTable.Img_SelectedBg:SetNativeSize() cellTable.txt_Name_Selected.text = nil cellTable.txt_Name_Nomal.text = nil UIUtils.SetLabelText(cellTable.txt_Name_Nomal_S, Const_IDS[spCfg.TabName]) UIUtils.SetLabelText(cellTable.txt_Name_Selected_S, Const_IDS[spCfg.TabName]) else UIUtils.SetImageByAssetBundle(cellTable.Img_UnSelectedBg, Default_Tab_Path_UnSelected) UIUtils.SetImageByAssetBundle(cellTable.Img_SelectedBg, Default_Tab_Path_Selected) cellTable.Img_UnSelectedBg.transform:SetSizeDelta(Default_Tab_Width, Default_Tab_Height) cellTable.Img_SelectedBg.transform:SetSizeDelta(Default_Tab_Width, Default_Tab_Height) end end function UILoginSelectServer:RefreshData(index) local flag = 0 ----当没有角色时 不显示页签 这里用一个flag标记一下 保证获取下表正确 if self.havaRole then flag = 1 end if index == flag then local lastLoginShardInfo = MDL.Login.GetLastLoginServerInfo() if lastLoginShardInfo then self:ShowTopHint(true) UIUtils.SetLabel(self.txt_ServerName, MDL.Login.GetFirstAndServerNameByInfo(lastLoginShardInfo)) else self:ShowTopHint(false) end local list = self:GetHaveRoleShardList() self.group_Scroll:ClearCells() for i,v in ipairs(list) do self.group_Scroll:AddData(v, 1) end elseif index == flag + 1 then self:ShowTopHint(false) local list = MDL.Login.GetRencentList(self:GetServerList()) self.group_Scroll:ClearCells() for i,v in ipairs(list) do self.group_Scroll:AddData(v, 0) end else self:ShowTopHint(false) self.group_Scroll:ClearCells() for i,v in ipairs(self.group[index - flag - 1]) do self.group_Scroll:AddData(v, 0) end end end --没有推荐服务器 function UILoginSelectServer:RefreshNoRecmdListData(index) local flag = 0 ----当没有角色时 不显示页签 这里用一个flag标记一下 保证获取下表正确 if self.havaRole then flag = 1 end if index == flag then local lastLoginShardInfo = MDL.Login.GetLastLoginServerInfo() if lastLoginShardInfo then self:ShowTopHint(true) UIUtils.SetLabel(self.txt_ServerName, MDL.Login.GetFirstAndServerNameByInfo(lastLoginShardInfo)) else self:ShowTopHint(false) end local list = self:GetHaveRoleShardList() self.group_Scroll:ClearCells() for i,v in ipairs(list) do self.group_Scroll:AddData(v, 1) end else self:ShowTopHint(false) self.group_Scroll:ClearCells() for i,v in ipairs(self.group[index - flag]) do self.group_Scroll:AddData(v, 0) end end end --data "_shardId_shardName_showState_order_playerName_level" function UILoginSelectServer:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.UICommonPopUpTab.loop_Tab then self:InitTabs(cellTable, data, index) elseif scrollRect == self.group_Scroll and data then self:OnCellInfoInit(cellTable,data) end end --infoStr "_shardId_shardName_showState_order_playerName_level_roleid" function UILoginSelectServer:OnCellInfoInit(item,data) local spId = 0 if data.level then local strTable = string.split(data.level,',') local info = MDL.Login.GetServerInfoByID(data.shard) self:SetPortrait(item.UIHeroHeadTempate, data.head_icon) local level = strTable[1] local _levelStr = UTL.Item.GetNobilityByTeamLevel(tonumber(level)) -- 爵位转换 -- 设置区服状态 local serverState = tonumber(data.ss) if serverState == MDL.Login.ShardShowState.ShowState_Maintenance then UIUtils.SetActive(item.group_ServerState.gameObject, true) item.group_ServerState:SetState(1) else UIUtils.SetActive(item.group_ServerState.gameObject, false) end spId = tonumber(info["group_id"]) if spId > 0 then item.txt_Lv.text = nil item.txt_Lv_S.text = string.FormatByIdsId(Const_IDS.IDS_HeroLevelShow, _levelStr) item.txt_PlayerName.text = nil item.txt_servername.text = nil item.txt_PlayerName_S.text = data.name item.txt_servername_S.text = MDL.Login.GetFirstAndServerNameByInfo(info) else item.txt_Lv.text = string.FormatByIdsId(Const_IDS.IDS_HeroLevelShow, _levelStr) item.txt_Lv_S.text = nil item.txt_PlayerName.text = data.name item.txt_servername.text = MDL.Login.GetFirstAndServerNameByInfo(info) item.txt_PlayerName_S.text = nil item.txt_servername_S.text = nil end else local serverState = tonumber(data.ss) if serverState == MDL.Login.ShardShowState.ShowState_NewSer then item.group_ServerState:SetState(2) elseif serverState == MDL.Login.ShardShowState.ShowState_Hot then item.group_ServerState:SetState(0) elseif serverState == MDL.Login.ShardShowState.ShowState_Maintenance then item.group_ServerState:SetState(1) elseif serverState == MDL.Login.ShardShowState.ShowState_Crowd then item.group_ServerState:SetState(0) elseif serverState == MDL.Login.ShardShowState.ShowState_Fluent then item.group_ServerState:SetState(2) else item.group_ServerState:SetState(2) end spId = tonumber(data["group_id"]) if spId > 0 then if string.isNilOrEmpty(data.nameExtra) then item.txt_Num_S.text = string.FormatByIdsId(Const_IDS.IDS_Rank_ServerIDS, MDL.Login.GetFirstName(data)) else item.txt_Num_S.text = string.format("%s\n(%s)", data.nameExtra, string.FormatByIdsId(Const_IDS.IDS_Rank_ServerIDS, MDL.Login.GetFirstName(data))) end item.txt_Name_S.text = MDL.Login.GetServerNameByInfo(data) item.txt_Num.text = nil item.txt_Name.text = nil else item.txt_Num.text = string.FormatByIdsId(Const_IDS.IDS_Rank_ServerIDS,MDL.Login.GetFirstName(data)) item.txt_Name.text = MDL.Login.GetServerNameByInfo(data) item.txt_Num_S.text = nil item.txt_Name_S.text = nil end end local _, cfg = DataSheetManager.SpecialServerTab:TryGetDataByTabID(spId) if cfg then UIUtils.SetImageByAssetBundle(item.img_Bg, cfg.ServerPicture) UIUtils.SetActive(item.img_CellBg_S, true) else UIUtils.SetImageByAssetBundle(item.img_Bg, Default_Cell_Path) UIUtils.SetActive(item.img_CellBg_S, false) end end function UILoginSelectServer:OnCellSelect(scrollRect, index, cellTable, data) if scrollRect == self.UICommonPopUpTab.loop_Tab then self:ClickTabs(cellTable, index) self.curSelectTabIndex = index elseif scrollRect == self.group_Scroll and data then if data.level then data = MDL.Login.GetServerInfoByID(data.shard) end EventSystem.Dispatch(EventID.UI_Login_RefreshLoginServerInfo,data["name"], MDL.Login.GetFirstAndServerNameByInfo(data), data["ss"], data["v_gid"]) self:CloseView() end end -- 设置头像,此处因为没有加载ctl,所以需要单独设置不走通用接口 function UILoginSelectServer:SetPortrait(uiHead, portraitId) local headPortraitId = tonumber(portraitId) local portraitData if headPortraitId>0 then portraitData = DataSheetManager.HeadPortrait:GetDataByID(headPortraitId) end -- 头像数据没有找到 if not portraitData then -- 默认头像作为当前使用头像 for _, v in DataSheetManager.HeadPortrait:GetEnumerator() do if v.Default == 1 then portraitData = v end end end if portraitData then if portraitData.HeroID > 0 then UIUtils.SetUICircleImageScaleRadiusAndOffset(uiHead.img_PlayerHead, 0.7, 0.15) else UIUtils.SetUICircleImageScaleRadiusAndOffset(uiHead.img_PlayerHead, 0, 0.05) end uiHead.obj_HeadState:SetState(0) local iconAssetPath = string.format(IconPath, portraitData.HeadResource) if CTL.HotFix.CanAssetLoad(iconAssetPath) then UIUtils.SetImageByAssetBundle(uiHead.img_PlayerHead, string.format(IconPath, portraitData.HeadResource)) else UIUtils.SetImageByAssetBundle(uiHead.img_PlayerHead, ConstAssetPathConfig.AssetPath145) end end uiHead.img_PlayerAvatarBg.targetGraphic.raycastTarget = true end function UILoginSelectServer:InitRegion() if GameAppInfo.IsOpenRegion() then for i,v in LocalizationRegionCfg.GetRegionTypeDataSheetIterator() do if v.Number == GameAppInfo.Global_ProductId then UIUtils.SetLabelText(self.txt_Area , Const_IDS[v.RegionName]) break end end UIUtils.SetActive(self.btn_Area, true) else UIUtils.SetActive(self.btn_Area, false) end UIUtils.SetActive(self.btn_AreaSelect, CTL.Login.IsFierceServerOpen()) ---hp0014独有 关闭切换大区按钮 end function UILoginSelectServer:ShowTopHint(show) UIUtils.SetActive(self.group_LastLogin, show) local rectTransform if show then rectTransform = self.obj_noTopScroll:GetComponent(typeof(RectTransform)) else rectTransform = self.obj_allScroll:GetComponent(typeof(RectTransform)) end local rect = rectTransform.rect local localPosition = rectTransform.localPosition UIUtils.ChangeWidth(self.group_Scroll.gameObject, rect.width) UIUtils.ChangeHeight(self.group_Scroll.gameObject, rect.height) UIUtils.SetLocalPosition(self.group_Scroll.gameObject, localPosition.x, localPosition.y, localPosition.z) end --是否配置了专属服务器 function UILoginSelectServer:GetIfSpServerOpen() local list = self:GetServerList() for i, v in ipairs(list) do local spId = v.group_id and tonumber(v.group_id) or 0 if spId > 0 then return true end end return false end return UILoginSelectServer