Differential D3243 Diff 16503 binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/Single/Dropdowns/StartingResources.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/Single/Dropdowns/StartingResources.js
GameSettingControls.StartingResources = class extends GameSettingControlDropdown | GameSettingControls.StartingResources = class StartingResources extends GameSettingControlDropdown | ||||
{ | { | ||||
constructor(...args) | constructor(...args) | ||||
{ | { | ||||
super(...args); | super(...args); | ||||
this.dropdown.list = g_StartingResources.Title; | this.dropdown.list = g_StartingResources.Title; | ||||
this.dropdown.list_data = g_StartingResources.Resources; | this.dropdown.list_data = g_StartingResources.Resources; | ||||
this.perPlayer = false; | |||||
this.sprintfArgs = {}; | this.sprintfArgs = {}; | ||||
g_NewGameSettings.startingResources.watch(() => this.render(), ["resources"]); | |||||
g_NewGameSettings.map.watch(() => this.render(), ["type"]); | |||||
this.render(); | |||||
} | } | ||||
onHoverChange() | onHoverChange() | ||||
{ | { | ||||
let tooltip = this.Tooltip; | let tooltip = this.Tooltip; | ||||
if (this.dropdown.hovered != -1) | if (this.dropdown.hovered != -1) | ||||
{ | { | ||||
this.sprintfArgs.resources = g_StartingResources.Resources[this.dropdown.hovered]; | this.sprintfArgs.resources = g_StartingResources.Resources[this.dropdown.hovered]; | ||||
tooltip = sprintf(this.HoverTooltip, this.sprintfArgs); | tooltip = sprintf(this.HoverTooltip, this.sprintfArgs); | ||||
} | } | ||||
this.dropdown.tooltip = tooltip; | this.dropdown.tooltip = tooltip; | ||||
} | } | ||||
onMapChange(mapData) | render() | ||||
{ | |||||
let mapValue; | |||||
if (mapData && | |||||
mapData.settings && | |||||
mapData.settings.StartingResources !== undefined) | |||||
mapValue = mapData.settings.StartingResources; | |||||
if (mapValue !== undefined && mapValue != g_GameAttributes.settings.StartingResources) | |||||
{ | { | ||||
g_GameAttributes.settings.StartingResources = mapValue; | this.setEnabled(g_NewGameSettings.map.type != "scenario"); | ||||
this.gameSettingsControl.updateGameAttributes(); | this.setSelectedValue(g_NewGameSettings.startingResources.resources); | ||||
} | |||||
let isScenario = g_GameAttributes.mapType == "scenario"; | |||||
this.perPlayer = | |||||
isScenario && | |||||
mapData && mapData.settings && mapData.settings.PlayerData && | |||||
mapData.settings.PlayerData.some(pData => pData && pData.Resources !== undefined); | |||||
this.setEnabled(!isScenario && !this.perPlayer); | |||||
if (this.perPlayer) | |||||
this.label.caption = this.PerPlayerCaption; | |||||
} | |||||
onGameAttributesChange() | |||||
{ | |||||
if (g_GameAttributes.settings.StartingResources === undefined) | |||||
{ | |||||
g_GameAttributes.settings.StartingResources = | |||||
g_StartingResources.Resources[g_StartingResources.Default]; | |||||
this.gameSettingsControl.updateGameAttributes(); | |||||
} | |||||
} | |||||
onGameAttributesBatchChange() | |||||
{ | |||||
if (!this.perPlayer) | |||||
this.setSelectedValue(g_GameAttributes.settings.StartingResources); | |||||
} | } | ||||
getAutocompleteEntries() | getAutocompleteEntries() | ||||
{ | { | ||||
return g_StartingResources.Title; | return g_StartingResources.Title; | ||||
} | } | ||||
onSelectionChange(itemIdx) | onSelectionChange(itemIdx) | ||||
{ | { | ||||
g_GameAttributes.settings.StartingResources = g_StartingResources.Resources[itemIdx]; | g_NewGameSettings.startingResources.setResources(g_StartingResources.Resources[itemIdx]); | ||||
this.gameSettingsControl.updateGameAttributes(); | |||||
this.gameSettingsControl.setNetworkGameAttributes(); | this.gameSettingsControl.setNetworkGameAttributes(); | ||||
} | } | ||||
}; | }; | ||||
GameSettingControls.StartingResources.prototype.TitleCaption = | GameSettingControls.StartingResources.prototype.TitleCaption = | ||||
translate("Starting Resources"); | translate("Starting Resources"); | ||||
GameSettingControls.StartingResources.prototype.Tooltip = | GameSettingControls.StartingResources.prototype.Tooltip = | ||||
translate("Select the game's starting resources."); | translate("Select the game's starting resources."); | ||||
GameSettingControls.StartingResources.prototype.HoverTooltip = | GameSettingControls.StartingResources.prototype.HoverTooltip = | ||||
translate("Initial amount of each resource: %(resources)s."); | translate("Initial amount of each resource: %(resources)s."); | ||||
GameSettingControls.StartingResources.prototype.PerPlayerCaption = | |||||
translateWithContext("starting resources", "Per Player"); | |||||
GameSettingControls.StartingResources.prototype.AutocompleteOrder = 0; | GameSettingControls.StartingResources.prototype.AutocompleteOrder = 0; |
Wildfire Games · Phabricator