Differential D3243 Diff 16503 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_NewGameSettings.population.watch(() => this.render(), ["useWorldPop", "cap"]); | ||||
{ | g_NewGameSettings.map.watch(() => this.render(), ["type"]); | ||||
g_GameAttributes.settings.PopulationCap = mapValue; | this.render(); | ||||
this.gameSettingsControl.updateGameAttributes(); | |||||
} | } | ||||
let isScenario = g_GameAttributes.mapType == "scenario"; | render() | ||||
{ | |||||
let isScenario = g_NewGameSettings.map.type == "scenario"; | |||||
this.perPlayer = | this.perPlayer = false; | ||||
/* | |||||
isScenario && | isScenario && | ||||
mapData && mapData.settings && mapData.settings.PlayerData && | mapData && mapData.settings && mapData.settings.PlayerData && | ||||
mapData.settings.PlayerData.some(pData => pData && pData.PopulationLimit !== undefined); | mapData.settings.PlayerData.some(pData => pData && pData.PopulationLimit !== undefined); | ||||
*/ | |||||
this.setEnabled(!isScenario && !this.perPlayer); | this.setEnabled(!isScenario && !this.perPlayer); | ||||
this.setHidden(g_NewGameSettings.population.useWorldPop); | |||||
if (!this.perPlayer) | |||||
this.setSelectedValue(g_NewGameSettings.population.cap); | |||||
if (this.perPlayer) | if (this.perPlayer) | ||||
this.label.caption = this.PerPlayerCaption; | this.label.caption = this.PerPlayerCaption; | ||||
} | } | ||||
onGameAttributesChange() | |||||
{ | |||||
if (g_GameAttributes.settings.WorldPopulation) | |||||
{ | |||||
this.setHidden(true); | |||||
g_GameAttributes.settings.PopulationCap = undefined; | |||||
} | |||||
else | |||||
{ | |||||
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_NewGameSettings.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_NewGameSettings.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