From 1ba1e86c5e6fffcb174b0e70e082876dbdd10328 Mon Sep 17 00:00:00 2001 From: temple Date: Tue, 30 Jan 2018 00:02:10 +0000 Subject: [PATCH] Use a countdown rather than a tooltip for displaying construction progress Change the time to completion to a countdown and remove the tooltip on the health bar. Move the number of builders to the time speed-up tooltip. Remove the build rate tooltip. Differential Revision: https://code.wildfiregames.com/D572 Early review by: wraitii Comments by: bb This was SVN commit r21072. --- .../data/mods/public/gui/common/tooltips.js | 30 ++++++++++++------ .../public/gui/session/selection_details.js | 31 +++---------------- .../simulation/components/Foundation.js | 2 +- .../simulation/components/GuiInterface.js | 12 ++----- .../public/simulation/components/Mirage.js | 6 ++-- .../components/tests/test_Foundation.js | 4 +-- 6 files changed, 32 insertions(+), 53 deletions(-) diff --git a/binaries/data/mods/public/gui/common/tooltips.js b/binaries/data/mods/public/gui/common/tooltips.js index 843e47581e..33cfc84cab 100644 --- a/binaries/data/mods/public/gui/common/tooltips.js +++ b/binaries/data/mods/public/gui/common/tooltips.js @@ -366,18 +366,28 @@ function getRepairRateTooltip(template) }); } -function getBuildRateTooltip(template) +function getBuildTimeTooltip(entState) { - if (!template.buildRate) - return ""; + if (!entState.foundation.numBuilders) + return sprintf(translatePlural( + "Add a worker to finish the construction in %(second)s second.", + "Add a worker to finish the construction in %(second)s seconds.", + Math.round(entState.foundation.buildTime.timeRemainingNew)), + { + "second": Math.round(entState.foundation.buildTime.timeRemainingNew) + }); - return sprintf(translate("%(buildRateLabel)s %(value)s %(health)s / %(second)s / %(worker)s"), { - "buildRateLabel": headerFont(translate("Build Rate:")), - "value": template.buildRate.toFixed(1), - "health": unitFont(translate("Health")), - "second": unitFont(translate("second")), - "worker": unitFont(translate("Worker")) - }); + return sprintf(translate("%(label)s %(details)s"), { + "label": headerFont(translate("Number of builders:")), + "details": entState.foundation.numBuilders + }) + "\n" + + sprintf(translatePlural( + "Add another worker to speed up the construction by %(second)s second.", + "Add another worker to speed up the construction by %(second)s seconds.", + Math.round(entState.foundation.buildTime.timeRemaining - entState.foundation.buildTime.timeRemainingNew)), + { + "second": Math.round(entState.foundation.buildTime.timeRemaining - entState.foundation.buildTime.timeRemainingNew) + }); } /** diff --git a/binaries/data/mods/public/gui/session/selection_details.js b/binaries/data/mods/public/gui/session/selection_details.js index 90957c186d..fd6c679bb4 100644 --- a/binaries/data/mods/public/gui/session/selection_details.js +++ b/binaries/data/mods/public/gui/session/selection_details.js @@ -111,19 +111,6 @@ function displaySingle(entState) let healthSize = unitHealthBar.size; healthSize.rright = 100 * Math.max(0, Math.min(1, entState.hitpoints / entState.maxHitpoints)); unitHealthBar.size = healthSize; - - if (entState.foundation && entState.visibility == "visible" && entState.foundation.numBuilders !== 0 && entState.buildTime) - Engine.GetGUIObjectByName("health").tooltip = sprintf( - translatePlural( - "This foundation will be completed in %(seconds)s second.", - "This foundation will be completed in %(seconds)s seconds.", - Math.ceil(entState.buildTime.timeRemaining)), - { - "seconds": Math.ceil(entState.buildTime.timeRemaining) - }); - else - Engine.GetGUIObjectByName("health").tooltip = ""; - Engine.GetGUIObjectByName("healthStats").caption = sprintf(translate("%(hitpoints)s / %(maxHitpoints)s"), { "hitpoints": Math.ceil(entState.hitpoints), "maxHitpoints": Math.ceil(entState.maxHitpoints) @@ -248,23 +235,14 @@ function displaySingle(entState) }); } // And for number of workers - else if (entState.foundation && entState.visibility != "hidden") + else if (entState.foundation) { Engine.GetGUIObjectByName("resourceCarryingIcon").hidden = false; Engine.GetGUIObjectByName("resourceCarryingText").hidden = false; Engine.GetGUIObjectByName("resourceCarryingIcon").sprite = "stretched:session/icons/repair.png"; - Engine.GetGUIObjectByName("resourceCarryingText").caption = entState.foundation.numBuilders + " "; - if (entState.foundation.numBuilders !== 0 && entState.visibility == "visible" && entState.buildTime) - Engine.GetGUIObjectByName("resourceCarryingIcon").tooltip = sprintf( - translatePlural( - "Number of builders.\nTasking another to this foundation would speed construction up by %(speedup)s second.", - "Number of builders.\nTasking another to this foundation would speed construction up by %(speedup)s seconds.", - Math.ceil(entState.buildTime.timeSpeedup)), - { - "speedup": Math.ceil(entState.buildTime.timeSpeedup) - }); - else - Engine.GetGUIObjectByName("resourceCarryingIcon").tooltip = translate("Number of builders."); + Engine.GetGUIObjectByName("resourceCarryingIcon").tooltip = getBuildTimeTooltip(entState); + Engine.GetGUIObjectByName("resourceCarryingText").caption = entState.foundation.numBuilders ? + Engine.FormatMillisecondsIntoDateStringGMT(entState.foundation.buildTime.timeRemaining * 1000, translateWithContext("countdown format", "m:ss")) + " " : ""; } else if (entState.repairable && entState.repairable.numBuilders > 0 && entState.visibility != "hidden") { @@ -313,7 +291,6 @@ function displaySingle(entState) getArmorTooltip, getGatherTooltip, getRepairRateTooltip, - getBuildRateTooltip, getSpeedTooltip, getGarrisonTooltip, getProjectilesTooltip, diff --git a/binaries/data/mods/public/simulation/components/Foundation.js b/binaries/data/mods/public/simulation/components/Foundation.js index 9c6fe07ee5..9b015e9a3e 100644 --- a/binaries/data/mods/public/simulation/components/Foundation.js +++ b/binaries/data/mods/public/simulation/components/Foundation.js @@ -173,7 +173,7 @@ Foundation.prototype.GetBuildTime = function() let rateNew = (this.totalBuilderRate + 1) * this.CalculateBuildMultiplier(this.GetNumBuilders() + 1); return { "timeRemaining": timeLeft / rate, - "timeSpeedup": timeLeft / rate - timeLeft / rateNew + "timeRemainingNew": timeLeft / rateNew }; }; diff --git a/binaries/data/mods/public/simulation/components/GuiInterface.js b/binaries/data/mods/public/simulation/components/GuiInterface.js index dbb25101ba..6a37c3cbd5 100644 --- a/binaries/data/mods/public/simulation/components/GuiInterface.js +++ b/binaries/data/mods/public/simulation/components/GuiInterface.js @@ -308,18 +308,10 @@ GuiInterface.prototype.GetEntityState = function(player, ent) let cmpFoundation = QueryMiragedInterface(ent, IID_Foundation); if (cmpFoundation) - { ret.foundation = { - "progress": cmpFoundation.GetBuildPercentage(), - "numBuilders": cmpFoundation.GetNumBuilders() + "numBuilders": cmpFoundation.GetNumBuilders(), + "buildTime": cmpFoundation.GetBuildTime() }; - cmpFoundation = Engine.QueryInterface(ent, IID_Foundation); - if (cmpFoundation) - { - ret.buildRate = cmpFoundation.GetBuildRate(); - ret.buildTime = cmpFoundation.GetBuildTime(); - } - } let cmpRepairable = QueryMiragedInterface(ent, IID_Repairable); if (cmpRepairable) diff --git a/binaries/data/mods/public/simulation/components/Mirage.js b/binaries/data/mods/public/simulation/components/Mirage.js index cd1f168587..70403a8941 100644 --- a/binaries/data/mods/public/simulation/components/Mirage.js +++ b/binaries/data/mods/public/simulation/components/Mirage.js @@ -17,8 +17,8 @@ Mirage.prototype.Init = function() this.classesList = []; - this.buildPercentage = 0; this.numBuilders = 0; + this.buildTime = {}; this.maxHitpoints = null; this.hitpoints = null; @@ -77,12 +77,12 @@ Mirage.prototype.GetClassesList = function() { return this.classesList }; Mirage.prototype.CopyFoundation = function(cmpFoundation) { this.miragedIids.add(IID_Foundation); - this.buildPercentage = cmpFoundation.GetBuildPercentage(); this.numBuilders = cmpFoundation.GetNumBuilders(); + this.buildTime = cmpFoundation.GetBuildTime(); }; -Mirage.prototype.GetBuildPercentage = function() { return this.buildPercentage; }; Mirage.prototype.GetNumBuilders = function() { return this.numBuilders; }; +Mirage.prototype.GetBuildTime = function() { return this.buildTime; }; // Repairable data (numBuilders shared with foundation as entities can't have both) diff --git a/binaries/data/mods/public/simulation/components/tests/test_Foundation.js b/binaries/data/mods/public/simulation/components/tests/test_Foundation.js index d739ca7084..0c61a5a08a 100644 --- a/binaries/data/mods/public/simulation/components/tests/test_Foundation.js +++ b/binaries/data/mods/public/simulation/components/tests/test_Foundation.js @@ -147,7 +147,7 @@ function testFoundation(...mocks) // Foundation starts with 1 hp, so there's 50 * 99/100 = 49.5 seconds left. TS_ASSERT_UNEVAL_EQUALS(cmpFoundation.GetBuildTime(), { 'timeRemaining': 49.5, - 'timeSpeedup': 49.5 - 49.5 / (2 * twoBuilderMultiplier) + 'timeRemainingNew': 49.5 / (2 * twoBuilderMultiplier) }); cmpFoundation.AddBuilder(11); TS_ASSERT_EQUALS(cmpFoundation.GetNumBuilders(), 2); @@ -155,7 +155,7 @@ function testFoundation(...mocks) TS_ASSERT_EQUALS(cmpFoundation.totalBuilderRate, 2); TS_ASSERT_UNEVAL_EQUALS(cmpFoundation.GetBuildTime(), { 'timeRemaining': 49.5 / (2 * twoBuilderMultiplier), - 'timeSpeedup': 49.5 / (2 * twoBuilderMultiplier) - 49.5 / (3 * threeBuilderMultiplier) + 'timeRemainingNew': 49.5 / (3 * threeBuilderMultiplier) }); cmpFoundation.AddBuilder(11); TS_ASSERT_EQUALS(cmpFoundation.GetNumBuilders(), 2);