Differential D1703 Diff 11331 binaries/data/mods/public/gui/gamesetup/Pages/MapBrowserPage/Controls/MapGridBrowser.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/gamesetup/Pages/MapBrowserPage/Controls/MapGridBrowser.js
- This file was added.
MapBrowserPageControls.MapGridBrowser = class extends GridBrowser | |||||
{ | |||||
constructor(mapBrowserPage, setupWindow) | |||||
{ | |||||
super(Engine.GetGUIObjectByName("mapBrowserContainer")); | |||||
this.setupWindow = setupWindow; | |||||
this.mapBrowserPage = mapBrowserPage; | |||||
this.mapCache = setupWindow.controls.mapCache; | |||||
this.mapFilters = setupWindow.controls.mapFilters; | |||||
this.mapList = []; | |||||
this.items = this.container.children.map((imageObject, itemIndex) => | |||||
new MapGridBrowserItem(mapBrowserPage, this, imageObject, itemIndex)); | |||||
this.container.tooltip = | |||||
colorizeHotkey(this.TooltipPrevious, this.HotkeyConfigPrevious) + "\n" + | |||||
colorizeHotkey(this.TooltipNext, this.HotkeyConfigNext); | |||||
this.mapBrowserPage.registerOpenPageHandler(this.onOpenPage.bind(this)); | |||||
this.mapBrowserPage.registerClosePageHandler(this.onClosePage.bind(this)); | |||||
this.mapBrowserPage.mapBrowserPageDialog.onMouseWheelUp = this.nextPage.bind(this); | |||||
this.mapBrowserPage.mapBrowserPageDialog.onMouseWheelDown = this.previousPage.bind(this); | |||||
} | |||||
onOpenPage() | |||||
{ | |||||
this.updateMapList(); | |||||
this.setSelectedIndex(this.mapList.findIndex(map => map.file == g_GameAttributes.map)); | |||||
this.goToPageOfSelected(); | |||||
this.container.onWindowResized = this.onWindowResized.bind(this); | |||||
Engine.SetGlobalHotkey(this.HotkeyConfigNext, this.nextPage.bind(this)); | |||||
Engine.SetGlobalHotkey(this.HotkeyConfigPrevious, this.previousPage.bind(this)); | |||||
} | |||||
onClosePage() | |||||
{ | |||||
delete this.container.onWindowResized; | |||||
Engine.UnsetGlobalHotkey(this.HotkeyConfigNext); | |||||
Engine.UnsetGlobalHotkey(this.HotkeyConfigPrevious); | |||||
} | |||||
updateMapList() | |||||
{ | |||||
let selectedMap = | |||||
this.mapList[this.selected] && | |||||
this.mapList[this.selected].file || undefined; | |||||
let mapList = this.mapFilters.getFilteredMaps( | |||||
this.mapBrowserPage.controls.MapType.getSelected(), | |||||
this.mapBrowserPage.controls.MapFilter.getSelected()); | |||||
let filterText = this.mapBrowserPage.controls.SearchBox.getFilterText(); | |||||
if (filterText) | |||||
{ | |||||
mapList = MatchSort.get(filterText, mapList, "name"); | |||||
if (!mapList.length) | |||||
{ | |||||
let filter = "all"; | |||||
for (let type of g_MapTypes.Name) | |||||
for (let map of this.mapFilters.getFilteredMaps(type, filter)) | |||||
mapList.push(Object.assign({ "type": type, "filter": filter }, map)); | |||||
mapList = MatchSort.get(filterText, mapList, "name"); | |||||
} | |||||
} | |||||
this.mapList = mapList; | |||||
this.itemCount = this.mapList.length; | |||||
this.resizeGrid(); | |||||
this.setSelectedIndex(this.mapList.findIndex(map => map.file == selectedMap)); | |||||
} | |||||
submitMapSelection() | |||||
{ | |||||
if (!g_IsController) | |||||
return; | |||||
let map = this.mapList[this.selected] || undefined; | |||||
if (!map) | |||||
return; | |||||
g_GameAttributes.mapType = map.type ? map.type : | |||||
this.mapBrowserPage.controls.MapType.getSelected(); | |||||
g_GameAttributes.mapFilter = map.filter ? map.filter : | |||||
this.mapBrowserPage.controls.MapFilter.getSelected(); | |||||
g_GameAttributes.map = map.file; | |||||
this.setupWindow.controls.gameSettingsControl.updateGameAttributes(); | |||||
} | |||||
}; | |||||
MapBrowserPageControls.MapGridBrowser.prototype.ItemRatio = 4 / 3; | |||||
MapBrowserPageControls.MapGridBrowser.prototype.DefaultItemWidth = 200; | |||||
MapBrowserPageControls.MapGridBrowser.prototype.MinItemWidth = 100; | |||||
MapBrowserPageControls.MapGridBrowser.prototype.HotkeyConfigNext = | |||||
"tab.next"; | |||||
MapBrowserPageControls.MapGridBrowser.prototype.HotkeyConfigPrevious = | |||||
"tab.prev"; | |||||
MapBrowserPageControls.MapGridBrowser.prototype.TooltipNext = | |||||
translate("%(hotkey)s: Go to the next page."); | |||||
MapBrowserPageControls.MapGridBrowser.prototype.TooltipPrevious = | |||||
translate("%(hotkey)s: Go to the previous page."); |
Wildfire Games · Phabricator