0ad/binaries/data/mods/public/gui/maps/mapbrowser/controls/MapDescription.js
Vantha fd847c2a23
Refactor GUI object resizing JS code passages
It is possible to modify sizes by setting the properties directly.
(Without having to create a copy of it)
This allows to shorten those passages quite a bit without any functional change.
2025-06-17 12:57:37 -05:00

40 lines
1.4 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");
const computedSize = this.mapBrowserSelectedPreview.getComputedSize();
const top = this.mapBrowserSelectedName.size.bottom;
const height = Math.floor((computedSize.right - computedSize.left) / this.ImageRatio);
this.mapBrowserSelectedPreview.size.top = top;
this.mapBrowserSelectedPreview.size.bottom = top + height;
this.mapBrowserSelectedDescription.size.top = top + height + 10;
gridBrowser.registerSelectionChangeHandler(this.onSelectionChange.bind(this));
}
onSelectionChange()
{
const 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);
}
};