SwiftlyS2

ToggleMenuOption

Class ToggleMenuOption

Namespace: SwiftlyS2.Core.Menus.OptionsBase

Assembly: SwiftlyS2.CS2.dll

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

public sealed class ToggleMenuOption : MenuOptionBase, IMenuOption, IDisposable

Inheritance

Implements

Inherited Members

Constructors

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

Creates an instance of SwiftlyS2.Core.Menus.OptionsBase.ToggleMenuOption with dynamic text updating capabilities.

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

When using this constructor, the SwiftlyS2.Core.Menus.OptionsBase.MenuOptionBase.Text property must be manually set to specify the initial text.

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

Creates an instance of SwiftlyS2.Core.Menus.OptionsBase.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
  • text string — The text content to display.
  • defaultToggleState bool — The default toggle state for new players. Defaults to true.
  • toggleOnSymbol string? — The HTML symbol to display when toggle is on. Defaults to green checkmark.
  • toggleOffSymbol string? — The HTML symbol to display when toggle is off. Defaults to red X mark.
  • updateIntervalMs int — The interval in milliseconds between text updates. Defaults to 120ms.
  • pauseIntervalMs int — The 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
  • player IPlayer — The player viewing the option.
  • displayLine int — The display line number (not used in this implementation).
Returns
  • string — The formatted display text with toggle state indicator.

GetToggleState(IPlayer)

Gets the toggle state for the specified player.

public bool GetToggleState(IPlayer player)
Parameters
  • player IPlayer — The player whose toggle state to retrieve.
Returns
  • bool — 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
  • player IPlayer — The player whose toggle state to set.
  • value bool — The toggle state to set.
Returns
  • bool — 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
Event Type

On this page