MenuComponentBase
Classpublic abstract class MenuComponentBase : IMenuComponentThe recommended starting point for a component.
Supplies identity, visibility and enabled rules, the activation pipeline shared by every interactive component, and a no-op action handler, leaving IMenuComponentRenderContext) as the only required member.
View sourceConstructors
Creates a component.
protected MenuComponentBase(string? id = null)- idstring?optionalA stable id, or null to generate one.
Properties
The hint shown while this component holds the selection, or null for none.
public string? Comment { get; set; }Whether this component accepts actions, for every player.
public bool Enabled { get; set; }Decides interactivity per player, or null to use Enabled.
public Func<IMenuSession, bool>? EnabledWhen { get; set; }A stable id for this component, unique within its menu.
public string Id { get; }Whether the selection can land on this component.
public virtual bool IsFocusable { get; }How many lines this component draws.
public virtual int LineCount { get; }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.
Whether activating this component plays the menu's selection sound.
public bool PlaySound { get; set; }An arbitrary value carried alongside this component.
public object? Tag { get; set; }Runs before an activation and can cancel it by returning false .
public Func<MenuActionContext, ValueTask<bool>>? Validating { get; set; }Whether this component is shown, for every player.
public bool Visible { get; set; }Decides visibility per player, or null to use Visible.
public Func<IMenuSession, bool>? VisibleWhen { get; set; }Evaluated on every frame. This is how one component instance is hidden from some players and not others without holding any per-player state itself.
The colour applied to WaitingText, or null to keep the normal style.
public string? WaitingColor { get; set; }The text shown in place of this component's own while an activation is still running.
public string WaitingText { get; set; }Methods
Runs an activation through the shared pipeline.
protected ValueTask<bool> ActivateAsync(MenuActionContext context, Func<MenuActionContext, ValueTask> body)- contextMenuActionContextThe action that triggered the activation.
- bodyFunc<MenuActionContext, ValueTask>The work to run once the activation is allowed.
Refuses when the component is disabled or a previous activation for the same player is still running, then consults Validating. While body runs the component draws WaitingText, so a slow callback cannot be triggered twice.
Produces the hint shown while this component holds the selection.
public virtual string? GetHint(IMenuSession session)- sessionIMenuSessionThe session asking.
Use this for a per-entry explanation, or to advertise keys the component takes over through MenuActionContext).
Offers an action to this component before the menu handles it.
public virtual ValueTask<bool> HandleActionAsync(MenuActionContext context)- contextMenuActionContextThe action being dispatched.
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.
Whether an activation started by this player is still running.
protected bool IsBusy(IMenuSession session)- sessionIMenuSessionThe session to check.
Whether this component can be interacted with by a player.
public virtual bool IsEnabled(IMenuSession session)- sessionIMenuSessionThe session asking.
Whether this component is shown to a player.
public virtual bool IsVisible(IMenuSession session)- sessionIMenuSessionThe session asking.
Whether an action matches a built-in or declared action by name.
protected static bool Matches(MenuActionContext context, MenuActionId action)- contextMenuActionContextThe dispatched action.
- actionMenuActionIdThe action to compare against.
Whether this component needs a new frame even though nothing invalidated the session.
public virtual bool NeedsRedraw(IMenuSession session, DateTime now)- sessionIMenuSessionThe session asking.
- nowDateTimeThe current time.
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.
Produces this component's renderer-agnostic output.
public abstract MenuNode Render(IMenuComponentRenderContext context)- contextIMenuComponentRenderContextThe player and focus state to draw for.