swiftlys2/docs/api/ai/
API Reference › Menu

IMenuSession

Interface
Namespace: SwiftlyS2.Shared.Menu · Assembly: SwiftlyS2.CS2.dll
public interface IMenuSession

One player's live view of an open menu.

Every piece of state that varies per player lives here rather than on the menu or its components, which is what allows one component instance to be shared across menus and players.

View source

Properties

FocusedComponent

The focused component, or null when the menu has nothing focusable.

IMenuComponent? FocusedComponent { get; }
Property Value

FocusedIndex

The index of the focused component within the visible focusable body components.

int FocusedIndex { get; }
Property Value

IsOpen

Whether this session is still open.

bool IsOpen { get; }
Property Value

Menu

The menu being viewed.

IMenu Menu { get; }
Property Value

Player

The player viewing the menu.

IPlayer Player { get; }
Property Value

Methods

CaptureChat(Func<string, bool>)

Routes this player's next chat messages to a handler instead of the chat.

IDisposable CaptureChat(Func<string, bool> onMessage)
Parameters
  • onMessageFunc<string, bool>Receives each message. Returning true swallows it so it never reaches the chat; returning false lets it through untouched.
Returns
A handle that stops the capture when disposed.

Only one capture is active per session; starting a second one replaces the first. The capture is dropped automatically when the menu closes or the player disconnects, so a component only needs to dispose the handle when it finishes early.

Close()

Closes this session, returning the player to the parent menu when there is one.

void Close()

GetState<TState>(IMenuComponent)

Gets this player's state for a component, creating it on first use.

TState GetState<TState>(IMenuComponent component) where TState : class, new()
Parameters
Returns
TState
The per-player state instance.

Invalidate()

Marks this session as needing a redraw on the next tick.

void Invalidate()

Call this after changing anything that affects what the player sees. Frames are only sent when a session is invalidated, so forgetting this leaves the display stale.

MoveFocus(int)

Moves the selection by a number of entries, wrapping at both ends.

bool MoveFocus(int delta)
Parameters
  • deltaintHow far to move. Negative moves towards the top.
Returns
true when the selection changed.

SetFocus(int)

Moves the selection to a specific entry.

bool SetFocus(int index)
Parameters
  • indexintThe index among visible focusable body components.
Returns
true when the index was valid and the selection changed.

SetState<TState>(IMenuComponent, TState)

Replaces this player's state for a component.

void SetState<TState>(IMenuComponent component, TState state) where TState : class
Parameters
  • componentIMenuComponentThe component the state belongs to.
  • stateTStateThe state to store.