Skip to content

Settings Window

TheGenieOfTheCode edited this page Oct 29, 2026 · 4 revisions

Settings Window

SettingsSubmenu is a settings window built from settings you've already registered. List the keys, and it lays them out with the right control for each, adds a search box, section chips and indented sub-settings, saves only what changed, and asks to reload the world only when a setting that needs it actually changed. It's the window every Combat Tools module uses, so yours will look like theirs.

It extends Draw Steel's own application class, so it matches the system's look in both themes. CTLib loads before the system, so it builds the class the first time a module asks for it: call ctlib.settingsSubmenu() from your module's code, which runs after the system has loaded.

For the settings that stay on your module's tab in Foundry's own settings window, registerSettingsLayout gives the same headers, chips, indents and wiki links. See Your module's settings tab.

A minimal window

const SettingsSubmenu = ctlib.settingsSubmenu();

class MySettings extends SettingsSubmenu {
  static DEFAULT_OPTIONS = { id: 'my-module-settings', window: { title: 'My Module Settings' } };
  static get moduleId()    { return 'my-module'; }
  static get regularKeys() { return ['showDistances', 'distanceColour', 'fadeTime']; }
}

Hooks.once('init', () => {
  game.settings.register('my-module', 'showDistances', { name: 'Show Distances', hint: '...', scope: 'client', config: false, type: Boolean, default: true });
  // ...the other two
  game.settings.registerMenu('my-module', 'settings', {
    name: 'My Module', label: 'Configure', icon: 'fas fa-gear', type: MySettings, restricted: false,
  });
});

Register the settings with config: false so they only appear in your window.

What to override

Static getter Default What it does
moduleId null Your module's id. Required.
regularKeys [] The settings to show, in order. An entry can also be an object, see below.
debugKeys [] Settings shown under a Debug heading, only while your module has a debugMode setting and it's on.
enableKey null A master toggle: while it's off, every other setting in the window is greyed out.
dependencies {} { child: 'parent' } indents child under its parent and greys it out while the parent checkbox is off. '!parent' greys it out while parent is on.
requires {} The same as dependencies, without the indent.
intro null A line of text at the top of the window.
wiki null Links to your wiki, see Wiki links.
choiceHintPrefix null A localization prefix for a line under a dropdown that explains the chosen option, see below.

A parent in dependencies or requires can be any setting of your module, including one shown in another window: when it isn't in this window, its saved value counts. A child also greys out when its parent is greyed out by its own parent, and a nested window's row can be a child too, by its id.

A world setting is left out for players, so a window with restricted: false shows each user only what they may change.

Controls

Each setting gets its control from how it's registered: a checkbox for Boolean, a dropdown when it has choices, a slider when it has range, a number box for any other Number, and a text box for a String. A setting with requiresReload: true shows a Reload badge.

A setting registered with requiresModule: 'module-id' (or { id, label }) shows a badge saying whether that module is active, installed but off, or missing, here and in Foundry's own settings window. Until the module is active, the setting is greyed out and locked. Read it with ctlib.requiredSetting(namespace, key), which gives false while the module isn't active, whatever was saved.

For an image path with a file browser and preview, override _buildEntry:

_buildEntry(key) {
  const entry = super._buildEntry(key);
  if (entry && key === 'markerIcon') entry.isFilePicker = true;
  return entry;
}

_buildEntry returning null hides a setting, which is the place for conditions such as "only for players".

Saving stores only the settings whose value changed, so a setting the user never touched keeps following your default when you change it in a later version.

Entries that aren't settings

Put an object in regularKeys to show something else:

Object Shows
{ isSectionHeader: true, label } A heading. It's dropped when nothing follows it before the next heading.
{ isNestedMenu: true, id, name, label, icon, hint, opens } A button that opens another window. With opens set to that window's class, CTLib wires the click; without it, wire the click yourself in _onRender, by id.
{ isInfo: true, name, hint, isActive } A read-only line with an Active or Not Detected badge, for showing whether another module is present.

Any of these takes gmOnly: true to show it only to Directors. A nested window entry takes free: true to stay usable while the enableKey toggle is off.

Search and sections

Every window has a search box. It hides the rows whose name and hint don't contain every word typed, and the headings left with nothing under them. When a nested window opened with opens is another SettingsSubmenu, its settings are searched too: a match shows as a chip under that window's row, and clicking the chip opens the window on that setting.

With four or more section headings, a row of chips under the search box jumps to each section and marks the one in view.

Foundry's own settings search finds settings inside these windows as well. For a menu registered with a SettingsSubmenu type, matching settings are listed under the menu's button, and clicking one opens the window on it.

To open a window on one setting yourself, pass focusKey: new MySettings({ focusKey: 'fadeTime' }).render(true) scrolls to that setting and flashes it. focusSetting(key) does the same in an open window.

Explaining dropdown options

With choiceHintPrefix set to 'MYMOD.setting', a dropdown for the mode setting looks up MYMOD.setting.mode.choiceHint.<value> for the selected value and shows it under the hint, updating as the choice changes. Options with no such string show nothing extra.

Adding behaviour

Override _onRender(context, options) and call super._onRender(context, options) first. The form is this.element, and each control's name is its setting key.

Your module's settings tab

registerSettingsLayout(moduleId, groups, options) arranges the settings and menus that stay on your module's tab in Foundry's settings window. Call it once, in init or at the top of a file; CTLib applies it each time the settings window renders.

ctlib.registerSettingsLayout('my-module', [
  { label: 'MYMOD.tab.display', items: ['settings', 'showDistances', 'fadeTime'], wiki: 'Display' },
  { label: 'MYMOD.tab.module', items: ['debugMode'] },
], {
  indent: ['fadeTime'],
  dependencies: { fadeTime: 'showDistances' },
  wiki: { base: 'https://github.com/me/my-module/wiki/', pages: { showDistances: 'Display#distances' } },
});
Argument What it does
groups Headings, in order, each { label, items, wiki }. label is a lang key or text, items the setting and menu keys under it, and wiki an optional page for the heading. Rows in no group follow the last heading. With four or more groups, the tab gets section chips.
options.indent Keys to indent.
options.dependencies { child: 'parent' }, as in the window: the child is indented and greyed out while the parent checkbox is off, or on with '!parent'.
options.wiki { base, pages }: pages maps a setting or menu key to a wiki page, shown as a books icon on its label.

Wiki links

A books icon beside a label opens a wiki page in a new tab. In a window, static get wiki() returns { base, pages }, where each key in pages is a setting key, a nested window's id, or a section heading's text, and each value is a page name or a full URL.

static get wiki() {
  return { base: 'https://github.com/me/my-module/wiki/', pages: { showDistances: 'Display#distances' } };
}

For your own markup:

Function Returns
wikiUrl(base, page) page added to base, page itself when it's a full URL, or null when there's no page.
wikiLink(url) A books icon link to url, with a tooltip and label naming the page.
addWikiLink(element, url) Appends a wikiLink to element, unless it already has one or url is empty.

Related Pages

Clone this wiki locally