Differential D3243 Diff 16537 binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/Single/Dropdowns/PopulationCap.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/Single/Dropdowns/PopulationCap.js
GameSettingControls.PopulationCap = class extends GameSettingControlDropdown | GameSettingControls.PopulationCap = class PopulationCap extends GameSettingControlDropdown | ||||
{ | { | ||||
constructor(...args) | constructor(...args) | ||||
{ | { | ||||
super(...args); | super(...args); | ||||
this.perPlayer = false; | this.perPlayer = false; | ||||
this.dropdown.list = g_PopulationCapacities.Title; | this.dropdown.list = g_PopulationCapacities.Title; | ||||
this.dropdown.list_data = g_PopulationCapacities.Population; | this.dropdown.list_data = g_PopulationCapacities.Population; | ||||
this.sprintfArgs = {}; | this.sprintfArgs = {}; | ||||
} | |||||
onMapChange(mapData) | |||||
{ | |||||
let mapValue; | |||||
if (mapData && | |||||
mapData.settings && | |||||
mapData.settings.PopulationCap !== undefined) | |||||
mapValue = mapData.settings.PopulationCap; | |||||
if (mapValue !== undefined && mapValue != g_GameAttributes.settings.PopulationCap) | |||||
{ | |||||
g_GameAttributes.settings.PopulationCap = mapValue; | |||||
this.gameSettingsControl.updateGameAttributes(); | |||||
} | |||||
let isScenario = g_GameAttributes.mapType == "scenario"; | |||||
this.perPlayer = | |||||
isScenario && | |||||
mapData && mapData.settings && mapData.settings.PlayerData && | |||||
mapData.settings.PlayerData.some(pData => pData && pData.PopulationLimit !== undefined); | |||||
this.setEnabled(!isScenario && !this.perPlayer); | g_GameSettings.population.watch(() => this.render(), ["useWorldPop", "cap", "perPlayer"]); | ||||
g_GameSettings.map.watch(() => this.render(), ["type"]); | |||||
if (this.perPlayer) | this.render(); | ||||
this.label.caption = this.PerPlayerCaption; | |||||
} | } | ||||
onGameAttributesChange() | render() | ||||
{ | { | ||||
if (g_GameAttributes.settings.WorldPopulation) | this.setHidden(g_GameSettings.population.useWorldPop); | ||||
{ | this.setEnabled(!g_GameSettings.map.type == "scenario" && !g_GameSettings.population.perPlayer); | ||||
this.setHidden(true); | if (g_GameSettings.population.perPlayer) | ||||
g_GameAttributes.settings.PopulationCap = undefined; | this.label.caption = this.PerPlayerCaption; | ||||
} | |||||
else | else | ||||
{ | this.setSelectedValue(g_GameSettings.population.cap); | ||||
this.setHidden(false); | |||||
if (g_GameAttributes.settings.PopulationCap === undefined) | |||||
{ | |||||
g_GameAttributes.settings.PopulationCap = g_PopulationCapacities.Population[g_PopulationCapacities.Default]; | |||||
this.gameSettingsControl.updateGameAttributes(); | |||||
} | |||||
} | |||||
} | |||||
onGameAttributesBatchChange() | |||||
{ | |||||
if (!this.perPlayer) | |||||
this.setSelectedValue(g_GameAttributes.settings.PopulationCap); | |||||
} | } | ||||
onHoverChange() | onHoverChange() | ||||
{ | { | ||||
let tooltip = this.Tooltip; | let tooltip = this.Tooltip; | ||||
if (this.dropdown.hovered != -1) | if (this.dropdown.hovered != -1) | ||||
{ | { | ||||
let popCap = g_PopulationCapacities.Population[this.dropdown.hovered]; | let popCap = g_PopulationCapacities.Population[this.dropdown.hovered]; | ||||
let players = g_GameAttributes.settings.PlayerData.length; | let players = g_GameSettings.playerCount.nbPlayers; | ||||
if (popCap * players >= this.PopulationCapacityRecommendation) | if (popCap * players >= this.PopulationCapacityRecommendation) | ||||
{ | { | ||||
this.sprintfArgs.players = players; | this.sprintfArgs.players = players; | ||||
this.sprintfArgs.popCap = popCap; | this.sprintfArgs.popCap = popCap; | ||||
tooltip = setStringTags(sprintf(this.HoverTooltip, this.sprintfArgs), this.HoverTags); | tooltip = setStringTags(sprintf(this.HoverTooltip, this.sprintfArgs), this.HoverTags); | ||||
} | } | ||||
} | } | ||||
this.dropdown.tooltip = tooltip; | this.dropdown.tooltip = tooltip; | ||||
} | } | ||||
onSelectionChange(itemIdx) | onSelectionChange(itemIdx) | ||||
{ | { | ||||
g_GameAttributes.settings.PopulationCap = g_PopulationCapacities.Population[itemIdx]; | g_GameSettings.population.setPopCap(false, g_PopulationCapacities.Population[itemIdx]); | ||||
this.gameSettingsControl.updateGameAttributes(); | |||||
this.gameSettingsControl.setNetworkGameAttributes(); | this.gameSettingsControl.setNetworkGameAttributes(); | ||||
} | } | ||||
}; | }; | ||||
GameSettingControls.PopulationCap.prototype.TitleCaption = | GameSettingControls.PopulationCap.prototype.TitleCaption = | ||||
translate("Population Cap"); | translate("Population Cap"); | ||||
GameSettingControls.PopulationCap.prototype.Tooltip = | GameSettingControls.PopulationCap.prototype.Tooltip = | ||||
Show All 17 Lines |
Wildfire Games · Phabricator