improve display of timing options, patch by Vladislav, fixes #2894

This was SVN commit r16732.
This commit is contained in:
mimo
2015-06-07 20:58:51 +00:00
parent 6a1ee7137c
commit f260e75499
4 changed files with 80 additions and 59 deletions
@@ -74,7 +74,58 @@ function openURL(url)
messageBox(600, 200, sprintf(translate("Opening %(url)s\n in default web browser. Please wait...."), { url: url }), translate("Opening page"), 2);
}
function updateFPS()
{
Engine.GetGUIObjectByName("fpsCounter").caption = sprintf(translate("FPS: %(fps)s"), { fps: Engine.GetFPS() });
function updateCounters()
{
var caption = "";
var linesCount = 0;
var researchCount = 0;
if (Engine.ConfigDB_GetValue("user", "overlay.fps") === "true")
{
caption += sprintf(translate("FPS: %(fps)4s"), { fps: Engine.GetFPS() }) + "\n";
++linesCount;
}
if (Engine.ConfigDB_GetValue("user", "overlay.realtime") === "true")
{
caption += (new Date()).toLocaleTimeString() + "\n";
++linesCount;
}
// 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)
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 (Engine.ConfigDB_GetValue("user", "gui.session.ceasefirecounter") === "true" && g_SimState.ceasefireActive)
{
var remainingTimeString = timeToString(g_SimState.ceasefireTimeRemaining);
caption += remainingTimeString + "\n";
var diplomacyCeasefireCounter = Engine.GetGUIObjectByName("diplomacyCeasefireCounter");
diplomacyCeasefireCounter.caption = sprintf(translateWithContext("ceasefire", "Time remaining until ceasefire is over: %(time)s."), {"time": remainingTimeString});
++linesCount;
}
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 });
}
+20 -22
View File
@@ -14,27 +14,34 @@
<!--
==========================================
- FPS COUNTER
- FPS & REAL TIME & GAME TIME COUNTER
==========================================
-->
<object name="dataCounter"
type="text"
ghost="true"
hidden="false"
z="199"
size="100%-90 40 100%-5 40"
font="mono-10"
textcolor="white"
text_align="right"
text_valign="top"
sprite="color: 0 0 0 100"
>
<action on="Tick">
updateCounters();
</action>
</object>
<object name="fpsCounter"
type="text"
ghost="true"
hidden="true"
hotkey="fps.toggle"
sprite="color: 0 0 0 200"
font="mono-stroke-10"
textcolor="white"
size="100%-130 50 100%-60 70"
z="199"
>
<action on="Tick">
this.hidden = Engine.ConfigDB_GetValue("user", "overlay.fps") !== "true";
updateFPS();
</action>
<action on="Press">
Engine.ConfigDB_CreateValue("user", "overlay.fps", ""+this.hidden);
Engine.ConfigDB_CreateValue("user", "overlay.fps", ""+(Engine.ConfigDB_GetValue("user", "overlay.fps")!== "true"));
</action>
</object>
@@ -49,18 +56,9 @@
ghost="true"
hidden="true"
hotkey="realtime.toggle"
sprite="color: 0 0 0 200"
font="mono-stroke-10"
textcolor="white"
size="100%-130 80 100%-60 100"
z="199"
>
<action on="Tick">
this.hidden = Engine.ConfigDB_GetValue("user", "overlay.realtime") !== "true";
this.caption = (new Date()).toLocaleTimeString();
</action>
<action on="Press">
Engine.ConfigDB_CreateValue("user", "overlay.realtime", ""+this.hidden);
Engine.ConfigDB_CreateValue("user", "overlay.realtime", ""+(Engine.ConfigDB_GetValue("user", "overlay.realtime") !== "true"));
</action>
</object>
@@ -44,6 +44,9 @@ var g_Disconnected = false; // Lost connection to server
// Holds player states from the last tick
var g_CachedLastStates = "";
// Top coordinate of the research list
var g_ResearchListTop = 4;
// Colors to flash when pop limit reached
const DEFAULT_POPULATION_COLOR = "white";
const POPULATION_ALERT_COLOR = "orange";
@@ -542,8 +545,6 @@ function onSimulationUpdate()
updatePlayerDisplay();
updateSelectionDetails();
updateBuildingPlacementPreview();
updateTimeElapsedCounter();
updateCeasefireCounter();
updateTimeNotifications();
if (!g_IsObserver)
updateResearchDisplay();
@@ -756,7 +757,7 @@ function updateResearchDisplay()
{
var button = Engine.GetGUIObjectByName("researchStartedButton[" + i + "]");
var size = button.size;
size.top = (4 + buttonSideLength) * i;
size.top = g_ResearchListTop + (4 + buttonSideLength) * i;
size.bottom = size.top + buttonSideLength;
button.size = size;
}
@@ -792,32 +793,6 @@ function updateResearchDisplay()
Engine.GetGUIObjectByName("researchStartedButton[" + i + "]").hidden = true;
}
function updateCeasefireCounter()
{
var simState = GetSimState();
var isActive = simState.ceasefireActive;
var remainingTimeString = timeToString(simState.ceasefireTimeRemaining);
var ceasefireCounter = Engine.GetGUIObjectByName("ceasefireCounter");
var diplomacyCeasefireCounter = Engine.GetGUIObjectByName("diplomacyCeasefireCounter");
ceasefireCounter.hidden = !isActive || Engine.ConfigDB_GetValue("user", "gui.session.ceasefirecounter") !== "true";
diplomacyCeasefireCounter.hidden = !isActive;
ceasefireCounter.caption = remainingTimeString;
diplomacyCeasefireCounter.caption = sprintf(translateWithContext("ceasefire", "Time remaining until ceasefire is over: %(time)s."), {"time": remainingTimeString});
}
function updateTimeElapsedCounter()
{
var simState = GetSimState();
var timeElapsedCounter = Engine.GetGUIObjectByName("timeElapsedCounter");
if (g_CurrentSpeed != 1.0)
timeElapsedCounter.caption = sprintf(translate("%(time)s (%(speed)sx)"), { time: timeToString(simState.timeElapsed), speed: Engine.FormatDecimalNumberIntoString(g_CurrentSpeed) });
else
timeElapsedCounter.caption = timeToString(simState.timeElapsed);
}
// Toggles the display of status bars for all of the player's entities.
function recalculateStatusBarDisplay()
{
@@ -152,16 +152,13 @@
<!-- ================================ ================================ -->
<object size="100%-250 45 100%-140 65" type="text" name="timeElapsedCounter" style="SettingsText" hotkey="timeelapsedcounter.toggle" hidden="true">
<action on="Tick">
this.hidden = Engine.ConfigDB_GetValue("user", "gui.session.timeelapsedcounter") !== "true";
</action>
<action on="Press">
Engine.ConfigDB_CreateValue("user", "gui.session.timeelapsedcounter", ""+this.hidden);
Engine.ConfigDB_CreateValue("user", "gui.session.timeelapsedcounter", ""+(Engine.ConfigDB_GetValue("user", "gui.session.timeelapsedcounter") !== "true"));
</action>
</object>
<object size="100%-250 80 100%-140 100" type="text" name="ceasefireCounter" style="SettingsText" hotkey="ceasefirecounter.toggle" hidden="true">
<action on="Press">
Engine.ConfigDB_CreateValue("user", "gui.session.ceasefirecounter", ""+this.hidden);
Engine.ConfigDB_CreateValue("user", "gui.session.ceasefirecounter", ""+(Engine.ConfigDB_GetValue("user", "gui.session.ceasefirecounter") !== "true"));
</action>
</object>