SwiftlyS2

IMenuOption

Interface IMenuOption

Namespace: SwiftlyS2.Shared.Menus

Assembly: SwiftlyS2.CS2.dll

Represents a menu option that can be displayed and interacted with by players.

public interface IMenuOption : IDisposable

Implements

Properties

CloseAfterClick

Gets a value indicating whether the menu should be closed after handling the click.

bool CloseAfterClick { get; }
Property Value

Comment

Gets or sets the comment content displayed for this menu option.

string Comment { get; set; }
Property Value
Remarks

This is a global property. Changing it will affect what all players see.

Enabled

Gets or sets a value indicating whether this option can be interacted with.

bool Enabled { get; set; }
Property Value
Remarks

This is a global property. Changing it will affect what all players see.

LineCount

Gets the number of lines this option requests to occupy in the menu.

int LineCount { get; }
Property Value

MaxWidth

The maximum display width for menu option text in relative units.

float MaxWidth { get; set; }
Property Value

Gets the menu that this option belongs to.

IMenuAPI? Menu { get; }
Property Value
Remarks

This property will be null until the option is added to a menu via SwiftlyS2.Shared.Menus.IMenuAPI.AddOption(SwiftlyS2.Shared.Menus.IMenuOption). When implementing custom menu options, avoid accessing this property in the constructor as it will not be set yet.

PlaySound

Gets or sets a value indicating whether a sound should play when this option is selected.

bool PlaySound { get; set; }
Property Value

Tag

Gets or sets an object that contains data about this option.

object? Tag { get; set; }
Property Value

Text

Gets or sets the text content displayed for this menu option.

string Text { get; set; }
Property Value
Remarks

This is a global property. Changing it will affect what all players see.

TextSize

Gets or sets the text size for this option.

MenuOptionTextSize TextSize { get; set; }
Property Value

TextStyle

Gets or sets the text overflow style for this option.

MenuOptionTextStyle TextStyle { get; set; }
Property Value

Visible

Gets or sets a value indicating whether this option is visible in the menu.

bool Visible { get; set; }
Property Value
Remarks

This is a global property. Changing it will affect what all players see.

Methods

GetDisplayText(IPlayer, int)

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

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...

GetEnabled(IPlayer)

Determines whether this option is enabled for the specified player.

bool GetEnabled(IPlayer player)
Parameters
  • player IPlayer — The player to check enabled state for.
Returns
  • bool — True if the option is enabled for the player, otherwise, false.

GetVisible(IPlayer)

Determines whether this option is visible to the specified player.

bool GetVisible(IPlayer player)
Parameters
  • player IPlayer — The player to check visibility for.
Returns
  • bool — True if the option is visible to the player, otherwise, false.

IsClickTaskCompleted(IPlayer)

Determines whether the click task for the specified player is completed.

bool IsClickTaskCompleted(IPlayer player)
Parameters
  • player IPlayer — The player to check.
Returns
  • bool — True if the click task is completed; otherwise, false.

OnClickAsync(IPlayer)

Handles the click action for this option.

ValueTask OnClickAsync(IPlayer player)
Parameters
  • player IPlayer — The player who clicked the option.
Returns
  • ValueTask — A task that represents the asynchronous operation.

OnValidatingAsync(IPlayer)

Validates whether the specified player can interact with this option.

ValueTask<bool> OnValidatingAsync(IPlayer player)
Parameters
  • player IPlayer — The player to validate.
Returns
  • ValueTask<bool> — A task that represents the asynchronous operation. The task result is true if validation succeeds; otherwise, false.

SetEnabled(IPlayer, bool)

Sets the enabled state of this option for a specific player.

void SetEnabled(IPlayer player, bool enabled)
Parameters
  • player IPlayer — The player to set enabled state for.
  • enabled bool — True to enable the option for the player; false to disable it.
Remarks

The per-player enabled state has lower priority than the global SwiftlyS2.Shared.Menus.IMenuOption.Enabled property.

SetVisible(IPlayer, bool)

Sets the visibility of this option for a specific player.

void SetVisible(IPlayer player, bool visible)
Parameters
  • player IPlayer — The player to set visibility for.
  • visible bool — True to make the option visible to the player; false to hide it.
Remarks

The per-player visibility has lower priority than the global SwiftlyS2.Shared.Menus.IMenuOption.Visible property.

AfterFormat

Occurs after HTML markup is assembled, allowing customization of the final HTML output.

event EventHandler<MenuOptionFormattingEventArgs>? AfterFormat
Event Type

BeforeFormat

Occurs before HTML markup is assembled, allowing customization of the text content.

event EventHandler<MenuOptionFormattingEventArgs>? BeforeFormat
Event Type

Click

Occurs when the option is clicked by a player.

event AsyncEventHandler<MenuOptionClickEventArgs>? Click
Event Type

EnabledChanged

Occurs when the enabled state of the option changes.

event EventHandler<MenuOptionEventArgs>? EnabledChanged
Event Type

TextChanged

Occurs when the text of the option changes.

event EventHandler<MenuOptionEventArgs>? TextChanged
Event Type

Validating

Occurs before a SwiftlyS2.Shared.Menus.IMenuOption.Click event is processed, allowing validation and cancellation.

event EventHandler<MenuOptionValidatingEventArgs>? Validating
Event Type

VisibilityChanged

Occurs when the visibility of the option changes.

event EventHandler<MenuOptionEventArgs>? VisibilityChanged
Event Type

On this page