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

ProgressBarComponent

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

A non-interactive bar showing a value that something else owns.

The value is pulled from ProgressProvider rather than stored, and the component asks for a redraw on its own whenever the value has moved, so a bar tracking live state stays current without the plugin invalidating anything.

View source

Constructors

ProgressBarComponent(string, Func<IMenuSession, float>?, bool, string?)

Creates a progress bar.

public ProgressBarComponent(string text = "", Func<IMenuSession, float>? progressProvider = null, bool multiLine = false, string? id = null)
Parameters
  • textstringoptionalThe label to display.
  • progressProviderFunc<IMenuSession, float>?optionalProduces the progress, from zero to one.
  • multiLinebooloptionalWhether the bar is drawn on its own line below the label.
  • idstring?optionalA stable id, or null to generate one.

Properties

BarWidth

How many segments the bar is drawn with. Never below one.

public int BarWidth { get; set; }
Property Value

ClosingBracket

The bracket drawn after the bar.

public string ClosingBracket { get; set; }
Property Value

ClosingBracketColor

The colour of the closing bracket, or null to keep Style.

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

EmptyChar

The character drawn for an empty segment.

public string EmptyChar { get; set; }
Property Value

EmptyColor

The colour of the empty segments.

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

FilledChar

The character drawn for a filled segment.

public string FilledChar { get; set; }
Property Value

FilledColor

The colour of the filled segments, or null to keep Style.

public string? FilledColor { 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.

LineCount

How many lines this component draws.

public override int LineCount { get; }
Property Value

Used to decide how much of the body fits on one page, without rendering components that will not be shown. It must match what IMenuComponentRenderContext) produces: a MenuBlankNode costs its Lines, a MenuStackNode costs the sum of its children, and everything else costs one. A component that returns a stack has to override this, otherwise it is budgeted as a single line and the page overflows.

MultiLine

Whether the bar is drawn on its own line below the label.

public bool MultiLine { get; set; }
Property Value

OpeningBracket

The bracket drawn before the bar.

public string OpeningBracket { get; set; }
Property Value

OpeningBracketColor

The colour of the opening bracket, or null to keep Style.

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

ProgressProvider

Produces the progress for a player, from zero to one. Null reads as zero.

public Func<IMenuSession, float>? ProgressProvider { get; set; }
Property Value

ShowPercentage

Whether a percentage is shown next to the bar.

public bool ShowPercentage { get; set; }
Property Value

Methods

GetProgress(IMenuSession)

Reads the progress for a player, clamped between zero and one.

public float GetProgress(IMenuSession session)
Parameters
Returns
The progress.

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.