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.
This commit is contained in:
temple 2018-01-30 00:02:10 +00:00
parent 7e14a33411
commit 1ba1e86c5e
6 changed files with 32 additions and 53 deletions

View file

@ -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)
});
}
/**

View file

@ -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,

View file

@ -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
};
};

View file

@ -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)

View file

@ -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)

View file

@ -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);