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

IMenuComponent

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

A reusable unit a menu is built from.

A component owns exactly two things: how it draws, and how it reacts to actions. It owns no per-player state, which is what makes a single instance safe to place in several menus and to show to several players at once. Anything that varies per player belongs in IMenuSession state. Prefer deriving from MenuComponentBase rather than implementing this directly.

View source

Properties

Id

A stable id for this component, unique within its menu.

string Id { get; }
Property Value

IsFocusable

Whether the selection can land on this component.

bool IsFocusable { get; }
Property Value

LineCount

How many lines this component draws.

int LineCount { get; }
Property Value

Used to decide how much of the body fits on one page, without rendering components that will not be shown. It must match what IMenuComponentRenderContext) produces: a MenuBlankNode costs its Lines, a MenuStackNode costs the sum of its children, and everything else costs one. A component that returns a stack has to override this, otherwise it is budgeted as a single line and the page overflows.

PlaySound

Whether activating this component plays the menu's selection sound.

bool PlaySound { get; }
Property Value

Methods

GetHint(IMenuSession)

Produces the hint shown while this component holds the selection.

string? GetHint(IMenuSession session)
Parameters
Returns
The hint text, or null to show nothing.

Use this for a per-entry explanation, or to advertise keys the component takes over through MenuActionContext).

HandleActionAsync(MenuActionContext)

Offers an action to this component before the menu handles it.

ValueTask<bool> HandleActionAsync(MenuActionContext context)
Parameters
Returns
true to consume the action and stop the menu's own handling from running.

Only the focused component is offered actions. Returning true is how a component takes over a key that would otherwise navigate or close the menu.

IsEnabled(IMenuSession)

Whether this component can be interacted with by a player.

bool IsEnabled(IMenuSession session)
Parameters
Returns
true when the component accepts actions.

IsVisible(IMenuSession)

Whether this component is shown to a player.

bool IsVisible(IMenuSession session)
Parameters
Returns
true when the component should be drawn.

NeedsRedraw(IMenuSession, DateTime)

Whether this component needs a new frame even though nothing invalidated the session.

bool NeedsRedraw(IMenuSession session, DateTime now)
Parameters
Returns
true to redraw on this tick.

Asked once per tick for every visible component of an otherwise clean session, so keep the check cheap. Animated text and live values are what this exists for.

Render(IMenuComponentRenderContext)

Produces this component's renderer-agnostic output.

MenuNode Render(IMenuComponentRenderContext context)
Parameters
Returns
The nodes describing this component.