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

InputComponent

Class
Namespace: SwiftlyS2.Shared.Menu.Components · Assembly: SwiftlyS2.CS2.dll
public class InputComponent : MenuValueComponent<string>, IMenuComponent
Inherits object, MenuComponentBase, TextComponent, MenuValueComponent<string>
Implements IMenuComponent

A selectable line whose value the player types into chat.

Activating starts a chat capture for that player only: the next message they send becomes the value and never reaches the chat. Activating again while waiting cancels.

View source

Constructors

InputComponent(string, string, Func<string, bool>?, Action<MenuValueChangedContext<string>>?, string?)

Creates an input.

public InputComponent(string text = "", string defaultValue = "", Func<string, bool>? validator = null, Action<MenuValueChangedContext<string>>? onChanged = null, string? id = null)
Parameters
  • textstringoptionalThe label to display.
  • defaultValuestringoptionalThe value a player starts with.
  • validatorFunc<string, bool>?optionalDecides whether a typed value is acceptable.
  • onChangedAction<MenuValueChangedContext<string>>?optionalRuns after the value changes.
  • idstring?optionalA stable id, or null to generate one.

Properties

AcceptedColor

The colour of AcceptedText.

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

AcceptedText

The text shown briefly after a value is accepted.

public string AcceptedText { get; set; }
Property Value

EmptyText

The text shown while no value has been entered.

public string EmptyText { get; set; }
Property Value

HintMessage

The message sent to the player when the capture starts, or null to send nothing.

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

InvalidColor

The colour of InvalidText.

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

InvalidText

The text shown briefly after a value is rejected.

public string InvalidText { get; set; }
Property Value

MaxLength

The longest value accepted. Longer input is cut. Never below one.

public int MaxLength { get; set; }
Property Value

StatusDurationMs

How long an accepted or invalid status stays on screen, in milliseconds.

public int StatusDurationMs { get; set; }
Property Value

Validator

Decides whether a typed value is acceptable, or null to accept anything non-empty.

public Func<string, bool>? Validator { get; set; }
Property Value

WaitingForInputColor

The colour of WaitingForInputText.

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

WaitingForInputText

The text shown while waiting for the player to type.

public string WaitingForInputText { get; set; }
Property Value

Methods

Coerce(IMenuSession, string)

Adjusts a value before it is stored.

protected override string Coerce(IMenuSession session, string value)
Parameters
Returns
The value to store.

Used for clamping into a range or into the bounds of a list.

HandleActionAsync(MenuActionContext)

Offers an action to this component before the menu handles it.

public override ValueTask<bool> HandleActionAsync(MenuActionContext context)
Parameters
Returns
true to consume the action and stop the menu's own handling from running.

Only the focused component is offered actions. Returning true is how a component takes over a key that would otherwise navigate or close the menu.

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.

Render(IMenuComponentRenderContext)

Produces this component's renderer-agnostic output.

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