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

ToggleMenuOption

Class
Namespace: SwiftlyS2.Core.Menus.OptionsBase · Assembly: SwiftlyS2.CS2.dll
public sealed class ToggleMenuOption : MenuOptionBase, IMenuOption, IDisposable

Represents a toggleable menu option that displays an on/off state.

View source

Constructors

ToggleMenuOption(bool, string?, string?, int, int)

Creates an instance of ToggleMenuOption with dynamic text updating capabilities.

public ToggleMenuOption(bool defaultToggleState = true, string? toggleOnSymbol = null, string? toggleOffSymbol = null, int updateIntervalMs = 120, int pauseIntervalMs = 1000)
Parameters
  • defaultToggleStatebooloptionalThe default toggle state for new players. Defaults to true.
  • toggleOnSymbolstring?optionalThe HTML symbol to display when toggle is on. Defaults to green checkmark.
  • toggleOffSymbolstring?optionalThe HTML symbol to display when toggle is off. Defaults to red X mark.
  • updateIntervalMsintoptionalThe interval in milliseconds between text updates. Defaults to 120ms.
  • pauseIntervalMsintoptionalThe pause duration in milliseconds before starting the next text update cycle. Defaults to 1000ms.

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

ToggleMenuOption(string, bool, string?, string?, int, int)

Creates an instance of ToggleMenuOption with dynamic text updating capabilities.

public ToggleMenuOption(string text, bool defaultToggleState = true, string? toggleOnSymbol = null, string? toggleOffSymbol = null, int updateIntervalMs = 120, int pauseIntervalMs = 1000)
Parameters
  • textstringThe text content to display.
  • defaultToggleStatebooloptionalThe default toggle state for new players. Defaults to true.
  • toggleOnSymbolstring?optionalThe HTML symbol to display when toggle is on. Defaults to green checkmark.
  • toggleOffSymbolstring?optionalThe HTML symbol to display when toggle is off. Defaults to red X mark.
  • updateIntervalMsintoptionalThe interval in milliseconds between text updates. Defaults to 120ms.
  • pauseIntervalMsintoptionalThe pause duration in milliseconds before starting the next text update cycle. Defaults to 1000ms.

Methods

GetDisplayText(IPlayer, int)

Gets the display text for this option, including the toggle state indicator.

public override string GetDisplayText(IPlayer player, int displayLine = 0)
Parameters
  • playerIPlayerThe player viewing the option.
  • displayLineintoptionalThe display line number (not used in this implementation).
Returns
The formatted display text with toggle state indicator.

GetToggleState(IPlayer)

Gets the toggle state for the specified player.

public bool GetToggleState(IPlayer player)
Parameters
  • playerIPlayerThe player whose toggle state to retrieve.
Returns
True if toggled on, false if toggled off. Uses the configured default value for new players.

SetToggleState(IPlayer, bool)

Sets the toggle state for the specified player and triggers the value changed event.

public bool SetToggleState(IPlayer player, bool value)
Parameters
  • playerIPlayerThe player whose toggle state to set.
  • valueboolThe toggle state to set.
Returns
True if the value was changed, false if it was already the same value.

ValueChanged

Event triggered when the toggle value changes for a player.

public event EventHandler<MenuOptionValueChangedEventArgs<bool>>? ValueChanged
Value
EventHandler<MenuOptionValueChangedEventArgs<bool>>?