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

SubmenuComponent

Class
Namespace: SwiftlyS2.Shared.Menu.Components · Assembly: SwiftlyS2.CS2.dll
public class SubmenuComponent : TextComponent, IMenuComponent

A selectable line that opens another menu.

The submenu is produced by a factory rather than held directly, so it can be built lazily from the state of the player opening it. Closing the submenu returns the player here: a menu that has no parent of its own is adopted by this one when it opens.

View source

Constructors

SubmenuComponent(string, IMenu, string?)

Creates a submenu entry from an already built menu.

public SubmenuComponent(string text, IMenu submenu, string? id = null)
Parameters
  • textstringThe label to display.
  • submenuIMenuThe menu to open.
  • idstring?optionalA stable id, or null to generate one.

SubmenuComponent(string, Func<IMenuSession, IMenu?>, string?)

Creates a submenu entry from a factory.

public SubmenuComponent(string text, Func<IMenuSession, IMenu?> factory, string? id = null)
Parameters
  • textstringThe label to display.
  • factoryFunc<IMenuSession, IMenu?>Produces the menu to open. Returning null cancels the navigation.
  • idstring?optionalA stable id, or null to generate one.

SubmenuComponent(string, Func<IMenuSession, ValueTask<IMenu?>>, string?)

Creates a submenu entry from an asynchronous factory.

public SubmenuComponent(string text, Func<IMenuSession, ValueTask<IMenu?>> factory, string? id = null)
Parameters

Properties

FocusedColor

The colour applied when the entry is focused, or null to keep Style.

public string? FocusedColor { get; set; }
Property Value

IsFocusable

Whether the selection can land on this component.

public override bool IsFocusable { get; }
Property Value

A label can hold the selection like any other body entry, so a menu scrolls past it rather than skipping over it, but it never overrides MenuActionContext) so activating it is always a no-op.

Methods

HandleActionAsync(MenuActionContext)

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

public override 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.

ResolveStyle(IMenuComponentRenderContext)

Resolves the style to draw with, accounting for the disabled state.

protected override MenuTextStyle ResolveStyle(IMenuComponentRenderContext context)
Parameters
Returns
The style to use.