Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/maps/mapbrowser/grid/MapGridBrowser.js
Show All 31 Lines | class MapGridBrowser extends GridBrowser | ||||
onClosePage() | onClosePage() | ||||
{ | { | ||||
delete this.container.onWindowResized; | delete this.container.onWindowResized; | ||||
Engine.UnsetGlobalHotkey(this.HotkeyConfigNext, "Press"); | Engine.UnsetGlobalHotkey(this.HotkeyConfigNext, "Press"); | ||||
Engine.UnsetGlobalHotkey(this.HotkeyConfigPrevious, "Press"); | Engine.UnsetGlobalHotkey(this.HotkeyConfigPrevious, "Press"); | ||||
} | } | ||||
getSelectedFile() | getSelected() | ||||
{ | { | ||||
return this.mapList[this.selected].file || undefined; | return this.mapList[this.selected] || undefined; | ||||
} | } | ||||
select(mapFile) | select(mapFile) | ||||
{ | { | ||||
this.setSelectedIndex(this.mapList.findIndex(map => map.file == mapFile)); | this.setSelectedIndex(this.mapList.findIndex(map => map.file == mapFile)); | ||||
this.goToPageOfSelected(); | this.goToPageOfSelected(); | ||||
} | } | ||||
updateMapList() | updateMapList() | ||||
{ | { | ||||
let selectedMap = | const selectedMap = this.mapList[this.selected]?.file; | ||||
this.mapList[this.selected] && | const mapType = this.mapBrowserPage.controls.MapFiltering.getSelectedMapType(); | ||||
this.mapList[this.selected].file || undefined; | const mapFilter = this.mapBrowserPage.controls.MapFiltering.getSelectedMapFilter(); | ||||
const filterText = this.mapBrowserPage.controls.MapFiltering.getSearchText(); | |||||
let mapList = this.mapFilters.getFilteredMaps( | const randomMap = { | ||||
this.mapBrowserPage.controls.MapFiltering.getSelectedMapType(), | "file": "random", | ||||
this.mapBrowserPage.controls.MapFiltering.getSelectedMapFilter()); | "name": translate("Random"), | ||||
Stan: You might want translate with context here. Single words might not get translated properly… | |||||
"description": translate("Pick a map at random."), | |||||
"mapType": "random", | |||||
"filter": "default" | |||||
}; | |||||
let mapList = this.mapFilters.getFilteredMaps(mapType, mapFilter); | |||||
if (mapType === "random") | |||||
mapList.unshift(randomMap); | |||||
let filterText = this.mapBrowserPage.controls.MapFiltering.getSearchText(); | |||||
if (filterText) | if (filterText) | ||||
{ | { | ||||
mapList = MatchSort.get(filterText, mapList, "name"); | mapList = MatchSort.get(filterText, mapList, "name"); | ||||
if (!mapList.length) | if (!mapList.length) | ||||
{ | { | ||||
let filter = "all"; | const filter = "all"; | ||||
mapList.push(randomMap); | |||||
for (let type of g_MapTypes.Name) | for (let type of g_MapTypes.Name) | ||||
for (let map of this.mapFilters.getFilteredMaps(type, filter)) | for (let map of this.mapFilters.getFilteredMaps(type, filter)) | ||||
mapList.push(Object.assign({ "type": type, "filter": filter }, map)); | mapList.push(Object.assign({ "type": type, "filter": filter }, map)); | ||||
mapList = MatchSort.get(filterText, mapList, "name"); | mapList = MatchSort.get(filterText, mapList, "name"); | ||||
} | } | ||||
} | } | ||||
if (this.mapBrowserPage.controls.MapFiltering.getSelectedMapType() == "random") | |||||
{ | |||||
mapList = [{ | |||||
"file": "random", | |||||
"name": translateWithContext("random map pick", "Random"), | |||||
"description": translate("Pick a map at random."), | |||||
}, ...mapList]; | |||||
} | |||||
this.mapList = mapList; | this.mapList = mapList; | ||||
this.itemCount = this.mapList.length; | this.itemCount = this.mapList.length; | ||||
this.resizeGrid(); | this.resizeGrid(); | ||||
this.setSelectedIndex(this.mapList.findIndex(map => map.file == selectedMap)); | this.setSelectedIndex(this.mapList.findIndex(map => map.file == selectedMap)); | ||||
} | } | ||||
} | } | ||||
MapGridBrowser.prototype.ItemRatio = 4 / 3; | MapGridBrowser.prototype.ItemRatio = 4 / 3; | ||||
MapGridBrowser.prototype.DefaultItemWidth = 200; | MapGridBrowser.prototype.DefaultItemWidth = 200; | ||||
MapGridBrowser.prototype.MinItemWidth = 100; | MapGridBrowser.prototype.MinItemWidth = 100; | ||||
MapGridBrowser.prototype.HotkeyConfigNext = "tab.next"; | |||||
MapGridBrowser.prototype.HotkeyConfigPrevious = "tab.prev"; |
Wildfire Games · Phabricator
You might want translate with context here. Single words might not get translated properly without proper context.