> For the complete documentation index, see [llms.txt](https://stoneforgeteam.gitbook.io/stoneforgeteam-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://stoneforgeteam.gitbook.io/stoneforgeteam-docs/ui/main-menu.md).

# The main menu

`MainMenu` changes the main menu's list of buttons: add your own anywhere in it, move, remove or re-add the game's own, or clear it and build a menu of your own. The in-game [Esc menu](/stoneforgeteam-docs/ui/esc-menu.md) works the same way.

```csharp
MainMenu.AddButton(context, "My Mod", window.Open);                   // above Exit
MainMenu.AddAfter(context, VanillaButton.Play, "Multiplayer", lobby.Open);
MainMenu.AddBefore(context, "Credits", "Patch Notes", notes.Open);   // by name or text
```

A button's text can be a function, so it follows the game's language (see [Localization](/stoneforgeteam-docs/core-concepts/localization.md)):

```csharp
MainMenu.AddButton(context, () => context.Localization.Get("menu.options"), window.Open);
MainMenu.AddAfter(context, VanillaButton.Play, () => context.Localization.Get("menu.multiplayer"), lobby.Open);
```

`AddButton`, and `AddBefore` / `AddAfter` with a `VanillaButton`, take one.

## The game's buttons

`VanillaButton` names the game's own buttons, from the main list and its play screens:

`Play`, `Settings`, `Credits`, `Exit`, `Continue`, `NewGame`, `LoadGame`, `Prologue`, `Adventure`, `Back`.

Each does in your menu what it does in the game's - greyed out as the game's is (and `Continue`, with no last save, left out). Their text is the game's, in its language.

## Removing the game's buttons

```csharp
MainMenu.RemoveButton(context, VanillaButton.Credits);
MainMenu.RemoveButton(context, "Other Mod's Button");   // by its text
```

## Building a menu of your own

```csharp
MainMenu.ClearButtons(context);
MainMenu.AddButton(context, VanillaButton.Play);
MainMenu.AddButton(context, "Multiplayer", lobby.Open);
MainMenu.AddButton(context, VanillaButton.Settings);
MainMenu.AddButton(context, VanillaButton.Exit);
```

Menus can lead to menus. A button can clear the list and add others, with the game's `Back` to return:

```csharp
MainMenu.AddAfter(context, VanillaButton.Credits, "More", () =>
{
    MainMenu.ClearButtons(context);
    MainMenu.AddButton(context, VanillaButton.Continue);
    MainMenu.AddButton(context, VanillaButton.NewGame);
    MainMenu.AddButton(context, "Load Newest Save", LoadNewest);
    MainMenu.AddButton(context, VanillaButton.Back);   // the main menu as it started
});
```

## Reference

| `MainMenu`                                                                                        |                                                                                                         |
| ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| `AddButton(context, text, onClick)`                                                               | Your button, above Exit (or last).                                                                      |
| `AddBefore(context, anchor, text, onClick)`                                                       | Just above a button.                                                                                    |
| `AddAfter(context, anchor, text, onClick)`                                                        | Just below a button.                                                                                    |
| `AddButton(context, VanillaButton)`, `AddBefore(context, anchor, VanillaButton)`, `AddAfter(...)` | One of the game's buttons, back in, or moved if it's already there.                                     |
| `RemoveButton(context, VanillaButton)`, `RemoveButton(context, name)`                             | Take a button out. A named button that isn't there yet (another mod's, added later) goes when it comes. |
| `ClearButtons(context)`                                                                           | Empty the menu: the game's buttons and every mod's added so far.                                        |
| `RestoreButtons(context)`                                                                         | The menu as it was when the game started, with what every mod did while it loaded.                      |
| `UndoChanges(context)`                                                                            | Undo just this mod's changes since it loaded (other mods' stay): for a change a mod makes for a while.  |

An **anchor** is a `VanillaButton`, or a button's name: the game button's name (`"Play"` or `"Start"`, `"Settings"`, `"Credits"`, `"Exit"`), the text shown on any button (in the game's language), or the text of a button a mod added. Case doesn't matter. If the anchor isn't in the menu, the new button goes above Exit (or last).

The menu is laid out from every loaded mod's calls in the order they were made (mods load in folder order), and shows a change at once. A mod switched off takes what it did with it: its buttons go, and what it cleared comes back.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://stoneforgeteam.gitbook.io/stoneforgeteam-docs/ui/main-menu.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
