Skip to content

Foundry Settings

R edited this page Nov 11, 2026 · 5 revisions

Foundry.Settings

Part of the Foundry API reference.

New to WoW addons? Start here →

Foundry.Settings is a thin bridge over Blizzard's options-panel registration surface. It wraps Blizzard's Settings.* API, so you call one factory and get a controller for the category you registered. It can register a panel frame you build yourself, or a launcher entry that holds one button which opens your own options window. It is not a widget factory, not an options framework, and not a SavedVariables owner. You build your panel frame or your options window; Foundry owns only the registration and the resulting Blizzard category object.

API version: Foundry.Settings is API version 2. Assert it with F:RequireModule("Settings", 2) if your addon needs the module present at a minimum version. (This is the module's version; the library as a whole is F.API_VERSION, which is 7 as of v1.0.114.) Settings version 2 adds launcher entries (§8), which need version 2. Panel registration works the same on version 1 and 2.


1. Mission

The registration idiom every addon needs looks the same everywhere: call the Settings.RegisterCanvasLayoutCategory + Settings.RegisterAddOnCategory pair and store the resulting category for later. It is easy to get subtly wrong (wrong registration order, re-calling RegisterAddOnCategory for subcategories, double-registration from multiple callsites). Foundry.Settings encapsulates that idiom into a single factory so you write it once and it is tested, validated, and correct.

What the module does: registration (a panel frame, or a launcher entry), the duplicate-refusal registry, and a clean :Open() for the category you registered.

What the module does not do: create frames, lay out controls, own SavedVariables, provide localization, manage profiles, or wire OnCommit / OnDefault / OnRefresh callbacks. Those all stay on your panel frame, where Blizzard designed them to live.


2. F.Settings:New(config) — the factory

local F = _G.Foundry_1_0

local panel = CreateFrame("Frame", "MyAddonSettingsPanel")
panel.name = "My Addon"

local settings = F.Settings:New({
    title  = "My Addon",   -- required: player-facing category title
    frame  = panel,        -- the panel frame to register (or launch, see §8)
    parent = nil,          -- optional: parent Settings controller (subcategory), or nil
    name   = "My Addon",   -- optional: duplicate-refusal key (defaults to title)
})

:New returns a controller object. The controller owns the registered Blizzard category and the name key in Foundry's live-registry. No event frame is created; Settings registers no WoW engine events.

Supply exactly one of frame or launch. frame registers a panel you built (this section and §3 to §7). launch registers a launcher entry (§8).

Config fields

Field Type Required Meaning
title non-empty string yes Player-facing category title. Passed as the second argument to Settings.RegisterCanvasLayoutCategory.
frame frame one of frame or launch Your panel frame. Foundry registers it but does not create or mutate it. Must be a table with a GetObjectType method (i.e. a real frame). Cannot be combined with launch.
launch function one of frame or launch Launcher mode. Called with no arguments when the player clicks the entry's button. Cannot be combined with frame. See §8.
buttonText non-empty string with launch only The label on the launcher button. Required with launch, and refused with frame. See §8.
parent Foundry.Settings controller or nil no When a live (non-destroyed) Settings controller is supplied, Foundry registers a subcategory under it. See §5. Not supported with launch.
name non-empty string no The duplicate-refusal key stored in Foundry's module-level live registry. Defaults to title when omitted. Freed when the controller is :Destroy()-ed.

Atomic validation

Validation is atomic. :New inspects every field before calling any Blizzard API. If any field is invalid, Foundry calls F:RaiseDevError(...) with a "Settings:New: ..." prefix and returns without registering anything. Prior registrations by other controllers are never touched.

Validation order:

  1. title — must be a non-empty string.
  2. frame and launch: exactly one must be supplied.
  3. With frame: it must be a table that has GetObjectType (i.e. a real WoW frame), and buttonText must be absent. With launch: it must be a function, and buttonText must be a non-empty string.
  4. parent: if supplied, must be a live (non-destroyed) Foundry.Settings controller (nil is also accepted), and it is refused with launch.
  5. name: if explicitly supplied, must be a non-empty string; omitting it defaults to title.
  6. Duplicate-key check: if the resolved name (defaulting to title) already belongs to a live controller, the call is refused.

Duplicate-refusal registry

Foundry keeps a module-level table of all name keys owned by live controllers. A second :New with a key already in that table is refused and leaves existing registrations untouched. The key is freed only when :Destroy() is called on the controller that owns it. The registry persists for the module's lifetime and is not cleared per-event or per-session; this matches the persistent ownedNames approach used in Foundry.Lifecycle.


3. Registration

Foundry.Settings always uses Blizzard's Settings API. It checks for the functions it needs by feature detection, not version checks or pcall:

local function hasModernSettings()
    return type(_G.Settings) == "table"
        and type(_G.Settings.RegisterCanvasLayoutCategory) == "function"
        and type(_G.Settings.RegisterAddOnCategory) == "function"
end

For a root controller (parent is nil):

local category, layout = Settings.RegisterCanvasLayoutCategory(frame, title)
Settings.RegisterAddOnCategory(category)

Settings.RegisterAddOnCategory is called once for the root only. Both category and layout are stored on the controller and are accessible via :GetNativeHandles() as handles.category and handles.layout.

For a child controller (parent is a live Settings controller):

local subcategory, subcategoryLayout =
    Settings.RegisterCanvasLayoutSubcategory(parent._category, frame, title)

Settings.RegisterAddOnCategory is not called again for the child.

Client without the Settings API: :New registers nothing and returns nothing. In a dev build it raises an error. In a release build it prints a message and returns, so check the result if your addon can run on such a client. Every client Foundry supports has the Settings API, so addons on those clients see no difference. There is no InterfaceOptions fallback, and GetNativeHandles().mode is always "settings".

Error strategy: feature detection handles the absence case. If the Settings API is present but a call itself errors, Foundry lets the error surface rather than wrapping in a blanket pcall. This matches the Foundry house style: fail loudly in dev builds so real Blizzard errors are not swallowed.


4. Controller methods

Every method refuses on a destroyed controller with F:RaiseDevError("Settings:<Method> called on a destroyed controller").

:Open()

Opens the Blizzard settings panel to this controller's category.

Settings.OpenToCategory(self._category:GetID())

categoryID is a number obtained from category:GetID(). The category object is not passed directly. This call is taint-safe from an insecure OnClick handler, since Blizzard's own XML callers use it directly. No C_Timer.After defer is needed. For a launcher controller, :Open() opens the Settings panel to the launcher entry; it does not call your launch function.

:GetCategoryID()

Returns the numeric category ID usable with Settings.OpenToCategory.

self._category:GetID() → number. Root, child, and launcher category objects expose :GetID() with the same contract (confirmed in-game for a subcategory: it returns a number, e.g. 35).

:GetNativeHandles()

Returns a fresh table containing the live Blizzard objects this controller owns. A fresh table is returned on every call; mutating the returned table does not corrupt controller state. The Blizzard objects inside are live references.

Key Value
frame The registered panel frame (the frame you passed to :New). nil for a launcher.
category The Blizzard category or subcategory object.
categoryID category:GetID() as a number.
mode Always "settings".
layout The layout object returned when the category was registered.
initializer The Blizzard button initializer (launcher only; nil for a panel).
kind "canvas" for a panel frame, "launcher" for a launcher entry.

Use this when you need to reach a Blizzard object Foundry.Settings does not wrap — for example to hand the category to another API that expects it directly, or to use the layout anchor for pinning controls to the canvas. Called on a destroyed controller, :GetNativeHandles refuses like every other post-Destroy call and returns nil.

:Destroy()

Marks the controller destroyed, frees the duplicate-refusal key from Foundry's live registry, and releases internal references. Idempotent: a second :Destroy() is a no-op.

:Destroy() does not promise to unregister the Blizzard category. Blizzard provides no reliable unregister API for addon categories; the category remains visible in the Settings panel after Destroy. The point of :Destroy() is freeing Foundry's bookkeeping (the duplicate-refusal key, the controller references) and preventing the destroyed controller from quietly half-working via post-Destroy method calls.


5. Subcategories

Pass a live Settings controller as parent to register a subcategory:

local rootSettings = F.Settings:New({
    title = "My Addon",
    frame = rootPanel,
})

local subSettings = F.Settings:New({
    title  = "Advanced",
    frame  = advancedPanel,
    parent = rootSettings,   -- registers as a child of rootSettings
    name   = "My Addon.Advanced",
})

Foundry calls Settings.RegisterCanvasLayoutSubcategory(rootSettings._category, advancedPanel, "Advanced"), which returns a subcategory object with a :GetID() method. This was confirmed in game: the return value is a table with :GetID() → number, identical in contract to the root category object. Settings.RegisterAddOnCategory is not called again for the child.

Validation: the parent field must be a live (non-destroyed) Settings controller. Passing a destroyed controller, or any other value that is not a Foundry.Settings controller, is rejected atomically. Launcher entries cannot have a parent.

Child methods: :Open(), :GetCategoryID(), :GetNativeHandles(), and :Destroy() all work on child controllers with the same contracts as root controllers. :GetCategoryID() returns the child's own numeric ID; :Open() calls Settings.OpenToCategory(childCategory:GetID()).


6. Teardown

settings:Destroy()

:Destroy() is the right call when you want deterministic cleanup of Foundry's bookkeeping — for example when a feature module is disabled, or in tests that create and tear down controllers. What it guarantees:

  • The controller is marked destroyed; all further method calls are refused.
  • The name key is freed from Foundry's duplicate-refusal registry, so the same name can be registered again by a new controller. Because Blizzard cannot unregister a category, that later :New reuses the category already registered under the name when its title and frame (or title and buttonText) are the same, plus the same parent for a subcategory, and is refused when any of them differ, including switching between a panel and a launcher (see §8).
  • Internal references to the frame and category object are released.

What it does not guarantee:

  • The Blizzard category is not unregistered. Blizzard provides no reliable API to remove an addon category from the Settings panel; the entry remains visible for the session. If you need the panel entry gone, you are in territory Foundry cannot help with — file a request or use :GetNativeHandles() to reach the raw object and experiment.

If you simply drop your reference to the controller without calling :Destroy(), Lua's garbage collector reclaims the controller table, but the duplicate-refusal key stays live in Foundry's registry until the module is unloaded or :Destroy() is explicitly called. For long-lived root registrations (the common case), this is not an issue — you register once and keep the controller for the session.


7. Worked example

Panel registration (the common case)

Build your panel frame as you normally would. Call :New once from your addon's OnInitialize. Store the controller. Drive :Open() from your button.

local F = _G.Foundry_1_0

local OptionsPanel = {}

function OptionsPanel:Initialize()
    -- Build the stub panel that appears in the Settings sidebar.
    -- The panel itself is just a redirect button; your real options
    -- frame is a separate, standalone frame.
    local panel = CreateFrame("Frame", "MyAddonSettingsPanel")
    panel.name = "My Addon"

    local label = panel:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
    label:SetPoint("TOPLEFT", panel, "TOPLEFT", 16, -16)
    label:SetText("My Addon")

    local button = CreateFrame("Button", nil, panel, "UIPanelButtonTemplate")
    button:SetSize(190, 24)
    button:SetPoint("TOPLEFT", label, "BOTTOMLEFT", 0, -16)
    button:SetText("Open My Addon Options")
    button:SetScript("OnClick", function()
        OptionsPanel:Open()
    end)

    -- Register with Blizzard via Foundry.Settings.
    self.settings = F.Settings:New({
        title = "My Addon",
        frame = panel,
    })
end

function OptionsPanel:Open()
    -- Show your real options frame. The Blizzard Settings panel stays
    -- open in the background; Esc will dismiss it. If you want to open
    -- directly to the Blizzard category instead, call:
    --   self.settings:Open()
    -- Replace `myRealOptionsFrame` with a reference to your actual frame.
    myRealOptionsFrame:Show()
end

Call OptionsPanel:Initialize() from your lifecycle OnInitialize. Do not call it at file scope — CreateFrame and Settings.* must not be called at parse time.

Adding a subcategory

local advPanel = CreateFrame("Frame", "MyAddonAdvancedSettingsPanel")
advPanel.name = "Advanced"

local label = advPanel:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
label:SetPoint("TOPLEFT", advPanel, "TOPLEFT", 16, -16)
label:SetText("My Addon — Advanced")

self.advancedSettings = F.Settings:New({
    title  = "Advanced",
    frame  = advPanel,
    parent = self.settings,        -- child of the root controller above
    name   = "My Addon.Advanced",  -- distinct duplicate-refusal key
})

advPanel appears nested under "My Addon" in the Settings sidebar.


8. Launcher entries

Use a launcher when your options already live in your own window and you do not want to build a placeholder panel just to hold a redirect button. Pass launch and buttonText instead of frame:

local F = _G.Foundry_1_0

-- Call this once from your addon's OnInitialize.
function MyAddon:RegisterOptionsEntry()
    self.settings = F.Settings:New({
        title      = "My Addon",
        buttonText = "Open My Addon Options",
        launch     = function()
            MyAddon:ShowOptionsWindow()  -- show your own options window
        end,
    })
end

What :New does in this mode:

  • Registers a vertical-layout category under AddOns in the Settings panel, titled title, holding one Blizzard button labeled buttonText.
  • Calls your launch function with no arguments when the player clicks the button. The button's own click arguments are not passed on.
  • Makes the title and the button text searchable in the Settings panel.
  • Returns the same kind of controller as a panel registration. :GetCategoryID() and :Destroy() work as usual. :Open() opens the Settings panel to the launcher entry.

Rules:

  • launch and frame are mutually exclusive. Supplying both, or neither, is refused.
  • buttonText is required with launch and must be a non-empty string. buttonText with frame is refused.
  • parent is not supported with launch. A launcher entry is always a root entry.
  • name defaults to title and works as it does for panels.
  • Validation is atomic, as in §2. A refused call registers nothing.
  • If the client lacks the Settings functions a launcher needs, :New is refused the same way as in §3 (dev builds raise an error, release builds print a message and return).
  • If you :Destroy() the controller and the player later clicks the button (Blizzard keeps the button for the session), nothing is launched. Dev builds raise an error naming the entry. Call :New again with the same title, buttonText and name to restore it.

GetNativeHandles() on a launcher controller returns frame = nil, kind = "launcher", and initializer set to the Blizzard button initializer, alongside category, categoryID, mode, and layout as in the Controller methods section.

Requiring version 2

Launcher entries need Foundry.Settings API version 2. The Foundry copy that loads may be older than the one you shipped, because only one copy runs and it is the first one loaded, unless a newer 1.0.115 or later copy upgrades it in place. For the reason, see Which copy runs, and why. Pick one of two approaches:

-- Raise an error if the loaded copy is older than version 2:
local Settings = F:RequireModule("Settings", 2)
-- Or fall back to your own handling when it is older:
if F.Settings and (F.Settings.API_VERSION or 0) >= 2 then
    MyAddon.settings = F.Settings:New({
        title      = "My Addon",
        buttonText = "Open My Addon Options",
        launch     = function() MyAddon:ShowOptionsWindow() end,
    })
else
    -- Foundry.Settings is missing or too old: register a panel the
    -- way §2 shows, or skip the entry.
end

9. What Foundry.Settings does not do

  • Widget and control helpers. Checkboxes, dropdowns, sliders, and other controls are not provided. Build your panel frame with whatever approach you use for other frames. Foundry does not create or lay out panel content.
  • OnCommit, OnDefault, OnRefresh wiring. Blizzard calls these optional methods on your panel frame when the user applies, defaults, or shows the category. Wire them directly on your frame before passing it to :New; Foundry does not intercept or proxy them.
  • SavedVariables. Foundry.Settings owns no saved data. User settings persistence is Foundry.DB's domain, not Settings'.
  • Profile management. Switching profiles, per-character vs global data, reset to defaults — all of this lives in your DB layer, not in Settings.
  • Localization. The title you pass is your responsibility. Foundry passes it to Blizzard verbatim.
  • AceConfig compatibility. Foundry.Settings does not consume AceConfig tables or auto-generate controls from a config definition. If you use AceConfig-3.0, keep using it; Foundry.Settings can co-exist (you would pass your AceConfig panel frame to :New, not replace AceConfig).
  • Older-client fallback. Foundry.Settings uses only Blizzard's Settings.* API. On a client without it, nothing is registered: dev builds raise an error and release builds print a message.

10. Escape hatch: GetNativeHandles()

When you need a Blizzard object that Foundry.Settings does not expose through its own API, drop to the native surface without removing the controller:

local handles = settings:GetNativeHandles()
-- handles.frame       == your panel frame (nil for a launcher)
-- handles.category    == the Blizzard category/subcategory object
-- handles.categoryID  == category:GetID() as a number
-- handles.mode        == "settings" (always)
-- handles.layout      == the layout object from the category registration
-- handles.initializer == the button initializer (launcher only, else nil)
-- handles.kind        == "canvas" or "launcher"

The returned table is a fresh table on every call. Mutating it does not affect the controller. The objects inside (frame, category) are live references to the real Blizzard objects; reading or calling methods on them does reach the live state.

Common reasons to use this:

  • You need the category object to pass to a third-party API that expects it directly (e.g. a settings-layout library).
  • You want to call Settings.OpenToCategory(handles.categoryID) yourself rather than going through :Open().
  • You want to check handles.kind at runtime to tell a panel from a launcher.

If you find yourself reaching into native handles to work around a missing controller method, that is a signal the missing method belongs in Foundry.Settings. File a feature request instead of building a permanent workaround on top of the escape hatch.

Called on a destroyed controller, :GetNativeHandles refuses like every other post-Destroy call and returns nil.

Clone this wiki locally