> For the complete documentation index, see [llms.txt](https://malbersanimations.gitbook.io/animal-controller/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://malbersanimations.gitbook.io/animal-controller/malbers-questforge/controller-support/screen-navigation.md). Agents can also search and read this documentation through its [MCP server](https://malbersanimations.gitbook.io/animal-controller/~gitbook/mcp).

# Screen Navigation

Quest Forge keeps a stack of the screens that are open. The screen on top owns the input: B closes that screen only, focus stays inside it, and the character's gameplay buttons are switched off until the last blocking screen closes. This page explains the components behind that and how to plug your own screens in.

***

### The Screen Stack

Every Quest Forge screen reports itself to the **UI State Coordinator** when it opens and closes. Nested screens stack up, for example:

**World Map → Waypoint Picker → On-Screen Keyboard**

The top of the stack is the active screen. Closing a screen removes it from the stack and the one underneath becomes active again.

| Screen              | Opened by                                                                                                                              |
| ------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| `Dialogue`          | A conversation (Dialogue Manager)                                                                                                      |
| `ModalWindow`       | A dialogue modal window                                                                                                                |
| `Journal`           | The Quest Journal                                                                                                                      |
| `FactionJournal`    | The Reputation screen                                                                                                                  |
| `WorldMap`          | The World Map                                                                                                                          |
| `WaypointPicker`    | The waypoint picker over the map                                                                                                       |
| `FastTravelConfirm` | The fast travel confirmation over the map                                                                                              |
| `POIFilter`         | The map filter panel                                                                                                                   |
| `TextEntry`         | The [On-Screen Keyboard](broken://pages/f6bd9cd2079ede3f48d15dc318888c94d81532a1)                                                      |
| `Controls`          | The [Controls screen](broken://pages/2c62b533ab2143c845caa35d520153ce51b02697), including when another product (Inventory V3) shows it |
| `NewQuest`          | Reserved for the new-quest panel                                                                                                       |
| `Custom`            | Free for your own screens                                                                                                              |

***

### B Closes the Top Screen Only

Each screen listens for the router's **Cancel** command (B / Esc) and only acts when it is the top screen. The router takes a snapshot of the screen state before it hands a press to the screens, and each screen checks that snapshot. So when the Controls screen closes itself on B, the Journal underneath does not also see the press and close. One press always closes one screen.

| Top screen          | What B does                                                        |
| ------------------- | ------------------------------------------------------------------ |
| Controls            | Closes Controls (or closes its Swap / Reset all box first).        |
| On-Screen Keyboard  | Cancels the edit and closes the keyboard.                          |
| Waypoint Picker     | Removes the pending waypoint and closes the picker.                |
| Fast Travel Confirm | Declines and closes the dialog.                                    |
| Map Filters         | Closes the filter panel.                                           |
| World Map           | Closes the map (when the navigator's **Cancel Closes Map** is on). |
| Journal             | Closes the journal.                                                |

***

### Gameplay Blocking

While a screen that blocks gameplay is open, the **Gameplay Input Blocker** switches off the player's gameplay buttons, so a menu press does not also make the character jump, crouch, attack, holster or pause in the background. It also locks the character and pauses the camera's look and wheel zoom, so scrolling a list or the map doesn't turn the camera.

Only rows that were on are switched off, and only those are switched back on when the screen closes. Switching back on waits until the end of the frame, so the B that closes a screen can't also crouch (B is Crouch in gameplay).

During dialogue and modal windows the blocker steps aside: the Dialogue Manager runs its own blocking for conversations.

Add it with **Add Component → Malbers → Quest Forge → Controller → Gameplay Input Blocker** (One-Click Setup adds it to the ControllerSupport object so no setup is required).

#### Inspector Properties

| Property             | Type      | Description                                                                                                                                                                                                                                                                                                                              |
| -------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Keep Enabled**     | string\[] | Player input rows that stay on while a screen is open, because they open or close Quest Forge screens. Default: `OpenMap`, `CloseMap`, `OpenJournal`, `AdvanceDialogue`.                                                                                                                                                                 |
| **Fallback Blocked** | string\[] | Rows to switch off when the player's input component can't list its rows (input sources other than **MInputLink**). Default: `Jump`, `Crouch`, `Interact`, `MainAttack`, `SecondAttack`, `Ability1`, `Action3`, `Action4`, `Reload`, `Holster1`, `Holster2`, `Holster3`, `Strafe`, `Sprint`, `LockOn`, `Inventory`, `Pause`, `PeekPath`. |
| **Lock Character**   | bool      | Lock the character's movement and its own input while blocked, like dialogue does. Default: on.                                                                                                                                                                                                                                          |

With **MInputLink**, the blocker switches off every row on the active map except those in **Keep Enabled**. The player is found through the Quest Manager's player reference, else the object tagged **Player**.

***

### Focus When a Screen or Popup Opens

The **UI Focus Controller** decides which button the controller has selected.

* **When a screen opens**, it selects that screen's first control: the **First Selection** of the screen's focus context, or else the first usable button under its **Root**.
* **When a popup opens over a screen** (waypoint picker, fast travel confirmation, map filters, on-screen keyboard, Controls), the popup pushes its own focus context. Focus is trapped inside the popup, and the button the player was on is remembered. The press that opened the popup can't move the selection off the popup's first button in the same frame.
* **When the popup closes**, the remembered button is selected again (for example the waypoint name field after the on-screen keyboard closes).
* **When the selection is lost** (the selected button is hidden, disabled or outside the trapped popup), the nearest usable button is selected.
* **When the player picks up a gamepad**, focus is restored on the current screen so there is always a selection to move from.

Add it with **Add Component → Malbers → Quest Forge → Controller → UI Focus Controller**.

#### Inspector Properties

| Property              | Type                         | Description                                                     |
| --------------------- | ---------------------------- | --------------------------------------------------------------- |
| **State Coordinator** | QuestForgeUIStateCoordinator | The coordinator to follow. Found automatically when empty.      |
| **Input**             | QuestForgeInputRouter        | The router, for device changes. Found automatically when empty. |
| **Contexts**          | List                         | One entry per screen.                                           |

Each **Contexts** entry has:

| Property            | Type               | Description                                                                              |
| ------------------- | ------------------ | ---------------------------------------------------------------------------------------- |
| **State**           | QuestForgeUIScreen | The screen this entry is for.                                                            |
| **Root**            | GameObject         | The part of the UI that owns focus for this screen (the window, not the whole canvas).   |
| **First Selection** | Selectable         | Optional. The control focused first. Empty uses the first usable control under **Root**. |

The older **Gamepad UI Focus** component still works. With a UI Focus Controller in the scene it pushes and pops a focus context; without one it handles its own panel as before.

***

### Selection Frame

The **Selection Frame** draws a gold outline around whatever the controller has selected inside its **Scope**. It follows the selected element every frame, at any layout and canvas scale, and pulses gently so it reads as a cursor. By default it only shows while a gamepad is in use, because the mouse has its own pointer.

The waypoint picker and map filter panel add one automatically. Add one to your own panel with **Add Component → Malbers → Quest Forge → Controller → Selection Frame**.

#### Inspector Properties

| Property         | Type          | Description                                                                                                   |
| ---------------- | ------------- | ------------------------------------------------------------------------------------------------------------- |
| **Scope**        | RectTransform | Only selections inside this rect are outlined. The frame is drawn as its last child. Defaults to this object. |
| **Color**        | Color         | Frame colour. Default: gold (R 1, G 0.78, B 0.1).                                                             |
| **Thickness**    | float         | Outline thickness in reference pixels. Default: 3.                                                            |
| **Padding**      | float         | Gap between the selected element and the frame. Default: 3.                                                   |
| **Pulse**        | bool          | Gently pulse the frame. Default: on.                                                                          |
| **Gamepad Only** | bool          | Only show while a gamepad is the active device. Default: on.                                                  |
| **Frame Sprite** | Sprite        | Optional 9-sliced border sprite. Empty uses a built-in square outline.                                        |

***

### Mouse and Controller Together

* **Device switching** is detected from any button press on any device, a stick pushed past half way, or the mouse moved more than 4 pixels. Prompts, the selection frame and the map crosshair follow straight away. With **Prefer Gamepad When Connected** on the Input Router, plugging in a pad switches to gamepad mode before the player presses anything, and unplugging the last pad switches back.
* **Hovering a list row selects it** (quest rows, dialogue choices, Reputation rows), so mouse, keyboard and gamepad always show one highlight. A row that appears under a mouse that isn't moving (the list just opened or scrolled) is not treated as a hover, so a resting mouse can't steal the controller's selection.
* **Brand changes** (picking up a PlayStation pad after an Xbox pad) refresh every prompt.

***

### Lists and Grids

The **UI Navigation Group** gives a list of buttons a fixed up/down/left/right order, so the controller never gets stuck or jumps to a random button. Quest Forge uses it for the map filter categories, and similar code drives the journal list, dialogue choices and the waypoint picker.

Add it with **Add Component → Malbers → Quest Forge → Controller → UI Navigation Group** on the parent of the buttons. A **UI Navigation Coordinator** on the canvas rebuilds every group once per frame when their contents change (the Controller & UI tab adds one where it is missing).

#### Inspector Properties

| Property                            | Type                         | Description                                                                                                                                                                            |
| ----------------------------------- | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Axis**                            | Vertical / Horizontal / Grid | How the children are linked.                                                                                                                                                           |
| **Wrap**                            | bool                         | Wrap from the last element back to the first. Default: off.                                                                                                                            |
| **Columns**                         | int                          | Grid only: number of columns. Default: 1.                                                                                                                                              |
| **Include Inactive**                | bool                         | Include inactive children when collecting. Default: off.                                                                                                                               |
| **Escape Up / Down / Left / Right** | Selectable                   | Where navigation goes when it leaves the group's edge (for example from a toggle grid up to a row of preset buttons). Empty stops at the edge. Hidden or disabled targets are skipped. |

For read-only lists that have no buttons (the Reputation screen), the **Stick Scroll** component scrolls a ScrollRect with the left stick while its screen is on top.

| Property          | Type               | Description                                                                                         |
| ----------------- | ------------------ | --------------------------------------------------------------------------------------------------- |
| **Scroll**        | ScrollRect         | The ScrollRect to scroll. Found under this object when empty.                                       |
| **Active Screen** | QuestForgeUIScreen | Only scroll while this screen is on top. `NothingOpen` always allows it. Default: `FactionJournal`. |
| **Speed**         | float              | Scroll speed at full stick. Default: 1.5.                                                           |
| **Dead Zone**     | float              | Ignore stick input below this. Default: 0.2.                                                        |

***

### Adding Your Own Screen

To make your own panel behave like a Quest Forge screen:

#### Step 1 — Report it

When the panel opens, push it on the stack. Pass `false` for `blocksGameplay` if the character should keep moving.

```csharp
QuestForgeUIStateCoordinator.Instance?.Open(QuestForgeUIScreen.Custom);
// …when it closes:
QuestForgeUIStateCoordinator.Instance?.Close(QuestForgeUIScreen.Custom);
```

#### Step 2 — Trap focus

```csharp
QuestForgeUIFocusController.Instance?.PushContext(panelRoot, firstButton, true);
// …when it closes:
QuestForgeUIFocusController.Instance?.PopContext();
```

#### Step 3 — Close on B

Listen to the router and act only when your screen is on top:

```csharp
void OnEnable()  => QuestForgeInputRouter.Instance.CommandPerformed += OnCommand;
void OnDisable() { if (QuestForgeInputRouter.Instance != null) QuestForgeInputRouter.Instance.CommandPerformed -= OnCommand; }

void OnCommand(QuestForgeUICommand command)
{
    if (command != QuestForgeUICommand.Cancel) return;
    if (!QuestForgeInputRouter.IsCommandFor(QuestForgeUIScreen.Custom)) return;
    ClosePanel();
}
```

#### Step 4 — Show the selection

Add a **Selection Frame** to the panel, and give the [Prompt Bar](broken://pages/2aadab553939c9656991af974cceee9bba254e04#prompt-bar) a profile for `Custom` if you want prompts.

***

### Public API

```csharp
// QuestForgeUIStateCoordinator
QuestForgeUIStateCoordinator coord = QuestForgeUIStateCoordinator.Instance;
coord.Open(QuestForgeUIScreen screen, bool blocksGameplay = true);
coord.Close(QuestForgeUIScreen screen);
coord.CloseAll();
bool open = coord.IsOpen(QuestForgeUIScreen.WorldMap);
QuestForgeUIScreen top = coord.CurrentState;               // NothingOpen when empty
IReadOnlyList<QuestForgeUIScreen> stack = coord.OpenScreens; // bottom first
bool blocking = coord.BlocksGameplay;
coord.Changed += (previous, current) => { };

// QuestForgeInputRouter (screen-aware checks for command handlers)
bool mine = QuestForgeInputRouter.IsCommandFor(QuestForgeUIScreen.Custom);
QuestForgeUIScreen owner = QuestForgeInputRouter.CommandScreen;
bool blocked = QuestForgeInputRouter.CommandBlocksGameplay;

// QuestForgeUIFocusController
var focus = QuestForgeUIFocusController.Instance;
focus.PushContext(GameObject root, Selectable firstSelection, bool trap = true);
focus.PopContext();
focus.RestoreFocus(QuestForgeUIScreen.Journal);
focus.RegisterContext(QuestForgeUIScreen.Custom, root, first);

// QuestForgeGameplayInputBlocker
bool isBlocking = blocker.IsBlocking;
blocker.RestoreNow(); // re-enable what it switched off

// QuestForgeSelectionFrame
QuestForgeSelectionFrame.Ensure(RectTransform scope, Color color);
```

***

### Notes

* **Without the controller managers** (no Input Router, coordinator or focus controller in the scene), every screen still works with mouse and keyboard. The controller parts simply do nothing.
* **Controller Managed.** The waypoint picker, fast travel confirmation, map filters and Controls panel each have a **Controller Managed** toggle (default on). Turn it off to keep that panel pointer-only.
* **Screen state is not saved.** `CloseAll()` clears the stack, for example on a hard UI reset.
