MenuOptionBase
Classpublic abstract class MenuOptionBase : IMenuOption, IDisposableProvides a base implementation for menu options with event-driven behavior.
Constructors
Creates an instance of MenuOptionBase.
protected MenuOptionBase()Using the parameterless constructor will not enable dynamic text updating features. Derived classes should override the Int32) method to implement custom text style changes.
Creates an instance of MenuOptionBase with dynamic text updating capabilities.
protected MenuOptionBase(int updateIntervalMs, int pauseIntervalMs)Values less than 1/64f*1000 milliseconds (approximately 15.6ms) are meaningless, as the refresh rate would be higher than the game's frame interval. Both parameters will be automatically clamped to this minimum value.
Properties
Gets or sets a function that dynamically provides the text content for this menu option.
public Func<string?>? BindingText { get; set; }When this property is set to a non-null function, the Text property's getter will invoke it to retrieve the current text value on each access. This enables automatic tracking of external string sources. The function can return null to indicate that it wants to fall back to the static Text value, or return an empty string to display nothing. Setting this property to null will revert to using only the static Text value stored in the backing field. Example usage: string myText = "Hello"; option.BindingText = () => myText; myText = "World"; // option.Text now returns "World" // Return null to use fallback Text option.BindingText = () => condition ? playerName : null;
Gets or sets a value indicating whether the menu should be closed after handling the click.
public bool CloseAfterClick { get; init; }Gets or sets the comment content displayed for this menu option.
public string Comment { get; set; }This is a global property. Changing it will affect what all players see.
Gets or sets a value indicating whether this option can be interacted with.
public bool Enabled { get; set; }This is a global property. Changing it will affect what all players see.
Gets the number of lines this option requests to occupy in the menu.
public virtual int LineCount { get; }The maximum display width for menu option text in relative units.
public float MaxWidth { get; set; }Gets or sets the menu that this option belongs to.
public IMenuAPI? Menu { get; }This property will be null until the option is added to a menu via IMenuOption). When implementing custom menu options, avoid accessing this property in the constructor as it will not be set yet.
Gets or sets a value indicating whether a sound should play when this option is selected.
public bool PlaySound { get; set; }Gets or sets an object that contains data about this option.
public object? Tag { get; set; }Gets or sets the text content displayed for this menu option.
public string Text { get; set; }This is a global property. Changing it will affect what all players see. When BindingText is set to a non-null function, the getter will invoke that function to retrieve the current text value dynamically. If the function returns null, it falls back to this property's static value. Otherwise, it returns the static value stored in the backing field. Setting this property directly will update the static fallback value without clearing any BindingText binding. This allows BindingText and static text to coexist, with BindingText taking priority. The function is allowed to return an empty string, which will be displayed as-is.
Gets or sets the text size for this option.
public MenuOptionTextSize TextSize { get; set; }Gets or sets the text overflow style for this option.
public MenuOptionTextStyle TextStyle { get; set; }Gets or sets a value indicating whether this option is visible in the menu.
public bool Visible { get; set; }This is a global property. Changing it will affect what all players see.
Methods
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public virtual void Dispose()Gets the display text for this option as it should appear to the specified player.
public virtual string GetDisplayText(IPlayer player, int displayLine = 0)When a menu option occupies multiple lines, MenuAPI may only need to display a specific line of that option. When LineCount=1 : The displayLine parameter is not needed; return the HTML-formatted string directly. When LineCount>=2 : Check the displayLine parameter: displayLine=0 : Return all content displayLine=1 : Return only the first line content displayLine=2 : Return only the second line content And so on... Note: MenuAPI ensures that the displayLine parameter will not exceed the option's LineCount .
Determines whether this option is enabled for the specified player.
public virtual bool GetEnabled(IPlayer player)- playerIPlayerThe player to check enabled state for.
Determines whether this option is visible to the specified player.
public virtual bool GetVisible(IPlayer player)- playerIPlayerThe player to check visibility for.
Determines whether the click task for the specified player is completed.
public virtual bool IsClickTaskCompleted(IPlayer player)- playerIPlayerThe player to check.
Handles the click action for this option.
public virtual ValueTask OnClickAsync(IPlayer player)- playerIPlayerThe player who clicked the option.
Validates whether the specified player can interact with this option.
public virtual ValueTask<bool> OnValidatingAsync(IPlayer player)- playerIPlayerThe player to validate.
Sets the enabled state of this option for a specific player.
public virtual void SetEnabled(IPlayer player, bool enabled)The per-player enabled state has lower priority than the global Enabled property.
Sets the visibility of this option for a specific player.
public virtual void SetVisible(IPlayer player, bool visible)The per-player visibility has lower priority than the global Visible property.
Occurs after HTML markup is assembled, allowing customization of the final HTML output.
public event EventHandler<MenuOptionFormattingEventArgs>? AfterFormatOccurs before HTML markup is assembled, allowing customization of the text content.
public event EventHandler<MenuOptionFormattingEventArgs>? BeforeFormatOccurs when the option is clicked by a player.
public event AsyncEventHandler<MenuOptionClickEventArgs>? ClickOccurs when the enabled state of the option changes.
public event EventHandler<MenuOptionEventArgs>? EnabledChangedOccurs when the text of the option changes.
public event EventHandler<MenuOptionEventArgs>? TextChangedOccurs before a click is processed, allowing validation and cancellation.
public event EventHandler<MenuOptionValidatingEventArgs>? ValidatingOccurs when the visibility of the option changes.
public event EventHandler<MenuOptionEventArgs>? VisibilityChanged