SwiftlyS2

SelectorMenuOption

Class SelectorMenuOption

Namespace: SwiftlyS2.Core.Menus.OptionsBase

Assembly: SwiftlyS2.CS2.dll

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.

public sealed class SelectorMenuOption<T> : MenuOptionBase, IMenuOption, IDisposable
Type Parameters
  • T — The type of the choices.

Inheritance

Implements

Inherited Members

Constructors

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

Creates an instance of SwiftlyS2.Core.Menus.OptionsBase.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
  • choices IEnumerable<T> — The list of available choices.
  • defaultIndex int — The default selected index. Defaults to 0.
  • displayFormatter Func<T, string>? — A function to format each choice for display. Defaults to ToString().
  • itemMaxWidth float — The maximum width for each choice item. Defaults to 10.
  • updateIntervalMs int — The interval in milliseconds between text animation updates. Defaults to 120ms.
  • pauseIntervalMs int — The pause duration in milliseconds before starting the next animation cycle. Defaults to 1000ms.
Remarks

When using this constructor, the SwiftlyS2.Core.Menus.OptionsBase.MenuOptionBase.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 SwiftlyS2.Core.Menus.OptionsBase.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
  • text string — The label text to display.
  • choices IEnumerable<T> — The list of available choices.
  • defaultIndex int — The default selected index. Defaults to 0.
  • displayFormatter Func<T, string>? — A function to format each choice for display. Defaults to ToString().
  • itemMaxWidth float — The maximum width for each choice item. Defaults to 10.
  • updateIntervalMs int — The interval in milliseconds between text animation updates. Defaults to 120ms.
  • pauseIntervalMs int — The 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
  • player IPlayer — The player requesting the display text.
  • displayLine int — The display line index of the option.
Returns
  • string — The formatted display text for the option.
Remarks
  • When LineCount=1: The displayLine parameter is not needed; return the HTML-formatted string directly.
    • displayLine=0: Return all content
    • displayLine=1: Return only the first line content
    • displayLine=2: Return only the second line content
    • And so on...

GetSelectedChoice(IPlayer)

Gets the currently selected choice for the specified player.

public T? GetSelectedChoice(IPlayer player)
Parameters
  • player IPlayer — The 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
  • player IPlayer — The player whose selection to retrieve.
Returns
  • int — 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
  • player IPlayer — The player whose selection to set.
  • index int — The 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
Event Type

On this page