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()
|
function updateCounters()
|
||||||
{
|
{
|
||||||
var caption = "";
|
let counters = [];
|
||||||
var linesCount = 0;
|
|
||||||
var researchCount = 0;
|
|
||||||
|
|
||||||
if (Engine.ConfigDB_GetValue("user", "overlay.fps") === "true")
|
if (Engine.ConfigDB_GetValue("user", "overlay.fps") === "true")
|
||||||
{
|
counters.push(sprintf(translate("FPS: %(fps)4s"), { "fps": Engine.GetFPS() }));
|
||||||
caption += sprintf(translate("FPS: %(fps)4s"), { "fps": Engine.GetFPS() }) + "\n";
|
|
||||||
++linesCount;
|
|
||||||
}
|
|
||||||
if (Engine.ConfigDB_GetValue("user", "overlay.realtime") === "true")
|
if (Engine.ConfigDB_GetValue("user", "overlay.realtime") === "true")
|
||||||
{
|
counters.push((new Date()).toLocaleTimeString());
|
||||||
caption += (new Date()).toLocaleTimeString() + "\n";
|
|
||||||
++linesCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If game has been started
|
// If game has been started
|
||||||
if (typeof g_SimState != "undefined")
|
if (typeof appendSessionCounters != "undefined")
|
||||||
{
|
appendSessionCounters(counters);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
var diplomacyCeasefireCounter = Engine.GetGUIObjectByName("diplomacyCeasefireCounter");
|
let dataCounter = Engine.GetGUIObjectByName("dataCounter");
|
||||||
if (g_SimState.ceasefireActive)
|
dataCounter.caption = counters.join("\n") + "\n";
|
||||||
{
|
dataCounter.hidden = !counters.length;
|
||||||
// Update ceasefire counter in the diplomacy window
|
dataCounter.size = sprintf("%(left)s %(top)s %(right)s %(bottom)s", {
|
||||||
var remainingTimeString = timeToString(g_SimState.ceasefireTimeRemaining);
|
"left": "100%%-100",
|
||||||
|
"top": "40",
|
||||||
diplomacyCeasefireCounter.caption = sprintf(
|
"right": "100%%-5",
|
||||||
translateWithContext("ceasefire", "Time remaining until ceasefire is over: %(time)s."),
|
"bottom": 40 + 14 * counters.length
|
||||||
{ "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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -165,6 +123,7 @@ function displayGamestateNotifications()
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Also called from the C++ side when ending the game.
|
* 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()
|
function getReplayMetadata()
|
||||||
{
|
{
|
||||||
|
@ -315,6 +315,23 @@ function openDiplomacy()
|
|||||||
g_IsDiplomacyOpen = true;
|
g_IsDiplomacyOpen = true;
|
||||||
|
|
||||||
updateDiplomacy(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)
|
function updateDiplomacy(opening = false)
|
||||||
@ -322,7 +339,8 @@ function updateDiplomacy(opening = false)
|
|||||||
if (g_ViewedPlayer < 1 || !g_IsDiplomacyOpen)
|
if (g_ViewedPlayer < 1 || !g_IsDiplomacyOpen)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
let isCeasefireActive = GetSimState().ceasefireActive;
|
let simState = GetSimState();
|
||||||
|
let isCeasefireActive = simState.ceasefireActive;
|
||||||
let hasSharedLos = GetSimState().players[g_ViewedPlayer].hasSharedLos;
|
let hasSharedLos = GetSimState().players[g_ViewedPlayer].hasSharedLos;
|
||||||
|
|
||||||
// Get offset for one line
|
// 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]);
|
diplomacyFormatAttackRequestButton(i, myself || playerInactive || isCeasefireActive || !hasAllies || !g_Players[i].isEnemy[g_ViewedPlayer]);
|
||||||
diplomacyFormatSpyRequestButton(i, myself || playerInactive || g_Players[i].isMutualAlly[g_ViewedPlayer] && hasSharedLos);
|
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)
|
function diplomacySetupTexts(i, rowsize)
|
||||||
@ -519,21 +543,6 @@ function diplomacyFormatSpyRequestButton(i, hidden)
|
|||||||
}; })(i);
|
}; })(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeDiplomacy()
|
|
||||||
{
|
|
||||||
g_IsDiplomacyOpen = false;
|
|
||||||
Engine.GetGUIObjectByName("diplomacyDialogPanel").hidden = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleDiplomacy()
|
|
||||||
{
|
|
||||||
let open = g_IsDiplomacyOpen;
|
|
||||||
closeOpenDialogs();
|
|
||||||
|
|
||||||
if (!open)
|
|
||||||
openDiplomacy();
|
|
||||||
}
|
|
||||||
|
|
||||||
function resizeTradeDialog()
|
function resizeTradeDialog()
|
||||||
{
|
{
|
||||||
let dialog = Engine.GetGUIObjectByName("tradeDialogPanel");
|
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.
|
* 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.
|
* The playerData format from g_GameAttributes is kept to reuse the GUI function presenting the data.
|
||||||
|
Loading…
Reference in New Issue
Block a user