0ad/binaries/data/mods/public/gui/maps/mapbrowser/controls/MapBrowserControls.js
Dunedan fc7e4ae69e
Small UI adjustments for better text fitting
When running 0ad with a language other than English, there are various
places where text doesn't properly fit. This adjusts the UI in a bunch
of these places to better accommodate longer strings as they appear in
other languages than English and to make the UI look more uniform in
general.
2024-12-28 08:52:13 +01:00

83 lines
2.7 KiB
JavaScript

class MapBrowserPageControls
{
constructor(mapBrowserPage, gridBrowser)
{
for (let name in this)
this[name] = new this[name](mapBrowserPage, gridBrowser);
this.mapBrowserPage = mapBrowserPage;
this.gridBrowser = gridBrowser;
this.setupButtons();
const alignmentHelper = new AlignmentHelper("max");
const labelMargin = 5;
this.mapBrowserSearchBoxLabel = Engine.GetGUIObjectByName("mapBrowserSearchBoxLabel");
this.mapBrowserSearchBoxControl = Engine.GetGUIObjectByName("mapBrowserSearchBoxControl");
alignmentHelper.setObject(this.mapBrowserSearchBoxControl, "left", this.mapBrowserSearchBoxLabel.size.right + labelMargin);
this.mapBrowserMapTypeLabel = Engine.GetGUIObjectByName("mapBrowserMapTypeLabel");
this.mapBrowserMapTypeControl = Engine.GetGUIObjectByName("mapBrowserMapTypeControl");
alignmentHelper.setObject(this.mapBrowserMapTypeControl, "left", this.mapBrowserMapTypeLabel.size.right + labelMargin);
this.mapBrowserMapFilterLabel = Engine.GetGUIObjectByName("mapBrowserMapFilterLabel");
this.mapBrowserMapFilterControl = Engine.GetGUIObjectByName("mapBrowserMapFilterControl");
alignmentHelper.setObject(this.mapBrowserMapFilterControl, "left", this.mapBrowserMapFilterLabel.size.right + labelMargin);
}
setupButtons()
{
this.pickRandom = Engine.GetGUIObjectByName("mapBrowserPagePickRandom");
this.pickRandom.onPress = () => {
let index = randIntInclusive(0, this.gridBrowser.itemCount - 1);
this.gridBrowser.setSelectedIndex(index);
this.gridBrowser.goToPageOfSelected();
};
this.select = Engine.GetGUIObjectByName("mapBrowserPageSelect");
this.select.onPress = () => this.onSelect();
this.close = Engine.GetGUIObjectByName("mapBrowserPageClose");
this.close.onPress = () => this.mapBrowserPage.closePage();
this.mapBrowserPage.registerOpenPageHandler(this.onOpenPage.bind(this));
this.gridBrowser.registerSelectionChangeHandler(() => this.onSelectionChange());
}
onOpenPage(allowSelection)
{
this.pickRandom.hidden = !allowSelection;
this.select.hidden = !allowSelection;
const usedCaptions = allowSelection ? MapBrowserPageControls.Captions.cancel :
MapBrowserPageControls.Captions.close;
this.close.caption = usedCaptions.caption;
this.close.tooltip = colorizeHotkey(usedCaptions.tooltip, "cancel");
}
onSelectionChange()
{
this.select.enabled = this.gridBrowser.selected != -1;
}
onSelect()
{
this.mapBrowserPage.submitMapSelection();
}
static Captions =
{
"close":
{
"caption": translate("Close"),
"tooltip": translate("%(hotkey)s: Close map browser.")
},
"cancel":
{
"caption": translate("Cancel"),
"tooltip": translate("%(hotkey)s: Close map browser and discard the selection.")
}
};
}