local UISelectRegionView = UIViewClass() local LocalizationRegionCfg = require "Localization/LocalizationRegionCfg" function UISelectRegionView:OnOpened(context) UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_Region_RegionListTitle) self:RegistSystemEvent(EventID.OnPingRequestFinish,self.OnPingRequestFinish) self:RegistSystemEvent(EventID.OnNetworkPingCompleted, self.OnNetworkPingCompleted) for i,v in LocalizationRegionCfg.GetRegionTypeDataSheetIterator() do UIUtils.SetLabelText(self.group_SelectArea[i].txt_Time , Const_IDS[v.RegionTime]) self.group_SelectArea[i].txt_Ping.text = "33ms" self.group_SelectArea[i].gameObject:SetActive(true) UIUtils.SetActive(self.group_SelectArea[i].group_Now, v.Number == GameAppInfo.Global_ProductId) if v.Number == GameAppInfo.Global_ProductId then self:OnSelectRegion(self.group_SelectArea[i].btn) self.group_SelectArea[i].txt_Area.text = UTL.Color.GetColorfulText("e8d588", v.RegionName) else UIUtils.SetLabelText(self.group_SelectArea[i].txt_Area , Const_IDS[v.RegionName]) end end self:RequestPing() end function UISelectRegionView:RequestPing() self.pingList = {} for i,v in LocalizationRegionCfg.GetRegionTypeDataSheetIterator() do local pingHost = string.split(v.PingUrl, "http://")[2] self.pingList[pingHost] = i if GameAppInfo.IsVersionGreaterThan18000() then UIUtils.NetworkPing(pingHost, 3, true) else UIUtils.NetworkPing(pingHost, 3) end end end function UISelectRegionView:OnPingRequestFinish(handle, ping) local index = self.pingList[handle] if index then if ping < 0 or ping > 1000 then self.group_SelectArea[index].txt_Ping.text = ">1000ms" self.group_SelectArea[index].img_Ping:SetState(2) else ping = math.floor(ping) self.group_SelectArea[index].txt_Ping.text = ping.."ms" if ping <= 200 then self.group_SelectArea[index].img_Ping:SetState(0) elseif ping <= 400 then self.group_SelectArea[index].img_Ping:SetState(1) else self.group_SelectArea[index].img_Ping:SetState(2) end end end end function UISelectRegionView:OnNetworkPingCompleted(hostName, ping) local index = self.pingList[hostName] if index then if ping <= 0 or ping > 1000 then self.group_SelectArea[index].txt_Ping.text = ">1000ms" self.group_SelectArea[index].img_Ping:SetState(2) else ping = math.floor(ping) self.group_SelectArea[index].txt_Ping.text = ping.."ms" if ping <= 200 then self.group_SelectArea[index].img_Ping:SetState(0) elseif ping <= 400 then self.group_SelectArea[index].img_Ping:SetState(1) else self.group_SelectArea[index].img_Ping:SetState(2) end end end end function UISelectRegionView:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UISelectRegionView:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() elseif comp == self.btn_Refresh then self:RequestPing() elseif comp == self.btn_Change then self:ClickChange() else self:OnSelectRegion(comp) end end function UISelectRegionView:ClickChange() local now = os.time() local localutcseconds = os.difftime(now, os.time(UTL.Time.OsDateOriginal("!*t", now))) local timeZone = math.floor(localutcseconds / UTL.Time.TotalSecondsOneHour) local regionId = LocalizationRegionCfg.GetRegionIdByTimeZone(timeZone) if regionId then local regionType = LocalizationRegionCfg.GetRegionTypeDataById(regionId) if regionType.Number ~= self.selectRegion.Number then local name = UIUtils.GetLocalizedTxt(Const_IDS[self.selectRegion.RegionName]) local str = string.FormatByIdsId(Const_IDS.IDS_Region_SwitchRegionConfirmText, name) UTL.MessageBox.ShowOKCancelBox(nil, str, function() CTL.Login.SelectRegion(self.selectRegion.Number) end, nil) else CTL.Login.SelectRegion(self.selectRegion.Number) end end end function UISelectRegionView:OnSelectRegion(comp) for i,v in ipairs(self.group_SelectArea) do if comp == v.btn then local regionType = LocalizationRegionCfg.GetRegionTypeDataById(i) self.btn_Change:SetGray(regionType.Number == GameAppInfo.Global_ProductId) self.selectRegion = regionType end UIUtils.SetActive(v.img_Select, comp == v.btn) end end return UISelectRegionView