API Reference › Menus.OptionsBase
ToggleMenuOption
ClassNamespace: SwiftlyS2.Core.Menus.OptionsBase · Assembly: SwiftlyS2.CS2.dll
public sealed class ToggleMenuOption : MenuOptionBase, IMenuOption, IDisposableRepresents a toggleable menu option that displays an on/off state.
View sourceConstructors
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.
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
Gets the display text for this option, including the toggle state indicator.
public override string GetDisplayText(IPlayer player, int displayLine = 0)Parameters
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.
Sets the toggle state for the specified player and triggers the value changed event.
public bool SetToggleState(IPlayer player, bool value)Event triggered when the toggle value changes for a player.
public event EventHandler<MenuOptionValueChangedEventArgs<bool>>? ValueChangedValue