> 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/context-menus.md).

# Right-click menus

`ContextMenus` changes the game's right-click menus: what a click on a unit, an object or an item offers (Talk, Attack, Explore...). A mod can add an option of its own to the menus of the instances it picks, or change any menu as it opens.

## An option of your own

```csharp
ContextMenus.Add(context, "Inspect",
    appliesTo: target => target.As<GameInstance>().IsA((int)GameObjectId.o_enemy),
    onClick: target => context.Log($"Inspecting {ActionsLog.NameOf(target)}"),
    hover: "Look this one over.");
```

`appliesTo` is asked as each menu opens, with what it's for; `onClick` runs on that instance when the option is clicked. Then the menu closes, as for the game's own options.

## Changing a menu as it opens

```csharp
ContextMenus.OnOpen(context, menu =>
{
    if (menu.Has("Attack") && Units.IsPlayer(menu.Target))
        menu.Remove("Attack");
    if (menu.Has("Talk"))
        menu.SetText("Talk", "Chat");
    menu.Add("Wave", target => context.Log("You wave."), index: 0, enabled: !Player.InCombat);
});
```

The handler gets the menu with its options as the game made them. Change it there: the game builds the menu's buttons from it afterwards.

| `ContextMenu`                                                   |                                                                                                                           |
| --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| `Target`                                                        | What the menu's for: the instance right-clicked.                                                                          |
| `Items`                                                         | Its options, top to bottom (`ContextMenuItem`: `Key`, `Text`, `Enabled`, `Hover`).                                        |
| `Has(key)`                                                      | Whether it has an option. The game's keys are `"Attack"`, `"Talk"`, `"Explore"`...                                        |
| `Add(text, onClick, index, enabled, hover)`                     | Adds an option, at the bottom or at `index`, greyed out unless `enabled`, with the game's hint on hover. Returns its key. |
| `Remove(key)`, `SetText(key, text)`, `SetEnabled(key, enabled)` | Removes, renames or greys out an option.                                                                                  |

A menu left with no options isn't shown, and one that grows is sized again as the game sizes it. A greyed-out option of yours doesn't run when clicked.

StoneForge makes the game's menu script hookable itself: no `[assembly: HookScript]` is needed.


---

# 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/context-menus.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.
