Differential D3155 Diff 14521 ps/trunk/binaries/data/mods/public/gui/session/top_panel/CounterPopulation.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/session/top_panel/CounterPopulation.js
/** | /** | ||||
* This class manages the population counter in the top panel. | * This class manages the population counter in the top panel. | ||||
* It flashes the counter if the training of any owned entity is blocked. | * It flashes the counter if the training of any owned entity is blocked. | ||||
*/ | */ | ||||
class CounterPopulation | class CounterPopulation | ||||
{ | { | ||||
constructor(resCode, panel, icon, count) | 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.count.onTick = this.onTick.bind(this); | this.count.onTick = this.onTick.bind(this); | ||||
this.isTrainingBlocked = false; | this.isTrainingBlocked = false; | ||||
this.color = this.DefaultPopulationColor; | this.color = this.DefaultPopulationColor; | ||||
this.stats = stats; | |||||
} | } | ||||
rebuild(playerState, getAllyStatTooltip) | rebuild(playerState, getAllyStatTooltip) | ||||
{ | { | ||||
this.count.caption = sprintf(translate(this.CounterCaption), playerState); | this.count.caption = sprintf(translate(this.CounterCaption), playerState); | ||||
let total = 0; | |||||
for (let resCode of g_ResourceData.GetCodes()) | |||||
total += playerState.resourceGatherers[resCode]; | |||||
// Do not show zeroes. | |||||
this.stats.caption = total || ""; | |||||
this.isTrainingBlocked = playerState.trainingBlocked; | this.isTrainingBlocked = playerState.trainingBlocked; | ||||
this.panel.tooltip = | this.panel.tooltip = | ||||
setStringTags(translate(this.PopulationTooltip), CounterManager.ResourceTitleTags) + "\n" + | setStringTags(translate(this.PopulationTooltip), CounterManager.ResourceTitleTags) + "\n" + | ||||
sprintf(translate(this.MaximumPopulationTooltip), { "popCap": playerState.popMax }) + | sprintf(translate(this.MaximumPopulationTooltip), { "popCap": playerState.popMax }) + | ||||
getAllyStatTooltip(this.getTooltipData.bind(this)); | getAllyStatTooltip(this.getTooltipData.bind(this)) + "\n" + | ||||
(total > 0 ? sprintf(translate("Current gatherers: %(amount)s"), { "amount" : total }) : ""); | |||||
} | } | ||||
getTooltipData(playerState, playername) | getTooltipData(playerState, playername) | ||||
{ | { | ||||
return { | return { | ||||
"playername": playername, | "playername": playername, | ||||
"statValue": sprintf(translate(this.AllyPopulationTooltip), playerState), | "statValue": sprintf(translate(this.AllyPopulationTooltip), playerState), | ||||
"orderValue": playerState.popCount | "orderValue": playerState.popCount | ||||
Show All 33 Lines |
Wildfire Games · Phabricator