Differential D3911 Diff 17669 ps/trunk/binaries/data/mods/public/gui/session/top_panel/CounterResource.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/session/top_panel/CounterResource.js
/** | /** | ||||
* This class manages the counter in the top panel for one resource type. | * This class manages the counter in the top panel for one resource type. | ||||
*/ | */ | ||||
class CounterResource | class CounterResource | ||||
{ | { | ||||
constructor(resCode, panel, icon, count, stats) | constructor(resCode, panel, icon, count, stats) | ||||
{ | { | ||||
this.resCode = resCode; | this.resCode = resCode; | ||||
this.panel = panel; | this.panel = panel; | ||||
this.icon = icon; | this.icon = icon; | ||||
this.count = count; | this.count = count; | ||||
this.stats = stats; | this.stats = stats; | ||||
} | } | ||||
rebuild(playerState, getAllyStatTooltip) | rebuild(playerState, getAllyStatTooltip) | ||||
{ | { | ||||
this.count.caption = Math.floor(playerState.resourceCounts[this.resCode]); | this.count.caption = abbreviateLargeNumbers(Math.floor(playerState.resourceCounts[this.resCode])); | ||||
// Do not show zeroes. | |||||
let gatherers = playerState.resourceGatherers[this.resCode]; | let gatherers = playerState.resourceGatherers[this.resCode]; | ||||
this.stats.caption = gatherers || ""; | this.stats.caption = gatherers ? coloredText(gatherers, this.DefaultResourceGatherersColor) : 0; | ||||
// TODO: Set the tooltip only if hovered? | // TODO: Set the tooltip only if hovered? | ||||
let description = g_ResourceData.GetResource(this.resCode).description; | let description = g_ResourceData.GetResource(this.resCode).description; | ||||
if (description) | if (description) | ||||
description = "\n" + translate(description); | description = "\n" + translate(description); | ||||
this.panel.tooltip = | this.panel.tooltip = | ||||
setStringTags(resourceNameFirstWord(this.resCode), CounterManager.ResourceTitleTags) + | setStringTags(resourceNameFirstWord(this.resCode), CounterManager.ResourceTitleTags) + | ||||
description + | description + | ||||
getAllyStatTooltip(this.getTooltipData.bind(this)) + "\n" + | getAllyStatTooltip(this.getTooltipData.bind(this)) + "\n" + CounterPopulation.prototype.CurrentGatherersTooltip; | ||||
(gatherers > 0 ? sprintf(translate("Gatherers: %(amount)s"), { "amount" : gatherers }) : ""); | |||||
} | } | ||||
getTooltipData(playerState, playername) | getTooltipData(playerState, playername) | ||||
{ | { | ||||
return { | return { | ||||
"playername": playername, | "playername": playername, | ||||
"statValue": Math.round(playerState.resourceCounts[this.resCode]), | "statValue": Math.round(playerState.resourceCounts[this.resCode]), | ||||
"orderValue": Math.round(playerState.resourceCounts[this.resCode]) | "orderValue": Math.round(playerState.resourceCounts[this.resCode]) | ||||
}; | }; | ||||
} | } | ||||
} | } | ||||
/** | |||||
* Color to highlight the resource gatherers. | |||||
*/ | |||||
CounterResource.prototype.DefaultResourceGatherersColor = "gold"; |
Wildfire Games · Phabricator