0ad/binaries/data/mods/public/gui/maps/mapbrowser/controls/MapDescription.js
wraitii ae9ea5b859 Map browser, used in the gamesetup and in the main menu.
This grid-based system allows browsing all available maps at a glance,
encouraging more diversity and making it nicer to pick a map.

Moves the mapCache and the map filters controller to the gui maps/
folders, and include that folder where it is used, instead of them being
in common/ or the gamesetup.

Comments By: Freagarach
Patch By: Nani (reworked by elexis then wraitii)
Fixes #5315 (though further work, such as proper scrolling, would be
nice).

Differential Revision: https://code.wildfiregames.com/D1703
This was SVN commit r24459.
2020-12-27 15:26:19 +00:00

49 lines
1.5 KiB
JavaScript

MapBrowserPageControls.prototype.MapDescription = class
{
constructor(mapBrowserPage, gridBrowser)
{
this.ImageRatio = 4 / 3;
this.mapBrowserPage = mapBrowserPage;
this.gridBrowser = gridBrowser;
this.mapCache = mapBrowserPage.mapCache;
this.mapBrowserSelectedName = Engine.GetGUIObjectByName("mapBrowserSelectedName");
this.mapBrowserSelectedPreview = Engine.GetGUIObjectByName("mapBrowserSelectedPreview");
this.mapBrowserSelectedDescription = Engine.GetGUIObjectByName("mapBrowserSelectedDescription");
let computedSize = this.mapBrowserSelectedPreview.getComputedSize();
let top = this.mapBrowserSelectedName.size.bottom;
let height = Math.floor((computedSize.right - computedSize.left) / this.ImageRatio);
{
let size = this.mapBrowserSelectedPreview.size;
size.top = top;
size.bottom = top + height;
this.mapBrowserSelectedPreview.size = size;
}
{
let size = this.mapBrowserSelectedDescription.size;
size.top = top + height + 10;
this.mapBrowserSelectedDescription.size = size;
}
gridBrowser.registerSelectionChangeHandler(this.onSelectionChange.bind(this));
}
onSelectionChange()
{
let map = this.gridBrowser.mapList[this.gridBrowser.selected];
if (!map)
return;
this.mapBrowserSelectedName.caption = map ? map.name : "";
this.mapBrowserSelectedDescription.caption = map ? map.description : "";
this.mapBrowserSelectedPreview.sprite =
this.mapCache.getMapPreview(
this.mapBrowserPage.controls.MapFiltering.getSelectedMapType(),
map.file);
}
};