0ad/binaries/data/mods/public/gui/maps/mapbrowser/controls/MapBrowserControls.js
Dunedan 93ce94655d
Use @stylistic/brace-style for eslint
Up to now `eslint-plugin-brace-rules` was used to enforce a common brace
style for JavaScript code. This plugin was however updated the last time
over 9 years ago and will be incompatible with ESLint v10, as that
[removes `context.getSourceCode()`][1], the plugin relies on.

To keep the eslint config working with ESLint v10, this replaces
`eslint-plugin-brace-rules` with the [`@stylistic/brace-style`][2] rule
from `@stylistic/eslint-plugin`, a package we already use.

While `@stylistic/brace-style` doesn't offer an option to format braces
in exactly the same way as before, the "allman" style seems to be the
one closest to the existing code.

[1]: https://eslint.org/blog/2025/11/eslint-v10.0.0-alpha.0-released/#removed-deprecated-rule-context-members
[2]: https://eslint.style/rules/brace-style
2026-01-12 21:33:52 +01:00

84 lines
2.7 KiB
JavaScript

class MapBrowserPageControls
{
constructor(mapBrowserPage, gridBrowser)
{
for (const 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 = () =>
{
const 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.")
}
};
}