← Mods

CairnModOptions

lib

v0.1.1

One in-game settings page for every mod's options.

Gives any mod a place to expose its settings inside Cairn's own Settings menu. Register a list of typed options and they appear on a Mods page — one mod at a time, picked from a dropdown at the top of the page.

Authors write zero UI: declare toggles, sliders, text fields, dropdowns, and buttons; players get native-looking controls that read and write your values live.

Features

  • Native "Mods" page in the game's Settings menu
  • One mod at a time, via a selector dropdown
  • Typed options: toggle, slider, text, list, dropdown, buttons, labels
  • Back each option with a MelonPreferences entry or your own get/set
  • Changes apply and persist the moment the player makes them

Requires


ModOption.Kind

Which kind of row this option renders as.

ModOption.Kind.Toggle

ModOption.Kind.Slider

ModOption.Kind.TextField

ModOption.Kind.ListArrows

ModOption.Kind.Dropdown

ModOption.Kind.ButtonDouble

ModOption.Kind.Action

ModOption.Kind.Label

ModOption

Build each row with a ModOption factory. Every option takes a label and an optional tooltip. Stateful options (toggle, slider, text, list, dropdown) bind either to a MelonPreferences entry — persisted to disk automatically — or to your own get/set callbacks.

ModOption.Toggle(label, entry, tooltip?) ModOption

Bool on/off. Backed by a MelonPreferences_Entry, or a Func get / Action set pair.

label string Row label.
entry MelonPreferences_Entry<bool> Backing preference (or pass get/set callbacks).
tooltip opt string Hover help.
ModOption.Toggle(label, get, set, tooltip?) ModOption

Bool on/off. Backed by a MelonPreferences_Entry, or a Func get / Action set pair.

label string Row label.
get Func<bool> Reads the current value.
set Action<bool> Writes the new value.
tooltip opt string Hover help.
ModOption.Slider(label, min, max, entry, tooltip?) ModOption

Float slider in [min, max].

label string Row label.
min float Lower bound.
max float Upper bound.
entry MelonPreferences_Entry<float> Backing preference (or pass get/set).
tooltip opt string Optional hover help.
ModOption.Slider(label, min, max, get, set, tooltip?) ModOption

Float slider in [min, max].

label string Row label.
min float Lower bound.
max float Upper bound.
get Func<float> Reads the current value.
set Action<float> Writes the new value.
tooltip opt string Optional hover help.
ModOption.TextField(label, entry, contentType?, tooltip?) ModOption

Editable string. contentType sets the keyboard/validation mode (e.g. IntegerNumber for numeric-only).

label string Row label.
entry MelonPreferences_Entry<string> Backing preference (or pass get/set).
contentType opt TMP_InputField.ContentType Input mode. Default Standard.
tooltip opt string Optional hover help.
ModOption.TextField(label, get, set, contentType?, tooltip?) ModOption

Editable string. contentType sets the keyboard/validation mode (e.g. IntegerNumber for numeric-only).

label string Row label.
get Func<string> Reads the current value.
set Action<string> Writes the new value.
contentType opt TMP_InputField.ContentType Input mode. Default Standard.
tooltip opt string Optional hover help.
ModOption.ListArrows(label, choices, entry, tooltip?) ModOption

Pick from a string list with left/right arrows. Stores the selected index.

label string Row label.
choices string[] Options to cycle through.
entry MelonPreferences_Entry<int> Stores the selected index (or pass get/set).
tooltip opt string Optional hover help.
ModOption.ListArrows(label, choices, get, set, tooltip?) ModOption

Pick from a string list with left/right arrows. Stores the selected index.

label string Row label.
choices string[] Options to cycle through.
get Func<int> Reads the selected index.
set Action<int> Writes the selected index.
tooltip opt string Optional hover help.
ModOption.Dropdown(label, choices, entry, tooltip?) ModOption

Pick from a string list with a popup dropdown. Stores the selected index.

label string Row label.
choices string[] Options to pick from.
entry MelonPreferences_Entry<int> Stores the selected index (or pass get/set).
tooltip opt string Optional hover help.
ModOption.Dropdown(label, choices, get, set, tooltip?) ModOption

Pick from a string list with a popup dropdown. Stores the selected index.

label string Row label.
choices string[] Options to pick from.
get Func<int> Reads the selected index.
set Action<int> Writes the selected index.
tooltip opt string Optional hover help.
ModOption.ButtonDouble(label, leftLabel, invokeLeft, rightLabel, invokeRight, leftActive?, rightActive?, tooltip?) ModOption

A row with two action buttons side by side. No persistent state. leftActive/rightActive toggle interactivity.

label string Row label.
leftLabel string Left button text.
invokeLeft Action Left button callback.
rightLabel string Right button text.
invokeRight Action Right button callback.
leftActive opt bool Whether the left button is interactive. Default true.
rightActive opt bool Whether the right button is interactive. Default true.
tooltip opt string Optional hover help.
ModOption.Action(label, invoke, tooltip?) ModOption

A single action button. No persistent state.

label string Button text.
invoke Action Pressed callback.
tooltip opt string Optional hover help.
ModOption.Info(text, tooltip?) ModOption

Read-only display text. No interaction — use for section headers or status lines.

text string Display text.
tooltip opt string Optional hover help.
Example
// backed by a MelonPreferences entry (persists to disk)
ModOption.Toggle("Enable", enabledEntry);

// or your own get/set
ModOption.Toggle("Enable",
    () => _enabled, v => _enabled = v);

// numeric-only text field
ModOption.TextField("Max count", maxEntry,
    TMP_InputField.ContentType.IntegerNumber);

// a non-persistent action button
ModOption.Action("Reload config", ReloadConfig);

ModOptionSet

One mod's block of options.

ModOptionSet.ModName

Display name the block was registered under.

ModOptionSet.Options

The mod's option rows, in declaration order.

ModOptions

Register a list of options under your mod's name. They become one section of the Mods page, selectable from the dropdown. Re-registering replaces your previous list. Consumer mods never touch the UI — the page reads this registry.

ModOptions.Sets IReadOnlyList

Every registered mod's option block, in registration order.

ModOptions.Register(modName, options)

Register or replace your mod's option list. modName labels your entry in the dropdown.

modName string Display name shown in the mod selector.
options IEnumerable<ModOption> Rows to display, in declaration order.
ModOptions.Unregister(modName)

Remove your mod's options from the page.

modName string The name you registered under.
Example
ModOptions.Register("MyMod", new[]
{
    ModOption.Toggle("God mode", godModeEntry),
    ModOption.Slider("Speed", 0f, 10f, speedEntry),
    ModOption.Dropdown("Difficulty",
        new[]{ "Easy", "Normal", "Hard" }, difficultyEntry),
    ModOption.Action("Reset to defaults", ResetAll),
});