From a3f223ffe29f8388d1a7a972b215e979f059af0b Mon Sep 17 00:00:00 2001 From: chenxi Date: Fri, 16 Jun 2023 16:16:39 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=B4=E6=8A=A4=E5=85=AC=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/app/module/login/login_manager.lua | 16 ++++++++++++++-- .../module/login/maintenance_notice_ui.lua | 19 ++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lua/app/module/login/login_manager.lua b/lua/app/module/login/login_manager.lua index 79fc1280..4b3bb209 100644 --- a/lua/app/module/login/login_manager.lua +++ b/lua/app/module/login/login_manager.lua @@ -30,6 +30,18 @@ function LoginManager:loginGame() ModuleManager.MaincityManager:firstEnterMainCity() end +function LoginManager:updateServerTime(serverTime) + self.serverTime = (serverTime or 0) // 1000 + self.differenceTime = -GFunc.getTickCount() +end + +function LoginManager:getServerTime() + if not self.serverTime then + return os.time() + end + return self.serverTime + (self.differenceTime or 0) + GFunc.getTickCount() +end + function LoginManager:getClientInfo() local clientInfo = {} local bundleId = Platform:getIdentifier() @@ -279,7 +291,7 @@ end function LoginManager:checkServerOpen() local serverOpenTime = tonumber(self.versionInfo.open_at or 0) - local clientTime = Time:getServerTime()*1000 + local clientTime = self:getServerTime()*1000 if clientTime < serverOpenTime then -- 未开服 self:showMaintenanceNoticeUI(self.versionInfo.notice, serverOpenTime) return @@ -353,7 +365,7 @@ function LoginManager:getServerList() local serverTime = (jsonData.now or 0) if serverTime > 0 then - Time:updateServerTime(serverTime) + ModuleManager.LoginManager:updateServerTime(serverTime) end self.versionInfo = jsonData self:checkServerOpen() diff --git a/lua/app/module/login/maintenance_notice_ui.lua b/lua/app/module/login/maintenance_notice_ui.lua index b25ea7c6..0c9c19ba 100644 --- a/lua/app/module/login/maintenance_notice_ui.lua +++ b/lua/app/module/login/maintenance_notice_ui.lua @@ -16,14 +16,27 @@ end function MaintenanceNoticeUI:onLoadRootComplete() local uiMap = self.root:genAllChildren() uiMap["maintenance_notice_ui.bg.title_bg.title_tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.NOTICE_TITLE)) + local contentTx = uiMap["maintenance_notice_ui.bg.img_2.scrollrect.viewport.content.content_tx"] if self.content == nil or self.content == "" then - uiMap["maintenance_notice_ui.bg.img_2.content_tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.MAINTENANCE_NOTICE_DEFAULT)) + contentTx:setText(I18N:getGlobalText(I18N.GlobalConst.MAINTENANCE_NOTICE_DEFAULT)) else - uiMap["maintenance_notice_ui.bg.img_2.content_tx"]:setText(self.content) + contentTx:setText(self.content) end + local scrollRectHeight = uiMap["maintenance_notice_ui.bg.img_2.scrollrect"]:getRectHeight() + local topOffset = -contentTx:fastGetAnchoredPositionY() + contentTx:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT_MESH_PRO):ForceMeshUpdate() + local height = contentTx:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT_MESH_PRO).renderedHeight + if height > scrollRectHeight then + uiMap["maintenance_notice_ui.bg.img_2.scrollrect"]:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_SCROLL_RECT).movementType = CS.UnityEngine.UI.ScrollRect.MovementType.Elastic + uiMap["maintenance_notice_ui.bg.img_2.scrollrect.viewport.content"]:setSizeDeltaY(height + topOffset*2) + else + uiMap["maintenance_notice_ui.bg.img_2.scrollrect"]:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_SCROLL_RECT).movementType = CS.UnityEngine.UI.ScrollRect.MovementType.Clamped + uiMap["maintenance_notice_ui.bg.img_2.scrollrect.viewport.content"]:setSizeDeltaY(scrollRectHeight) + end + uiMap["maintenance_notice_ui.bg.img_2.scrollrect.viewport.content"]:setAnchoredPositionY(0) uiMap["maintenance_notice_ui.bg.ok_btn"]:addClickListener(function() self:closeUI() - local clientTime = Time:getServerTime()*1000 + local clientTime = ModuleManager.LoginManager:getServerTime()*1000 if clientTime >= self.openTime then ModuleManager.LoginManager:resetServerListStartTime() ModuleManager.LoginManager:getServerList()