forked from 0ad/0ad
Move ingame time and ceasefire timer code from gui/common/ to gui/session/.
Use an array instead of string concatenation to avoid duplication and to enforce newlines on the syntax layer. Move closeDiplomacy and toggleDiplomacy to openDiplomacy. Differential Revision: https://code.wildfiregames.com/D183 Reviewed By: bb This was SVN commit r19268.
This commit is contained in:
parent
399ba92058
commit
380a429fc9
@ -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()
|
||||
{
|
||||
|
@ -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");
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user