Map browser fixes and improvements
- 'Random' map is filtered correctly
- When in 'fallback to all' mode, selecting something works (#6165).
- Fix hotkeys being broken (fixes map browser following 0406c4dfde
)
- Clear filters when reopening the map browser (seems natural).
Based on a patch by: nani
Refs #6045.
Fixes #6165.
Differential Revision: https://code.wildfiregames.com/D3833
This was SVN commit r25379.
This commit is contained in:
parent
2e08fd38ea
commit
fe3ff1b0ff
@ -66,7 +66,10 @@ class MapFilters
|
||||
maps.push({
|
||||
"file": mapPath,
|
||||
"name": translate(mapData.settings.Name),
|
||||
"description": translate(mapData.settings.Description)
|
||||
"description": translate(mapData.settings.Description),
|
||||
// For convenience when filtering, store which type/filter tuple returned this map.
|
||||
"mapType": mapTypeName,
|
||||
"filter": filterName
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -19,10 +19,19 @@ class MapBrowser
|
||||
|
||||
submitMapSelection()
|
||||
{
|
||||
let file = this.gridBrowser.getSelected();
|
||||
let type = this.controls.MapFiltering.getSelectedMapType();
|
||||
let filter = this.controls.MapFiltering.getSelectedMapFilter();
|
||||
if (file)
|
||||
{
|
||||
type = file.mapType;
|
||||
filter = file.filter;
|
||||
file = file.file;
|
||||
}
|
||||
this.onSubmitMapSelection(
|
||||
this.gridBrowser.getSelectedFile(),
|
||||
this.controls.MapFiltering.getSelectedMapType(),
|
||||
this.controls.MapFiltering.getSelectedMapFilter()
|
||||
file,
|
||||
type,
|
||||
filter
|
||||
);
|
||||
this.closePage();
|
||||
}
|
||||
|
@ -22,7 +22,10 @@ MapBrowserPageControls.prototype.MapFiltering = class
|
||||
onOpenPage()
|
||||
{
|
||||
// setTimeout avoids having the hotkey key inserted into the input text.
|
||||
setTimeout(() => this.searchBox.focus(), 0);
|
||||
setTimeout(() => {
|
||||
this.searchBox.control.caption = "";
|
||||
this.searchBox.focus();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
onClosePage()
|
||||
|
@ -37,9 +37,9 @@ class MapGridBrowser extends GridBrowser
|
||||
Engine.UnsetGlobalHotkey(this.HotkeyConfigPrevious, "Press");
|
||||
}
|
||||
|
||||
getSelectedFile()
|
||||
getSelected()
|
||||
{
|
||||
return this.mapList[this.selected].file || undefined;
|
||||
return this.mapList[this.selected] || undefined;
|
||||
}
|
||||
|
||||
select(mapFile)
|
||||
@ -50,35 +50,36 @@ class MapGridBrowser extends GridBrowser
|
||||
|
||||
updateMapList()
|
||||
{
|
||||
let selectedMap =
|
||||
this.mapList[this.selected] &&
|
||||
this.mapList[this.selected].file || undefined;
|
||||
const selectedMap = this.mapList[this.selected]?.file;
|
||||
const mapType = this.mapBrowserPage.controls.MapFiltering.getSelectedMapType();
|
||||
const mapFilter = this.mapBrowserPage.controls.MapFiltering.getSelectedMapFilter();
|
||||
const filterText = this.mapBrowserPage.controls.MapFiltering.getSearchText();
|
||||
const randomMap = {
|
||||
"file": "random",
|
||||
"name": translateWithContext("map selection", "Random"),
|
||||
"description": translate("Pick a map at random."),
|
||||
"mapType": "random",
|
||||
"filter": "default"
|
||||
};
|
||||
|
||||
let mapList = this.mapFilters.getFilteredMaps(
|
||||
this.mapBrowserPage.controls.MapFiltering.getSelectedMapType(),
|
||||
this.mapBrowserPage.controls.MapFiltering.getSelectedMapFilter());
|
||||
let mapList = this.mapFilters.getFilteredMaps(mapType, mapFilter);
|
||||
|
||||
if (mapType === "random")
|
||||
mapList.unshift(randomMap);
|
||||
|
||||
let filterText = this.mapBrowserPage.controls.MapFiltering.getSearchText();
|
||||
if (filterText)
|
||||
{
|
||||
mapList = MatchSort.get(filterText, mapList, "name");
|
||||
if (!mapList.length)
|
||||
{
|
||||
let filter = "all";
|
||||
const filter = "all";
|
||||
mapList.push(randomMap);
|
||||
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");
|
||||
}
|
||||
}
|
||||
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.itemCount = this.mapList.length;
|
||||
this.resizeGrid();
|
||||
@ -92,3 +93,7 @@ MapGridBrowser.prototype.ItemRatio = 4 / 3;
|
||||
MapGridBrowser.prototype.DefaultItemWidth = 200;
|
||||
|
||||
MapGridBrowser.prototype.MinItemWidth = 100;
|
||||
|
||||
MapGridBrowser.prototype.HotkeyConfigNext = "tab.next";
|
||||
|
||||
MapGridBrowser.prototype.HotkeyConfigPrevious = "tab.prev";
|
||||
|
Loading…
Reference in New Issue
Block a user