Differential D3243 Diff 16503 binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/Single/Dropdowns/MapSelection.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/Single/Dropdowns/MapSelection.js
GameSettingControls.MapSelection = class extends GameSettingControlDropdown | GameSettingControls.MapSelection = class MapSelection extends GameSettingControlDropdown | ||||
{ | { | ||||
constructor(...args) | constructor(...args) | ||||
{ | { | ||||
super(...args); | super(...args); | ||||
this.values = undefined; | this.values = undefined; | ||||
this.previousMapType = undefined; | // TODO: change this? | ||||
this.previousMapFilter = undefined; | g_NewGameSettings.map.mapCache = this.gameSettingsControl.mapCache; | ||||
g_NewGameSettings.map.watch(() => this.render(), ["map"]); | |||||
g_NewGameSettings.map.watch(() => this.updateMapList(), ["type"]); | |||||
this.gameSettingsControl.guiData.mapFilter.watch(() => this.updateMapList(), ["filter"]); | |||||
this.randomItem = { | this.randomItem = { | ||||
"file": this.RandomMapId, | "file": this.RandomMapId, | ||||
"name": setStringTags(this.RandomMapCaption, this.RandomItemTags), | "name": setStringTags(this.RandomMapCaption, this.RandomItemTags), | ||||
"description": this.RandomMapDescription | "description": this.RandomMapDescription | ||||
}; | }; | ||||
} | } | ||||
onHoverChange() | onHoverChange() | ||||
{ | { | ||||
this.dropdown.tooltip = this.values.description[this.dropdown.hovered] || this.Tooltip; | this.dropdown.tooltip = this.values.description[this.dropdown.hovered] || this.Tooltip; | ||||
} | } | ||||
onGameAttributesChange() | render() | ||||
{ | { | ||||
if (!g_GameAttributes.mapType || !g_GameAttributes.mapFilter) | // Can happen with bad matchsettings | ||||
return; | if (this.values.file.indexOf(g_NewGameSettings.map.map) === -1) | ||||
this.updateMapList(); | |||||
if (!this.gameSettingsControl.autostart && | |||||
this.values && | |||||
this.values.file.indexOf(g_GameAttributes.map || undefined) == -1) | |||||
{ | { | ||||
g_GameAttributes.map = this.values.file[0]; | g_NewGameSettings.map.selectMap(this.values.file[this.values.Default]); | ||||
this.gameSettingsControl.updateGameAttributes(); | return; | ||||
} | |||||
} | } | ||||
this.setSelectedValue(g_NewGameSettings.map.map); | |||||
onGameAttributesBatchChange() | |||||
{ | |||||
if (g_GameAttributes.map) | |||||
this.setSelectedValue(g_GameAttributes.map); | |||||
} | } | ||||
updateMapList() | updateMapList() | ||||
{ | { | ||||
if (this.previousMapType && | |||||
this.previousMapType == g_GameAttributes.mapType && | |||||
this.previousMapFilter && | |||||
this.previousMapFilter == g_GameAttributes.mapFilter) | |||||
return; | |||||
Engine.ProfileStart("updateMapSelectionList"); | Engine.ProfileStart("updateMapSelectionList"); | ||||
this.previousMapType = g_GameAttributes.mapType; | if (!g_NewGameSettings.map.type) | ||||
this.previousMapFilter = g_GameAttributes.mapFilter; | return; | ||||
{ | { | ||||
let values = | let values = | ||||
this.mapFilters.getFilteredMaps( | this.mapFilters.getFilteredMaps( | ||||
g_GameAttributes.mapType, | g_NewGameSettings.map.type, | ||||
g_GameAttributes.mapFilter, | this.gameSettingsControl.guiData.mapFilter.filter, | ||||
false); | false); | ||||
values.sort(sortNameIgnoreCase); | values.sort(sortNameIgnoreCase); | ||||
if (g_GameAttributes.mapType == "random") | if (g_NewGameSettings.map.type == "random") | ||||
values.unshift(this.randomItem); | values.unshift(this.randomItem); | ||||
this.values = prepareForDropdown(values); | this.values = prepareForDropdown(values); | ||||
} | } | ||||
this.dropdown.list = this.values.name; | this.dropdown.list = this.values.name; | ||||
this.dropdown.list_data = this.values.file; | this.dropdown.list_data = this.values.file; | ||||
Engine.ProfileStop(); | |||||
} | |||||
onSelectionChange(itemIdx) | g_NewGameSettings.map.setRandomOptions(this.values.file); | ||||
// Reset the selected map. | |||||
if (this.values.file.indexOf(g_NewGameSettings.map.map) === -1) | |||||
{ | { | ||||
this.selectMap(this.values.file[itemIdx]); | g_NewGameSettings.map.selectMap(this.values.file[this.values.Default]); | ||||
this.gameSettingsControl.setNetworkGameAttributes(); | this.gameSettingsControl.setNetworkGameAttributes(); | ||||
} | } | ||||
// The index may have changed: reset. | |||||
/** | this.setSelectedValue(g_NewGameSettings.map.map); | ||||
* @param mapPath - for example "maps/skirmishes/Acropolis Bay (2)" | |||||
*/ | |||||
selectMap(mapPath) | |||||
{ | |||||
if (g_GameAttributes.map == mapPath) | |||||
return; | |||||
Engine.ProfileStart("selectMap"); | |||||
// For scenario map, reset every setting per map selection | |||||
// For skirmish and random maps, persist player choices | |||||
if (g_GameAttributes.mapType == "scenario") | |||||
g_GameAttributes = { | |||||
"mapType": g_GameAttributes.mapType, | |||||
"mapFilter": g_GameAttributes.mapFilter | |||||
}; | |||||
g_GameAttributes.map = mapPath; | |||||
this.gameSettingsControl.updateGameAttributes(); | |||||
Engine.ProfileStop(); | Engine.ProfileStop(); | ||||
} | } | ||||
getAutocompleteEntries() | onSelectionChange(itemIdx) | ||||
{ | |||||
return this.values.name; | |||||
} | |||||
onPickRandomItems() | |||||
{ | |||||
if (g_GameAttributes.map == this.RandomMapId) | |||||
{ | { | ||||
this.selectMap(pickRandom(this.values.file.slice(1))); | // The triggering that happens on map change can be just slow enough | ||||
this.gameSettingsControl.pickRandomItems(); | // that the next event happens before we're done when scrolling, | ||||
} | // and then the scrolling is not smooth since it can take arbitrarily long to render. | ||||
// To avoid that, run the change on the next GUI tick, and only do one increment. | |||||
// TODO: the problem is mostly that updating visibility can relayout the gamesetting, | |||||
// which takes a few ms, but this could only be done once per frame anyways. | |||||
// NB: this technically makes it possible to start the game without the change going through | |||||
// but it's essentially impossible to trigger accidentally. | |||||
if (this.reRenderTimeout) | |||||
clearTimeout(this.reRenderTimeout); | |||||
this.reRenderTimeout = setTimeout(() => { | |||||
g_NewGameSettings.map.selectMap(this.values.file[itemIdx]); | |||||
this.gameSettingsControl.setNetworkGameAttributes(); | |||||
}, 0); | |||||
} | } | ||||
onGameAttributesFinalize() | getAutocompleteEntries() | ||||
{ | { | ||||
// Copy map well known properties (and only well known properties) | return this.values.name; | ||||
let mapData = this.mapCache.getMapData(g_GameAttributes.mapType, g_GameAttributes.map); | |||||
if (g_GameAttributes.mapType == "random") | |||||
g_GameAttributes.script = mapData.settings.Script; | |||||
g_GameAttributes.settings.TriggerScripts = Array.from(new Set([ | |||||
...(g_GameAttributes.settings.TriggerScripts || []), | |||||
...(mapData.settings.TriggerScripts || []) | |||||
])); | |||||
for (let property of this.MapSettings) | |||||
if (mapData.settings[property] !== undefined) | |||||
g_GameAttributes.settings[property] = mapData.settings[property]; | |||||
} | } | ||||
}; | }; | ||||
GameSettingControls.MapSelection.prototype.TitleCaption = | GameSettingControls.MapSelection.prototype.TitleCaption = | ||||
translate("Select Map"); | translate("Select Map"); | ||||
GameSettingControls.MapSelection.prototype.Tooltip = | GameSettingControls.MapSelection.prototype.Tooltip = | ||||
translate("Select a map to play on."); | translate("Select a map to play on."); | ||||
GameSettingControls.MapSelection.prototype.RandomMapId = | GameSettingControls.MapSelection.prototype.RandomMapId = | ||||
"random"; | "random"; | ||||
GameSettingControls.MapSelection.prototype.RandomMapCaption = | GameSettingControls.MapSelection.prototype.RandomMapCaption = | ||||
translateWithContext("map selection", "Random"); | translateWithContext("map selection", "Random"); | ||||
GameSettingControls.MapSelection.prototype.RandomMapDescription = | GameSettingControls.MapSelection.prototype.RandomMapDescription = | ||||
translate("Pick any of the given maps at random."); | translate("Pick any of the given maps at random."); | ||||
GameSettingControls.MapSelection.prototype.AutocompleteOrder = 0; | GameSettingControls.MapSelection.prototype.AutocompleteOrder = 0; | ||||
GameSettingControls.MapSelection.prototype.MapSettings = [ | |||||
"CircularMap", | |||||
"StartingTechnologies", | |||||
"DisabledTechnologies", | |||||
"DisabledTemplates", | |||||
"StartingCamera", | |||||
"Garrison", | |||||
// Copy the map name so that the replay menu doesn't have to load hundreds of map descriptions on init | |||||
// Also it allows determining the english mapname from the replay file if the map is not available. | |||||
"Name" | |||||
]; |
Wildfire Games · Phabricator