swiftlys2/docs/api/ai/
API Reference Menus.OptionsBase

SelectorMenuOption`1

Class
Namespace: SwiftlyS2.Core.Menus.OptionsBase · Assembly: SwiftlyS2.CS2.dll
public sealed class SelectorMenuOption<T> : MenuOptionBase, IMenuOption, IDisposable

Represents a selector menu option that allows cycling through a list of choices using left/right keys. Displays as: Label: PrevChoice [CurrentChoice] NextChoice This option claims the Exit and Use keys for previous and next selection respectively.

View source

Constructors

SelectorMenuOption(IEnumerable<T>, int, Func<T, string>?, float, int, int)

Creates an instance of SelectorMenuOption%601.

public SelectorMenuOption(IEnumerable<T> choices, int defaultIndex = 0, Func<T, string>? displayFormatter = null, float itemMaxWidth = 10, int updateIntervalMs = 120, int pauseIntervalMs = 1000)
Parameters
  • choicesIEnumerable<T>The list of available choices.
  • defaultIndexintoptionalThe default selected index. Defaults to 0.
  • displayFormatterFunc<T, string>?optionalA function to format each choice for display. Defaults to ToString().
  • itemMaxWidthfloatoptionalThe maximum width for each choice item. Defaults to 10.
  • updateIntervalMsintoptionalThe interval in milliseconds between text animation updates. Defaults to 120ms.
  • pauseIntervalMsintoptionalThe pause duration in milliseconds before starting the next animation cycle. Defaults to 1000ms.

When using this constructor, the Text property must be manually set to specify the label.

SelectorMenuOption(string, IEnumerable<T>, int, Func<T, string>?, float, int, int)

Creates an instance of SelectorMenuOption%601.

public SelectorMenuOption(string text, IEnumerable<T> choices, int defaultIndex = 0, Func<T, string>? displayFormatter = null, float itemMaxWidth = 10, int updateIntervalMs = 120, int pauseIntervalMs = 1000)
Parameters
  • textstringThe label text to display.
  • choicesIEnumerable<T>The list of available choices.
  • defaultIndexintoptionalThe default selected index. Defaults to 0.
  • displayFormatterFunc<T, string>?optionalA function to format each choice for display. Defaults to ToString().
  • itemMaxWidthfloatoptionalThe maximum width for each choice item. Defaults to 10.
  • updateIntervalMsintoptionalThe interval in milliseconds between text animation updates. Defaults to 120ms.
  • pauseIntervalMsintoptionalThe pause duration in milliseconds before starting the next animation cycle. Defaults to 1000ms.

Properties

Choices

Gets the available choices for this selector.

public IReadOnlyList<T> Choices { get; init; }
Property Value

WrapAround

Gets or sets whether the selector should wrap around when reaching the end.

public bool WrapAround { get; set; }
Property Value

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public override void Dispose()

GetDisplayText(IPlayer, int)

Gets the display text for this option as it should appear to the specified player.

public override string GetDisplayText(IPlayer player, int displayLine = 0)
Parameters
  • playerIPlayerThe player requesting the display text.
  • displayLineintoptionalThe display line index of the option.
Returns
The formatted display text for the option.

When a menu option occupies multiple lines, MenuAPI may only need to display a specific line of that option. When LineCount=1 : The displayLine parameter is not needed; return the HTML-formatted string directly. When LineCount>=2 : Check the displayLine parameter: displayLine=0 : Return all content displayLine=1 : Return only the first line content displayLine=2 : Return only the second line content And so on... Note: MenuAPI ensures that the displayLine parameter will not exceed the option's LineCount .

GetSelectedChoice(IPlayer)

Gets the currently selected choice for the specified player.

public T? GetSelectedChoice(IPlayer player)
Parameters
  • playerIPlayerThe player whose selection to retrieve.
Returns
T?
The selected choice, or default if no choices available.

GetSelectedIndex(IPlayer)

Gets the currently selected index for the specified player.

public int GetSelectedIndex(IPlayer player)
Parameters
  • playerIPlayerThe player whose selection to retrieve.
Returns
The selected index.

PauseTextAnimation()

Pauses the dynamic text animation.

public override void PauseTextAnimation()

ResumeTextAnimation()

Resumes the dynamic text animation.

public override void ResumeTextAnimation()

SetSelectedIndex(IPlayer, int)

Sets the selected index for the specified player.

public void SetSelectedIndex(IPlayer player, int index)
Parameters
  • playerIPlayerThe player whose selection to set.
  • indexintThe index to select. Will be clamped to valid range.

SelectionChanged

Occurs when the selected choice changes for a player.

public event EventHandler<MenuOptionValueChangedEventArgs<T>>? SelectionChanged
Value
EventHandler<MenuOptionValueChangedEventArgs<T>>?