swiftlys2/docs/api/ai/
API Reference › Menu.Components

TextComponent

Class
Namespace: SwiftlyS2.Shared.Menu.Components · Assembly: SwiftlyS2.CS2.dll
public class TextComponent : MenuComponentBase, IMenuComponent

A line of text that can be scrolled to but never does anything when activated.

The text may be fixed or produced per player through TextProvider, which is evaluated on every frame. Text wider than MaxWidth is truncated or scrolled according to Overflow, independently for every player looking at it.

View source

Constructors

TextComponent(string, string?)

Creates a text component with fixed text.

public TextComponent(string text = "", string? id = null)
Parameters
  • textstringoptionalThe text to display.
  • idstring?optionalA stable id, or null to generate one.

Properties

DisabledColor

The colour applied when the component is disabled, or null to keep Style.

public string? DisabledColor { get; set; }
Property Value

IsFocusable

Whether the selection can land on this component.

public override bool IsFocusable { get; }
Property Value

A label can hold the selection like any other body entry, so a menu scrolls past it rather than skipping over it, but it never overrides MenuActionContext) so activating it is always a no-op.

MaxWidth

The width the text is fitted into.

public float MaxWidth { get; set; }
Property Value

Measured with String), so it is a weighted width rather than a character count. Values below one turn fitting off.

Overflow

What happens to text wider than MaxWidth.

public MenuTextOverflow Overflow { get; set; }
Property Value

PauseIntervalMs

How long a scrolling animation rests at the end of a cycle, in milliseconds. Never below 15.

public int PauseIntervalMs { get; set; }
Property Value

Style

Presentation hints applied to the text.

public MenuTextStyle Style { get; set; }
Property Value

Text

The text shown when TextProvider is null or returns null.

public string Text { get; set; }
Property Value

TextProvider

Produces the text per player. Returning null falls back to Text.

public Func<IMenuSession, string?>? TextProvider { get; set; }
Property Value

UpdateIntervalMs

How often a scrolling animation advances, in milliseconds. Never below 15.

public int UpdateIntervalMs { get; set; }
Property Value

Methods

NeedsRedraw(IMenuSession, DateTime)

Whether this component needs a new frame even though nothing invalidated the session.

public override bool NeedsRedraw(IMenuSession session, DateTime now)
Parameters
Returns
true to redraw on this tick.

Asked once per tick for every visible component of an otherwise clean session, so keep the check cheap. Animated text and live values are what this exists for.

RawText(IMenuSession)

Resolves the text to display for a session without fitting it.

protected string RawText(IMenuSession session)
Parameters
Returns
The unfitted text.

Render(IMenuComponentRenderContext)

Produces this component's renderer-agnostic output.

public override MenuNode Render(IMenuComponentRenderContext context)
Parameters
Returns
The nodes describing this component.

RenderWaiting(IMenuComponentRenderContext)

Produces the placeholder shown while an activation is still running.

protected MenuNode? RenderWaiting(IMenuComponentRenderContext context)
Parameters
Returns
The placeholder node, or null when nothing is running.

Components that build their own node tree should return this first when it is not null, so a slow callback is visible to the player rather than looking like a dead key.

ResolveStyle(IMenuComponentRenderContext)

Resolves the style to draw with, accounting for the disabled state.

protected virtual MenuTextStyle ResolveStyle(IMenuComponentRenderContext context)
Parameters
Returns
The style to use.

ResolveText(IMenuSession)

Resolves the text to display for a session, fitted to MaxWidth.

protected string ResolveText(IMenuSession session)
Parameters
Returns
The resolved text.