diff --git a/binaries/data/mods/public/gui/common/functions_global_object.js b/binaries/data/mods/public/gui/common/functions_global_object.js index 3124055dcc..3736e4d6e2 100644 --- a/binaries/data/mods/public/gui/common/functions_global_object.js +++ b/binaries/data/mods/public/gui/common/functions_global_object.js @@ -63,69 +63,27 @@ function openURL(url) function updateCounters() { - var caption = ""; - var linesCount = 0; - var researchCount = 0; + let counters = []; if (Engine.ConfigDB_GetValue("user", "overlay.fps") === "true") - { - caption += sprintf(translate("FPS: %(fps)4s"), { "fps": Engine.GetFPS() }) + "\n"; - ++linesCount; - } + counters.push(sprintf(translate("FPS: %(fps)4s"), { "fps": Engine.GetFPS() })); + if (Engine.ConfigDB_GetValue("user", "overlay.realtime") === "true") - { - caption += (new Date()).toLocaleTimeString() + "\n"; - ++linesCount; - } + counters.push((new Date()).toLocaleTimeString()); // If game has been started - if (typeof g_SimState != "undefined") - { - if (Engine.ConfigDB_GetValue("user", "gui.session.timeelapsedcounter") === "true") - { - var currentSpeed = Engine.GetSimRate(); - if (currentSpeed != 1.0) - // Translation: The "x" means "times", with the mathematical meaning of multiplication. - caption += sprintf(translate("%(time)s (%(speed)sx)"), { - "time": timeToString(g_SimState.timeElapsed), - "speed": Engine.FormatDecimalNumberIntoString(currentSpeed) - }); - else - caption += timeToString(g_SimState.timeElapsed); - caption += "\n"; - ++linesCount; - } + if (typeof appendSessionCounters != "undefined") + appendSessionCounters(counters); - var diplomacyCeasefireCounter = Engine.GetGUIObjectByName("diplomacyCeasefireCounter"); - if (g_SimState.ceasefireActive) - { - // Update ceasefire counter in the diplomacy window - var remainingTimeString = timeToString(g_SimState.ceasefireTimeRemaining); - - diplomacyCeasefireCounter.caption = sprintf( - translateWithContext("ceasefire", "Time remaining until ceasefire is over: %(time)s."), - { "time": remainingTimeString } - ); - - // Update ceasefire overlay counter - if (Engine.ConfigDB_GetValue("user", "gui.session.ceasefirecounter") === "true") - { - caption += remainingTimeString + "\n"; - ++linesCount; - } - } - else if (!diplomacyCeasefireCounter.hidden) - diplomacyCeasefireCounter.hidden = true; - - g_ResearchListTop = 4; - if (linesCount) - g_ResearchListTop += 14 * linesCount; - } - - var dataCounter = Engine.GetGUIObjectByName("dataCounter"); - dataCounter.caption = caption; - dataCounter.size = sprintf("100%%-100 40 100%%-5 %(bottom)s", { "bottom": 40 + 14 * linesCount }); - dataCounter.hidden = linesCount == 0; + let dataCounter = Engine.GetGUIObjectByName("dataCounter"); + dataCounter.caption = counters.join("\n") + "\n"; + dataCounter.hidden = !counters.length; + dataCounter.size = sprintf("%(left)s %(top)s %(right)s %(bottom)s", { + "left": "100%%-100", + "top": "40", + "right": "100%%-5", + "bottom": 40 + 14 * counters.length + }); } /** @@ -165,6 +123,7 @@ function displayGamestateNotifications() /** * Also called from the C++ side when ending the game. + * The current page can be the summary screen or a message box, so it can't be moved to session/. */ function getReplayMetadata() { diff --git a/binaries/data/mods/public/gui/session/menu.js b/binaries/data/mods/public/gui/session/menu.js index 3d44285f10..e289a4ef01 100644 --- a/binaries/data/mods/public/gui/session/menu.js +++ b/binaries/data/mods/public/gui/session/menu.js @@ -315,6 +315,23 @@ function openDiplomacy() g_IsDiplomacyOpen = true; updateDiplomacy(true); + + Engine.GetGUIObjectByName("diplomacyDialogPanel").hidden = false; +} + +function closeDiplomacy() +{ + g_IsDiplomacyOpen = false; + Engine.GetGUIObjectByName("diplomacyDialogPanel").hidden = true; +} + +function toggleDiplomacy() +{ + let open = g_IsDiplomacyOpen; + closeOpenDialogs(); + + if (!open) + openDiplomacy(); } function updateDiplomacy(opening = false) @@ -322,7 +339,8 @@ function updateDiplomacy(opening = false) if (g_ViewedPlayer < 1 || !g_IsDiplomacyOpen) return; - let isCeasefireActive = GetSimState().ceasefireActive; + let simState = GetSimState(); + let isCeasefireActive = simState.ceasefireActive; let hasSharedLos = GetSimState().players[g_ViewedPlayer].hasSharedLos; // Get offset for one line @@ -344,7 +362,13 @@ function updateDiplomacy(opening = false) diplomacyFormatAttackRequestButton(i, myself || playerInactive || isCeasefireActive || !hasAllies || !g_Players[i].isEnemy[g_ViewedPlayer]); diplomacyFormatSpyRequestButton(i, myself || playerInactive || g_Players[i].isMutualAlly[g_ViewedPlayer] && hasSharedLos); } - Engine.GetGUIObjectByName("diplomacyDialogPanel").hidden = false; + + let diplomacyCeasefireCounter = Engine.GetGUIObjectByName("diplomacyCeasefireCounter"); + diplomacyCeasefireCounter.caption = sprintf( + translateWithContext("ceasefire", "Time remaining until ceasefire is over: %(time)s."), + { "time": timeToString(simState.ceasefireTimeRemaining) } + ); + diplomacyCeasefireCounter.hidden = !isCeasefireActive; } function diplomacySetupTexts(i, rowsize) @@ -519,21 +543,6 @@ function diplomacyFormatSpyRequestButton(i, hidden) }; })(i); } -function closeDiplomacy() -{ - g_IsDiplomacyOpen = false; - Engine.GetGUIObjectByName("diplomacyDialogPanel").hidden = true; -} - -function toggleDiplomacy() -{ - let open = g_IsDiplomacyOpen; - closeOpenDialogs(); - - if (!open) - openDiplomacy(); -} - function resizeTradeDialog() { let dialog = Engine.GetGUIObjectByName("tradeDialogPanel"); diff --git a/binaries/data/mods/public/gui/session/session.js b/binaries/data/mods/public/gui/session/session.js index 7254d50003..2d0e1c9109 100644 --- a/binaries/data/mods/public/gui/session/session.js +++ b/binaries/data/mods/public/gui/session/session.js @@ -1277,6 +1277,33 @@ function showTimeWarpMessageBox() ); } +/** + * Adds the ingame time and ceasefire counter to the global FPS and + * realtime counters shown in the top right corner. + */ +function appendSessionCounters(counters) +{ + let simState = GetSimState(); + + if (Engine.ConfigDB_GetValue("user", "gui.session.timeelapsedcounter") === "true") + { + let currentSpeed = Engine.GetSimRate(); + if (currentSpeed != 1.0) + // Translation: The "x" means "times", with the mathematical meaning of multiplication. + counters.push(sprintf(translate("%(time)s (%(speed)sx)"), { + "time": timeToString(simState.timeElapsed), + "speed": Engine.FormatDecimalNumberIntoString(currentSpeed) + })); + else + counters.push(timeToString(simState.timeElapsed)); + } + + if (simState.ceasefireActive && Engine.ConfigDB_GetValue("user", "gui.session.ceasefirecounter") === "true") + counters.push(timeToString(simState.ceasefireTimeRemaining)); + + g_ResearchListTop = 4 + 14 * counters.length; +} + /** * Send the current list of players, teams, AIs, observers and defeated/won and offline states to the lobby. * The playerData format from g_GameAttributes is kept to reuse the GUI function presenting the data.