mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-08-15 14:43:32 -07:00
It was removed in dee2b73c7d since it wasn't noticed that it referred to
the number in the top panel. Adding the number should make this more
clear. The color is only applied to the number instead of the whole line
so that it's harder to mistake it with just some fancy formatting.
Fixes: #7851
56 lines
1.6 KiB
JavaScript
56 lines
1.6 KiB
JavaScript
/**
|
|
* This class manages the counter in the top panel for one resource type.
|
|
*/
|
|
class CounterResource
|
|
{
|
|
constructor(resCode, panel, icon, count, stats)
|
|
{
|
|
this.resCode = resCode;
|
|
this.panel = panel;
|
|
this.icon = icon;
|
|
this.count = count;
|
|
this.stats = stats;
|
|
}
|
|
|
|
rebuild(playerState, getAllyStatTooltip)
|
|
{
|
|
this.count.caption = abbreviateLargeNumbers(Math.floor(playerState.resourceCounts[this.resCode]));
|
|
|
|
const gatherers = playerState.resourceGatherers[this.resCode];
|
|
const colorizedGatherers = coloredText(gatherers,
|
|
gatherers ? this.DefaultResourceGatherersColor : this.DefaultResourceGatherersColorZero);
|
|
this.stats.caption = colorizedGatherers;
|
|
|
|
|
|
// TODO: Set the tooltip only if hovered?
|
|
let description = g_ResourceData.GetResource(this.resCode).description;
|
|
if (description)
|
|
description = "\n" + translate(description);
|
|
|
|
this.panel.tooltip =
|
|
setStringTags(resourceNameFirstWord(this.resCode), CounterManager.ResourceTitleTags) +
|
|
description +
|
|
getAllyStatTooltip(this.getTooltipData.bind(this)) + "\n" +
|
|
sprintf(CounterPopulation.prototype.CurrentGatherersTooltip,
|
|
{ "currentGatherers": colorizedGatherers });
|
|
}
|
|
|
|
getTooltipData(playerState, playername)
|
|
{
|
|
return {
|
|
"playername": playername,
|
|
"statValue": Math.round(playerState.resourceCounts[this.resCode]),
|
|
"orderValue": Math.round(playerState.resourceCounts[this.resCode])
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Color to highlight the resource gatherers at zero.
|
|
*/
|
|
CounterResource.prototype.DefaultResourceGatherersColorZero = "200 200 200";
|
|
|
|
/**
|
|
* Color to highlight the resource gatherers.
|
|
*/
|
|
CounterResource.prototype.DefaultResourceGatherersColor = "gold";
|