swiftlys2/docs/api/ai/
API Reference Menus

IMenuAPI

Interface
Namespace: SwiftlyS2.Shared.Menus · Assembly: SwiftlyS2.CS2.dll
public interface IMenuAPI : IDisposable
Implements IDisposable

Represents an interactive menu that can be displayed to players.

View source

Properties

Builder

The builder used to construct and configure this menu.

IMenuBuilderAPI? Builder { get; }
Property Value

Configuration

Configuration settings for this menu.

MenuConfiguration Configuration { get; }
Property Value

KeybindOverrides

Keybind overrides for this menu.

MenuKeybindOverrides KeybindOverrides { get; }
Property Value

MenuManager

The menu manager that this menu belongs to.

IMenuManagerAPI MenuManager { get; }
Property Value

OptionScrollStyle

The scroll style for this menu options.

MenuOptionScrollStyle OptionScrollStyle { get; }
Property Value

Options

Read-only collection of all options in this menu.

IReadOnlyList<IMenuOption> Options { get; }
Property Value

Parent

The parent hierarchy information in a hierarchical menu structure.

(IMenuAPI? ParentMenu, IMenuOption? TriggerOption) Parent { get; }

ParentMenu is the parent menu instance, null for top-level menus. TriggerOption is the menu option that triggered this submenu, null for top-level or directly created menus.

Tag

Gets or sets an object that contains data about this menu.

object? Tag { get; set; }
Property Value

Methods

AddOption(IMenuOption)

Adds a new option to this menu.

void AddOption(IMenuOption option)
Parameters

GetCurrentOption(IPlayer)

Gets the menu option currently highlighted by the specified player.

IMenuOption? GetCurrentOption(IPlayer player)
Parameters
  • playerIPlayerThe player whose current selection to retrieve.
Returns
The currently selected option, or null if nothing is selected.

GetCurrentOptionIndex(IPlayer)

Gets the index of the currently highlighted option for the specified player.

int GetCurrentOptionIndex(IPlayer player)
Parameters
  • playerIPlayerThe player whose current selection index to retrieve.
Returns
The index of the currently selected option, or -1 if nothing is selected.

HideForPlayer(IPlayer)

Hides this menu for the specified player by removing its visual display.

void HideForPlayer(IPlayer player)
Parameters
  • playerIPlayerThe player whose menu will be hidden.

This method only hides the menu visually. To properly close a menu (which handles state cleanup, triggering events, and reopening parent menus), use IMenuAPI) instead.

MoveToOption(IPlayer, IMenuOption)

Moves the player's selection to the specified option.

bool MoveToOption(IPlayer player, IMenuOption option)
Parameters
  • playerIPlayerThe player whose selection to move.
  • optionIMenuOptionThe option to move the selection to.
Returns
True if the move was successful, false if the option was not found.

MoveToOptionIndex(IPlayer, int)

Moves the player's selection to the specified option index.

bool MoveToOptionIndex(IPlayer player, int index)
Parameters
  • playerIPlayerThe player whose selection to move.
  • indexintThe index of the option to move the selection to.
Returns
True if the move was successful, false if the index was out of bounds.

RemoveOption(IMenuOption)

Removes an option from this menu.

bool RemoveOption(IMenuOption option)
Parameters
Returns
True if the option was successfully removed, false if the option was not found.

ShowForPlayer(IPlayer)

Shows this menu to the specified player by displaying its content.

void ShowForPlayer(IPlayer player)
Parameters
  • playerIPlayerThe player who will see the menu.

This method only displays the menu visually. To properly open a menu (which handles state management, closing other menus, and triggering events), use IMenuAPI) instead.

OptionHovered

Fired when a different option is hovered.

event EventHandler<MenuEventArgs>? OptionHovered

This event is only fired when the hovered option changes.

OptionHovering

Fired when the selection pointer is hovering over an option.

event EventHandler<MenuEventArgs>? OptionHovering

This event is fired once per render frame.

OptionSelected

Fired when a menu option is selected (activated) by the player.

event EventHandler<MenuEventArgs>? OptionSelected