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

IMenuBuilder

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

Fluent construction of a menu.

View source

Methods

Add(IMenuComponent)

Appends a component to the body.

IMenuBuilder Add(IMenuComponent component)
Parameters
Returns
This builder.

AddFooter(IMenuComponent)

Appends a component to the footer.

IMenuBuilder AddFooter(IMenuComponent component)
Parameters
Returns
This builder.

AddHeader(IMenuComponent)

Appends a component to the header.

IMenuBuilder AddHeader(IMenuComponent component)
Parameters
Returns
This builder.

Build()

Builds the menu.

IMenu Build()
Returns
The built menu.

WithAction(MenuActionDescriptor)

Declares an action available in this menu.

IMenuBuilder WithAction(MenuActionDescriptor descriptor)
Parameters
Returns
This builder.

Declaring an action whose name matches a built-in traversal action rebinds that action for this menu only.

WithAction(string, MenuKey, string?)

Declares an action available in this menu, in the menu's own scope.

IMenuBuilder WithAction(string name, MenuKey defaultKey, string? label = null)
Parameters
  • namestringThe action name.
  • defaultKeyMenuKeyThe key to use when nothing overrides it.
  • labelstring?optionalThe footer label, or null to use the name.
Returns
This builder.

WithAction(string, MenuKey, Func<MenuActionContext, ValueTask>, string?)

Declares an action and gives it a menu-level handler, independent of whatever is focused.

IMenuBuilder WithAction(string name, MenuKey defaultKey, Func<MenuActionContext, ValueTask> handler, string? label = null)
Parameters
  • namestringThe action name.
  • defaultKeyMenuKeyThe key to use when nothing overrides it.
  • handlerFunc<MenuActionContext, ValueTask>Runs when the key is pressed and the focused component does not take the action over.
  • labelstring?optionalThe footer label, or null to use the name.
Returns
This builder.

For a key that does something regardless of which row is selected — an extra shortcut alongside navigation and select, rather than a component's own reaction to being activated. The focused component is still offered the action first, through MenuActionContext), so declaring this under an existing action's name (such as "Select" ) only runs the handler when nothing else claims that press.

WithAutoClose(TimeSpan?)

Closes an idle session automatically after a delay.

IMenuBuilder WithAutoClose(TimeSpan? delay)
Parameters
  • delayTimeSpan?How long a session may sit idle before it closes, or null to disable.
Returns
This builder.

Counted from when the session opens, not from the last input. Disabled by default.

WithInputMethod(MenuInputMethod)

Chooses how players interact with this menu.

IMenuBuilder WithInputMethod(MenuInputMethod inputMethod)
Parameters
Returns
This builder.

Defaults to Chat for menus drawn by Chat and Buttons for every other renderer.

WithInputMethodSource(IMenuInputMethodSource)

Adds a source of input method overrides for this menu.

IMenuBuilder WithInputMethodSource(IMenuInputMethodSource source)
Parameters
Returns
This builder.

Use this to enforce an input method from a plugin's own configuration. The server-wide configuration still wins, since it registers at a higher priority.

WithItemsPerPage(int)

Sets the largest number of body entries shown at once.

IMenuBuilder WithItemsPerPage(int itemsPerPage)
Parameters
  • itemsPerPageintThe page size. Must be at least one.
Returns
This builder.

An upper bound, not a guarantee. The server-wide line budget can cut the page down further, so entries that draw more than one line — spacers, multi-line components — leave room for fewer neighbours. This is what keeps the last entries of a long menu reachable instead of pushing them off screen.

WithKeybindSource(IMenuKeybindSource)

Adds a source of key overrides for this menu.

IMenuBuilder WithKeybindSource(IMenuKeybindSource source)
Parameters
Returns
This builder.

Use this to bind actions from a plugin's own configuration. The server-wide configuration still wins, since it registers at a higher priority.

WithParent(IMenu)

Sets the menu returned to when this one closes.

IMenuBuilder WithParent(IMenu parent)
Parameters
  • parentIMenuThe parent menu.
Returns
This builder.

WithRenderer(string)

Chooses the renderer this menu draws through.

IMenuBuilder WithRenderer(string rendererId)
Parameters
  • rendererIdstringThe registered renderer id.
Returns
This builder.

Defaults to CenterHtml. Building throws when the id is not registered.

WithRendererSource(IMenuRendererSource)

Adds a source of renderer overrides for this menu.

IMenuBuilder WithRendererSource(IMenuRendererSource source)
Parameters
Returns
This builder.

Use this to enforce a renderer from a plugin's own configuration. The server-wide configuration still wins, since it registers at a higher priority.

WithTitle(string)

Adds a title line to the header.

IMenuBuilder WithTitle(string title)
Parameters
Returns
This builder.