0ad/binaries/data/mods/public/gui/session/top_panel/CounterPopulation.js
Dunedan dee2b73c7d
Remove pointless content from counter tooltips
This removes the static text "Gatherers: current" from the
resource and population counter tooltips. This string was static and
only changed its color depending on whether units were assigned to
collect a certain resource. That information is however already
available in the counter display itself.
2025-04-24 18:49:10 +02:00

81 lines
2.4 KiB
JavaScript

/**
* This class manages the population counter in the top panel.
* It flashes the counter if the training of any owned entity is blocked.
*/
class CounterPopulation
{
constructor(resCode, panel, icon, count, stats)
{
this.resCode = resCode;
this.panel = panel;
this.icon = icon;
this.count = count;
this.count.onTick = this.onTick.bind(this);
this.isTrainingBlocked = false;
this.color = this.DefaultPopulationColor;
this.stats = stats;
}
rebuild(playerState, getAllyStatTooltip)
{
this.count.caption = sprintf(translate(this.CounterCaption), playerState);
let total = 0;
for (let resCode of g_ResourceData.GetCodes())
total += playerState.resourceGatherers[resCode];
this.stats.caption = coloredText(total, total ? this.DefaultTotalGatherersColor : this.DefaultTotalGatherersColorZero);
this.isTrainingBlocked = playerState.trainingBlocked;
this.panel.tooltip =
setStringTags(translate(this.PopulationTooltip), CounterManager.ResourceTitleTags) +
getAllyStatTooltip(this.getTooltipData.bind(this));
}
getTooltipData(playerState, playername)
{
return {
"playername": playername,
"statValue": sprintf(translate(this.AllyPopulationTooltip), playerState),
"orderValue": playerState.popCount
};
}
onTick()
{
if (this.panel.hidden)
return;
let newColor = this.isTrainingBlocked && Date.now() % 1000 < 500 ?
this.PopulationAlertColor :
this.DefaultPopulationColor;
if (newColor == this.color)
return;
this.color = newColor;
this.count.textcolor = newColor;
}
}
// Translation: Do not insert spaces around the slash symbol for this exact string. Keep only one space between popLimit and popMax.
CounterPopulation.prototype.CounterCaption = markForTranslation("%(popCount)s/%(popLimit)s (%(popMax)s)");
CounterPopulation.prototype.PopulationTooltip = markForTranslation("Population: current/limit (max)");
CounterPopulation.prototype.AllyPopulationTooltip = markForTranslation("%(popCount)s/%(popLimit)s (%(popMax)s)");
/**
* Color to highlight the total number of gatherers at zero.
*/
CounterPopulation.prototype.DefaultTotalGatherersColorZero = "200 200 200";
/**
* Color to highlight the total number of gatherers.
*/
CounterPopulation.prototype.DefaultTotalGatherersColor = "gold";
/**
* Colors to flash when pop limit reached.
*/
CounterPopulation.prototype.DefaultPopulationColor = "white";
CounterPopulation.prototype.PopulationAlertColor = "orange";